Browse Source

Rethink my behaviour — separate Driver instances for now

Artur Paikin 9 years ago
parent
commit
ed388b9d5b
3 changed files with 29 additions and 24 deletions
  1. 12 13
      test/acceptance/core.js
  2. 9 5
      test/acceptance/dragdrop.spec.js
  3. 8 6
      test/acceptance/i18n.spec.js

+ 12 - 13
test/acceptance/core.js

@@ -22,22 +22,21 @@ function monitorErrors (driver) {
   })
 }
 
-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)
+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 options = new firefox.Options().setProfile(profile)
+  var driver = new firefox.Driver(options)
 
-monitorErrors(driver)
+  monitorErrors(driver)
 
-var consoleElement = driver.findElement(By.id('console-log'))
-var hexoServer = 'http://localhost:4000'
+  return driver
+}
 
 module.exports = {
-  driver,
-  consoleElement,
-  By,
-  hexoServer
+  setDriver,
+  By
 }

+ 9 - 5
test/acceptance/dragdrop.spec.js

@@ -1,6 +1,8 @@
 var test = require('tape')
 var path = require('path')
 var core = require('./core')
+var driver = core.setDriver()
+var By = core.By
 
 var config = {
   dragDropTestUrl: 'http://localhost:4000/examples/dragdrop/',
@@ -8,27 +10,29 @@ var config = {
   imageAbsolutePath: path.join(__dirname, 'image.jpg')
 }
 
+var consoleElement = driver.findElement(By.id('console-log'))
+
 test('dragdrop: make sure DragDrop accepts and uploads 1 file via input', function (t) {
   t.plan(1)
 
   // Go to the example URL
-  core.driver.get(config.dragDropTestUrl)
+  driver.get(config.dragDropTestUrl)
 
   // Find input by css selector
-  var input = core.driver.findElement(core.By.css(config.dragDropInputSelector))
+  var input = driver.findElement(core.By.css(config.dragDropInputSelector))
 
   // Pass absolute image path to the input
   input.sendKeys(config.imageAbsolutePath)
 
   // Wait for a while for upload to go through
-  core.driver.sleep(3000)
+  driver.sleep(3000)
 
   // Get console elements’s value, then check if it has “Download” there somewhere,
   // if it does, then test passes
-  core.consoleElement.getAttribute('value').then(function (value) {
+  consoleElement.getAttribute('value').then(function (value) {
     var isFileUploaded = value.indexOf('Download') !== -1
     t.equal(isFileUploaded, true)
   })
 
-  core.driver.quit()
+  driver.quit()
 })

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

@@ -1,6 +1,8 @@
 var test = require('tape')
 var path = require('path')
 var core = require('./core')
+var driver = core.setDriver()
+var By = core.By
 
 var config = {
   i18nTestUrl: 'http://localhost:4000/examples/i18n',
@@ -9,19 +11,19 @@ var config = {
 }
 
 test('make sure Uppy loads with Russian language pack', function (t) {
-  core.driver.get(config.i18nTestUrl)
+  t.plan(1)
+
+  driver.get(config.i18nTestUrl)
 
   // Wait 3 seconds, for the page to load
-  core.driver.sleep(3000)
+  driver.sleep(3000)
 
-  core.driver.findElement(core.By.css(config.dragDropLabelSelector))
+  driver.findElement(By.css(config.dragDropLabelSelector))
     .getText()
     .then(function (val) {
       console.dir({val: val})
       t.equal(val, 'Выберите файл или перенесите его сюда')
     })
 
-  core.driver.quit()
-
-  t.end()
+  driver.quit()
 })