Просмотр исходного кода

extract nightwatch-helpers into npm package

Evan You 10 лет назад
Родитель
Сommit
d83088ab07

+ 2 - 2
build/nightwatch.config.js

@@ -2,8 +2,8 @@
 module.exports = {
   'src_folders': ['test/e2e/specs'],
   'output_folder': 'test/e2e/reports',
-  'custom_commands_path': ['test/e2e/custom-commands'],
-  'custom_assertions_path': ['test/e2e/custom-assertions'],
+  'custom_commands_path': ['node_modules/nightwatch-helpers/commands'],
+  'custom_assertions_path': ['node_modules/nightwatch-helpers/assertions'],
 
   'selenium': {
     'start_process': true,

+ 1 - 0
package.json

@@ -75,6 +75,7 @@
     "karma-webpack": "^1.7.0",
     "lodash": "^4.13.1",
     "nightwatch": "^0.9.0",
+    "nightwatch-helpers": "^1.0.0",
     "phantomjs-prebuilt": "^2.1.1",
     "rollup": "^0.33.0",
     "rollup-plugin-alias": "^1.2.0",

+ 0 - 18
test/e2e/custom-assertions/attributePresent.js

@@ -1,18 +0,0 @@
-exports.assertion = function (selector, attr) {
-  this.message = 'Testing if element <' + selector + '> has attribute ' + attr + '.'
-  this.expected = true
-  this.value = function (res) {
-    return res.value
-  }
-  this.pass = function (val) {
-    return val === this.expected
-  }
-  this.command = function (cb) {
-    var self = this
-    return this.api.execute(function (selector, attr) {
-      return document.querySelector(selector).hasAttribute(attr)
-    }, [selector, attr], function (res) {
-      cb.call(self, res)
-    })
-  }
-}

+ 0 - 18
test/e2e/custom-assertions/checked.js

@@ -1,18 +0,0 @@
-exports.assertion = function (selector, expected) {
-  this.message = 'Testing if element <' + selector + '> is checked.'
-  this.expected = expected !== false
-  this.value = function (res) {
-    return res.value
-  }
-  this.pass = function (val) {
-    return val === this.expected
-  }
-  this.command = function (cb) {
-    var self = this
-    return this.api.execute(function (selector) {
-      return document.querySelector(selector).checked
-    }, [selector], function (res) {
-      cb.call(self, res)
-    })
-  }
-}

+ 0 - 18
test/e2e/custom-assertions/count.js

@@ -1,18 +0,0 @@
-exports.assertion = function (selector, count) {
-  this.message = 'Testing if element <' + selector + '> has count: ' + count
-  this.expected = count
-  this.pass = function (val) {
-    return val === this.expected
-  }
-  this.value = function (res) {
-    return res.value
-  }
-  this.command = function (cb) {
-    var self = this
-    return this.api.execute(function (selector) {
-      return document.querySelectorAll(selector).length
-    }, [selector], function (res) {
-      cb.call(self, res)
-    })
-  }
-}

+ 0 - 16
test/e2e/custom-assertions/evaluate.js

@@ -1,16 +0,0 @@
-exports.assertion = function (fn, args) {
-  this.message = 'Testing custom eval...'
-  this.expected = true
-  this.value = function (res) {
-    return res.value
-  }
-  this.pass = function (val) {
-    return val === this.expected
-  }
-  this.command = function (cb) {
-    var self = this
-    return this.api.execute(fn, args || [], function (res) {
-      cb.call(self, res)
-    })
-  }
-}

+ 0 - 18
test/e2e/custom-assertions/focused.js

@@ -1,18 +0,0 @@
-exports.assertion = function (selector, expected) {
-  this.message = 'Testing if element <' + selector + '> is focused.'
-  this.expected = expected !== false
-  this.value = function (res) {
-    return res.value
-  }
-  this.pass = function (val) {
-    return val === this.expected
-  }
-  this.command = function (cb) {
-    var self = this
-    return this.api.execute(function (selector) {
-      return document.querySelector(selector) === document.activeElement
-    }, [selector], function (res) {
-      cb.call(self, res)
-    })
-  }
-}

+ 0 - 18
test/e2e/custom-assertions/hasHTML.js

@@ -1,18 +0,0 @@
-exports.assertion = function (selector, html) {
-  this.message = 'Testing if element <' + selector + '> has HTML: ' + html
-  this.expected = html
-  this.value = function (res) {
-    return res.value
-  }
-  this.pass = function (val) {
-    return val.indexOf(html) > -1
-  }
-  this.command = function (cb) {
-    var self = this
-    return this.api.execute(function (selector) {
-      return document.querySelector(selector).innerHTML
-    }, [selector], function (res) {
-      cb.call(self, res)
-    })
-  }
-}

+ 0 - 16
test/e2e/custom-assertions/notVisible.js

@@ -1,16 +0,0 @@
-exports.assertion = function (selector) {
-  this.message = 'Testing if element <' + selector + '> is not visible.'
-  this.expected = false
-  this.pass = function (val) {
-    return val === this.expected
-  }
-  this.value = function (res) {
-    return res.value
-  }
-  this.command = function (cb) {
-    var self = this
-    return this.api.isVisible(selector, function (res) {
-      cb.call(self, res)
-    })
-  }
-}

+ 0 - 3
test/e2e/custom-commands/dblClick.js

@@ -1,3 +0,0 @@
-exports.command = function (selector) {
-  return this.moveToElement(selector, 5, 5).doubleClick()
-}

+ 0 - 27
test/e2e/custom-commands/waitFor.js

@@ -1,27 +0,0 @@
-var util = require('util')
-var events = require('events')
-
-var waitFor = function () {
-  events.EventEmitter.call(this)
-}
-
-util.inherits(waitFor, events.EventEmitter)
-
-waitFor.prototype.command = function (ms, cb) {
-  var self = this
-
-  ms = ms || 1000
-
-  setTimeout(function () {
-    // if we have a callback, call it right before the complete event
-    if (cb) {
-      cb.call(self.client.api)
-    }
-
-    self.emit('complete')
-  }, ms)
-
-  return this
-}
-
-module.exports = waitFor