瀏覽代碼

Refactoring, added wait

Artur Paikin 9 年之前
父節點
當前提交
49f1bc8f07
共有 2 個文件被更改,包括 38 次插入25 次删除
  1. 19 17
      test/acceptance/dragdrop.spec.js
  2. 19 8
      test/acceptance/i18n.spec.js

+ 19 - 17
test/acceptance/dragdrop.spec.js

@@ -17,24 +17,26 @@ test('dragdrop: make sure DragDrop accepts and uploads 1 file via input', functi
     .findElement(By.css('.UppyDragDrop-One .UppyDragDrop-input'))
     .findElement(By.css('.UppyDragDrop-One .UppyDragDrop-input'))
     .sendKeys(path.join(__dirname, 'image.jpg'))
     .sendKeys(path.join(__dirname, 'image.jpg'))
 
 
-  driver.sleep(30000)
-
   // Get console elements’s value, then check if it has “Download” there somewhere,
   // Get console elements’s value, then check if it has “Download” there somewhere,
   // if it does, then test passes
   // if it does, then test passes
-  driver.findElement(By.id('console-log'))
-        .getAttribute('value')
-        .then(function (value) {
-          var isFileUploaded = value.indexOf('Download') !== -1
-          collectErrors(driver).then(function () {
-            t.equal(isFileUploaded, true)
-            driver.quit()
-          })
-        })
+  function isUploaded () {
+    return driver.findElement(By.id('console-log'))
+      .getAttribute('value')
+      .then(function (value) {
+        var isFileUploaded = value.indexOf('Download image.jpg') !== -1
+        return isFileUploaded
+      })
+  }
 
 
-  // driver.wait(isUploadSuccessful, 5000).then(function (result) {
-  //   t.equal(result, true)
-  // })
-  // .catch(function (err) {
-  //   console.error('Something went wrong\n', err.stack, '\n')
-  // })
+  driver.wait(isUploaded, 15000, 'File image.jpg should be uploaded within 15 seconds')
+    .then(function (result) {
+      collectErrors(driver).then(function () {
+        t.equal(result, true)
+        driver.quit()
+      })
+    })
+    .catch(function (err) {
+      t.fail(err)
+      driver.quit()
+    })
 })
 })

+ 19 - 8
test/acceptance/i18n.spec.js

@@ -3,19 +3,30 @@ var Driver = require('./Driver')
 var By = Driver.By
 var By = Driver.By
 var collectErrors = Driver.collectErrors
 var collectErrors = Driver.collectErrors
 
 
-test('make sure Uppy loads with Russian language pack', function (t) {
+test('i18n: make sure Uppy loads with Russian language pack', function (t) {
   t.plan(1)
   t.plan(1)
 
 
   var driver = Driver.setDriver()
   var driver = Driver.setDriver()
 
 
+  function findLabelTextElement () {
+    return driver.findElements(By.css('.UppyDragDrop-label')).then(function (result) {
+      return result[0]
+    })
+  }
+
   driver.get('http://localhost:4000/examples/i18n')
   driver.get('http://localhost:4000/examples/i18n')
-  driver
-    .findElement(By.css('.UppyDragDrop-label'))
-    .getText()
-    .then(function (value) {
-      collectErrors(driver).then(function () {
-        t.equal(value, 'Выберите файл или перенесите его сюда')
-        driver.quit()
+
+  driver.wait(findLabelTextElement, 8000, 'Uppy should load within 8 seconds')
+    .then(function (element) {
+      element.getText().then(function (value) {
+        collectErrors(driver).then(function () {
+          t.equal(value, 'Выберите файл или перенесите его сюда')
+          driver.quit()
+        })
       })
       })
     })
     })
+    .catch(function (err) {
+      t.fail(err)
+      driver.quit()
+    })
 })
 })