Browse Source

Large test refactor

Artur Paikin 8 years ago
parent
commit
c3544d2c21

+ 14 - 29
test/acceptance/dragdrop.spec.js

@@ -1,19 +1,11 @@
 var test = require('tape')
 var path = require('path')
-var chalk = require('chalk')
-var Driver = require('./Driver')
-var setSauceStatus = Driver.setSauceStatus
-var collectErrors = Driver.collectErrors
+var tools = require('./tools')
 
 module.exports = function (driver, platform, host) {
   var testName = 'DragDrop: upload one file'
-  var platformName = chalk.underline.yellow('[' +
-        platform.os + ' ' +
-        platform.browser + ' ' +
-        platform.version +
-      ']')
 
-  test(testName + ' ' + platformName, function (t) {
+  test(tools.prettyTestName(testName, platform), function (t) {
     t.plan(1)
 
     // Go to the example URL
@@ -21,15 +13,16 @@ module.exports = function (driver, platform, host) {
     driver.manage().window().maximize()
 
     // Set Saucelabs test name
-    driver.executeScript('sauce:job-name=' + testName).catch(function (err) {
-      console.log('local test, so this is ok: ' + err)
-    })
+    tools.setSauceTestName(driver, testName)
+
+    driver.executeScript(tools.uppySelectFakeFile)
+    driver.findElement({css: '.UppyDragDrop-uploadBtn'}).click()
 
     var platformBrowser = platform.browser.toLowerCase()
     if (platformBrowser === 'safari' || platformBrowser === 'microsoftedge') {
       console.log('fake-selecting a fake file')
-      driver.executeScript(Driver.uppySelectFakeFile)
-      driver.findElement({css: '#UppyDragDrop-Two .UppyDragDrop-uploadBtn'}).click()
+      driver.executeScript(tools.uppySelectFakeFile)
+      driver.findElement({css: '.UppyDragDrop-uploadBtn'}).click()
     } else {
       console.log('selecting a real file')
       // Make file input “visible”
@@ -53,7 +46,7 @@ module.exports = function (driver, platform, host) {
       // http://stackoverflow.com/questions/21994261/gettext-not-working-on-a-select-from-dropdown
 
       // TODO: figure out how to deal with multiple Uppy instances on the page
-      return driver.findElement({css: '.UppyProgressBar-percentage'})
+      return driver.findElement({css: '.UppyDragDrop-Two-Progress .UppyProgressBar-percentage'})
         .getAttribute('textContent')
         .then(function (value) {
           var progress = parseInt(value)
@@ -62,22 +55,14 @@ module.exports = function (driver, platform, host) {
         })
     }
 
-    driver.wait(isUploaded, 15000, 'File image.jpg should be uploaded within 15 seconds')
+    driver.wait(isUploaded, 12000, 'File image.jpg should be uploaded within 15 seconds')
       .then(function (result) {
-        collectErrors(driver).then(function () {
-          t.equal(result, true)
-          if (result) {
-            setSauceStatus(driver, true)
-          } else {
-            setSauceStatus(driver, false)
-          }
-          driver.quit()
-        })
+        tools.testEqual(driver, t, result)
+        driver.quit()
       })
       .catch(function (err) {
-        collectErrors(driver).then(function () {
-          t.fail(err)
-          setSauceStatus(false)
+        tools.collectErrors(driver).then(function () {
+          tools.testFail(driver, t, err)
           driver.quit()
         })
       })

+ 10 - 19
test/acceptance/fallback.spec.js

@@ -1,24 +1,18 @@
 var test = require('tape')
 var path = require('path')
-var chalk = require('chalk')
-var Driver = require('./Driver')
+var tools = require('./tools')
 
 module.exports = function (driver, platform, host) {
-  var testName = 'fallback: fall back to regular <form> upload when JS is not working, or not loaded yet, or browser is not supported by Uppy'
-  var platformName = chalk.underline.yellow('[' +
-      platform.os + ' ' +
-      platform.browser + ' ' +
-      platform.version +
-    ']')
-
-  test(testName + ' ' + platformName, function (t) {
+  var testName = 'Fallback: fall back to regular <form> upload when JS is not working, or not loaded yet, or browser is not supported by Uppy'
+
+  test(tools.prettyTestName(testName, platform), function (t) {
     t.plan(1)
 
     driver.get(host + '/examples/multipart/index.html')
 
     driver.manage().window().maximize()
 
-    Driver.setSauceTestName(driver, testName)
+    tools.setSauceTestName(driver, testName)
 
     driver
       .findElement({css: '.UppyForm input'})
@@ -35,7 +29,6 @@ module.exports = function (driver, platform, host) {
 
       return driver.getCurrentUrl().then(function (val) {
         console.log('current url is ', val)
-        // temp posttestserver.com/post.php?dir=uppy&status_code=202 for IE compatibility
         var isPageRedirected = val.indexOf('api2.transloadit.com') !== -1
         return isPageRedirected
       })
@@ -43,16 +36,14 @@ module.exports = function (driver, platform, host) {
 
     driver.wait(isRedirectedAfterUpload, 12000, 'Browser should navigate to api2.transloadit.com after upload')
       .then(function (isPageRedirected) {
-        Driver.testEqual(driver, t, isPageRedirected === true)
+        tools.testEqual(driver, t, isPageRedirected === true)
         driver.quit()
-        // Driver.collectErrors(driver).then(function () {
-        //   Driver.testEqual(driver, t, isPageRedirected === true)
-        //   driver.quit()
-        // })
       })
       .catch(function (err) {
-        Driver.testFail(driver, t, err)
-        driver.quit()
+        tools.collectErrors(driver).then(function () {
+          tools.testFail(driver, t, err)
+          driver.quit()
+        })
       })
   })
 }

+ 11 - 30
test/acceptance/i18n.spec.js

@@ -1,22 +1,16 @@
 var test = require('tape')
-var chalk = require('chalk')
-var Driver = require('./Driver')
+var tools = require('./tools')
 
 module.exports = function (driver, platform, host) {
-  var testName = 'i18n: make sure Uppy loads with Russian language pack '
-  var platformName = chalk.underline.yellow('[' +
-      platform.os + ' ' +
-      platform.browser + ' ' +
-      platform.version +
-    ']')
+  var testName = 'i18n: load with Russian language pack'
 
-  test(testName + ' ' + platformName, function (t) {
+  test(tools.prettyTestName(testName, platform), function (t) {
     t.plan(1)
 
     driver.get(host + '/examples/i18n')
     driver.manage().window().maximize()
 
-    Driver.setSauceTestName(driver, testName)
+    tools.setSauceTestName(driver, testName)
 
     function findLabelTextElement () {
       return driver.findElements({css: '.UppyDragDrop-label'}).then(function (result) {
@@ -27,29 +21,16 @@ module.exports = function (driver, platform, host) {
     driver.wait(findLabelTextElement, 8000, 'Uppy should load within 8 seconds')
       .then(function (element) {
         element.getText().then(function (value) {
-          Driver.collectErrors(driver).then(function () {
-            // why trim? Microsoft Edge:
-            // not ok 4 should be equal
-            //  ---
-            // operator: equal
-            // expected: 'Выберите файл или перенесите его сюда'
-            // actual:   'Выберите файл или перенесите его сюда '
-            Driver.testEqual(driver, t, value.trim() === 'Выберите файл или перенесите его сюда')
-            // t.equal(value.trim(), 'Выберите файл или перенесите его сюда')
-            // if (value.trim() === 'Выберите файл или перенесите его сюда') {
-            //   setSauceTestStatus(driver, true)
-            // } else {
-            //   setSauceTestStatus(driver, false)
-            // }
-            driver.quit()
-          })
+          // why trim? Microsoft Edge:
+          // expected: 'Выберите файл или перенесите его сюда'
+          // actual:   'Выберите файл или перенесите его сюда '
+          tools.testEqual(driver, t, value.trim() === 'Выберите файл или перенесите его сюда')
+          driver.quit()
         })
       })
       .catch(function (err) {
-        Driver.collectErrors(driver).then(function () {
-          Driver.testFail(driver, t, err)
-          // t.fail(err)
-          // setSauceTestStatus(driver, false)
+        tools.collectErrors(driver).then(function () {
+          tools.testFail(driver, t, err)
           driver.quit()
         })
       })

+ 6 - 6
test/acceptance/index.js

@@ -10,7 +10,7 @@
 // - http://selenium.googlecode.com/git/docs/api/javascript/namespace_webdriver_By.html
 // - http://selenium.googlecode.com/git/docs/api/javascript/class_webdriver_WebElement.html
 
-require('babel-register')
+// require('babel-register')
 
 var webdriver = require('selenium-webdriver')
 var remote = require('selenium-webdriver/remote')
@@ -47,7 +47,7 @@ if (isTravisTest) {
 console.log('Acceptance tests will be targetting: ' + host)
 
 var platforms = [
-  // { browser: 'Safari', version: '8.0', os: 'OS X 10.10' },
+  // { browser: 'Safari', version: '8.0', os: 'OS X 10.10' }
   // { browser: 'MicrosoftEdge', version: '13.10586', os: 'Windows 10' },
   { browser: 'Firefox', version: '38.0', os: 'Linux' },
   { browser: 'Internet Explorer', version: '10.0', os: 'Windows 8' },
@@ -58,8 +58,8 @@ var platforms = [
 
 var tests = [
   require('./multipart.spec.js'),
-  require('./i18n.spec.js')
-  // require('./dragdrop.spec.js')
+  require('./i18n.spec.js'),
+  require('./dragdrop.spec.js')
 ]
 
 function buildDriver (platform) {
@@ -98,7 +98,7 @@ function buildDriver (platform) {
   return driver
 }
 
-var customTests = {
+var specificTests = {
   fallback: function () {
     var ancientPlatform = { browser: 'internet explorer', version: '6.0', os: 'Windows XP' }
     var driver = buildDriver({ browser: 'internet explorer', version: '6.0', os: 'Windows XP' })
@@ -122,7 +122,7 @@ function runAllTests () {
 
     // run custom platform-specific tests here
     // fallback test
-    customTests.fallback()
+    specificTests.fallback()
   } else {
     // run tests just for local Firefox
     tests.forEach(function (test) {

+ 17 - 37
test/acceptance/multipart.spec.js

@@ -1,43 +1,33 @@
 var test = require('tape')
-var chalk = require('chalk')
-var Driver = require('./Driver')
+var tools = require('./tools')
+var path = require('path')
 
 module.exports = function (driver, platform, host) {
-  var testName = 'Multipart: upload two files'
-  var platformName = chalk.underline.yellow('[' +
-        platform.os + ' ' +
-        platform.browser + ' ' +
-        platform.version +
-      ']')
+  var testName = 'Multipart: upload a file'
 
-  test(testName + ' ' + platformName, function (t) {
+  test(tools.prettyTestName(testName, platform), function (t) {
     t.plan(1)
 
-    // Go to the example URL
     driver.get(host + '/examples/multipart/')
     driver.manage().window().maximize()
 
-    Driver.setSauceTestName(driver, testName)
+    tools.setSauceTestName(driver, testName)
 
     // driver.manage().timeouts().implicitlyWait(5 * 1000)
 
-    // If this is Edge or Safari, fake upload a dummy file object
     var platformBrowser = platform.browser.toLowerCase()
     if (platformBrowser === 'safari' || platformBrowser === 'microsoftedge') {
       console.log('fake-selecting a fake file')
-      driver.executeScript(Driver.uppySelectFakeFile)
+      driver.executeScript(tools.uppySelectFakeFile)
       driver.findElement({css: '.UppyForm-uploadBtn'}).click()
     } else {
-      console.log('fake-selecting a fake file')
-      driver.executeScript(Driver.uppySelectFakeFile)
-      driver.findElement({css: '.UppyForm-uploadBtn'}).click()
+      console.log('selecting a real file')
       // Find input by css selector & pass absolute image path to it
-      // console.log('selecting a real file')
-      // driver.findElement({css: '.UppyFormContainer .UppyForm-input'}).then(function (el) {
-      //   el.sendKeys(path.join(__dirname, 'image.jpg'))
-      //   el.sendKeys(path.join(__dirname, 'image2.jpg'))
-      //   driver.findElement({css: '.UppyForm-uploadBtn'}).click()
-      // })
+      driver.findElement({css: '.UppyFormContainer .UppyForm-input'}).then(function (el) {
+        el.sendKeys(path.join(__dirname, 'image.jpg'))
+        el.sendKeys(path.join(__dirname, 'image2.jpg'))
+        driver.findElement({css: '.UppyForm-uploadBtn'}).click()
+      })
     }
 
     function isUploaded () {
@@ -52,24 +42,14 @@ module.exports = function (driver, platform, host) {
         })
     }
 
-    driver.wait(isUploaded, 15000, 'File image.jpg should be uploaded within 15 seconds')
+    driver.wait(isUploaded, 12000, 'File image.jpg should be uploaded within 15 seconds')
       .then(function (result) {
-        Driver.collectErrors(driver).then(function () {
-          Driver.testEqual(driver, t, result)
-          // t.equal(result, true)
-          // if (result) {
-          //   setSauceTestStatus(driver, true)
-          // } else {
-          //   setSauceTestStatus(driver, false)
-          // }
-          driver.quit()
-        })
+        tools.testEqual(driver, t, result)
+        driver.quit()
       })
       .catch(function (err) {
-        Driver.collectErrors(driver).then(function () {
-          Driver.testFail(driver, t, err)
-          // t.fail(err)
-          // setSauceTestStatus(driver, false)
+        tools.collectErrors(driver).then(function () {
+          tools.testFail(driver, t, err)
           driver.quit()
         })
       })

+ 30 - 19
test/acceptance/Driver.js → test/acceptance/tools.js

@@ -1,7 +1,7 @@
 var webdriver = require('selenium-webdriver')
-var firefox = require('selenium-webdriver/firefox')
+// var firefox = require('selenium-webdriver/firefox')
 var By = webdriver.By
-var path = require('path')
+// var path = require('path')
 var chalk = require('chalk')
 
 function uppySelectFakeFile () {
@@ -17,6 +17,16 @@ function uppySelectFakeFile () {
   })
 }
 
+function prettyTestName (name, platform) {
+  var testName = chalk.cyan.bold(name)
+  var platformName = chalk.yellow(
+        platform.os + ', ' +
+        platform.browser + ' ' +
+        platform.version
+      )
+  return testName + ' / ' + platformName
+}
+
 // https://wiki.saucelabs.com/display/DOCS/Annotating+Tests+with+Selenium's+JavaScript+Executor
 function setSauceTestStatus (driver, passed) {
   driver
@@ -54,7 +64,7 @@ function collectErrors (driver) {
     .then(function (uppyLog) {
       console.error([
         '[uppy-log]',
-        chalk.magenta(uppyLog)
+        chalk.red(uppyLog)
       ].join(' '))
     })
     .catch(function (err) {
@@ -79,24 +89,25 @@ function collectErrors (driver) {
     //   })
 }
 
-function setDriver () {
-  var profile = new firefox.Profile()
-  profile.addExtension(path.join(__dirname, 'xpi', 'firebug-2.0.16.xpi'))
-  profile.addExtension(path.join(__dirname, 'xpi', 'JSErrorCollector.xpi'))
-  profile.setPreference('extensions.firebug.showChromeErrors', true)
-
-  var options = new firefox.Options().setProfile(profile)
-  var driver = new firefox.Driver(options)
-
-  // var driver = new webdriver.Builder()
-  //     .forBrowser('firefox')
-  //     .build()
-
-  return driver
-}
+// function setDriver () {
+//   var profile = new firefox.Profile()
+//   // profile.addExtension(path.join(__dirname, 'xpi', 'firebug-2.0.16.xpi'))
+//   // profile.addExtension(path.join(__dirname, 'xpi', 'JSErrorCollector.xpi'))
+//   // profile.setPreference('extensions.firebug.showChromeErrors', true)
+//
+//   var options = new firefox.Options().setProfile(profile)
+//   var driver = new firefox.Driver(options)
+//
+//   // var driver = new webdriver.Builder()
+//   //     .forBrowser('firefox')
+//   //     .build()
+//
+//   return driver
+// }
 
 module.exports = {
-  setDriver,
+  // setDriver,
+  prettyTestName,
   uppySelectFakeFile,
   collectErrors,
   testEqual,