init
This commit is contained in:
39
tests/e2e/custom-commands/customExecute.js
Normal file
39
tests/e2e/custom-commands/customExecute.js
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* A very basic Nightwatch custom command. The command name is the filename and the
|
||||
* exported "command" function is the command.
|
||||
*
|
||||
* Example usage:
|
||||
* browser.customExecute(function() {
|
||||
* console.log('Hello from the browser window')
|
||||
* });
|
||||
*
|
||||
* For more information on writing custom commands see:
|
||||
* https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands
|
||||
*
|
||||
* @param {*} data
|
||||
*/
|
||||
exports.command = function command(data) {
|
||||
// Other Nightwatch commands are available via "this"
|
||||
|
||||
// .execute() inject a snippet of JavaScript into the page for execution.
|
||||
// the executed script is assumed to be synchronous.
|
||||
//
|
||||
// See https://nightwatchjs.org/api/execute.html for more info.
|
||||
//
|
||||
this.execute(
|
||||
// The function argument is converted to a string and sent to the browser
|
||||
function(argData) {
|
||||
return argData;
|
||||
},
|
||||
|
||||
// The arguments for the function to be sent to the browser are specified in this array
|
||||
[data],
|
||||
|
||||
function(result) {
|
||||
// The "result" object contains the result of what we have sent back from the browser window
|
||||
console.log("custom execute result:", result.value);
|
||||
}
|
||||
);
|
||||
|
||||
return this;
|
||||
};
|
23
tests/e2e/custom-commands/openHomepage.js
Normal file
23
tests/e2e/custom-commands/openHomepage.js
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* A basic Nightwatch custom command
|
||||
* which demonstrates usage of ES6 async/await instead of using callbacks.
|
||||
* The command name is the filename and the exported "command" function is the command.
|
||||
*
|
||||
* Example usage:
|
||||
* browser.openHomepage();
|
||||
*
|
||||
* For more information on writing custom commands see:
|
||||
* https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands
|
||||
*
|
||||
*/
|
||||
module.exports = {
|
||||
command: async function() {
|
||||
// Other Nightwatch commands are available via "this"
|
||||
// .init() simply calls .url() command with the value of the "launch_url" setting
|
||||
this.init();
|
||||
this.waitForElementVisible("#app");
|
||||
|
||||
const result = await this.elements("css selector", "#app ul");
|
||||
this.assert.strictEqual(result.value.length, 3);
|
||||
}
|
||||
};
|
24
tests/e2e/custom-commands/openHomepageClass.js
Normal file
24
tests/e2e/custom-commands/openHomepageClass.js
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* A class-based Nightwatch custom command which is a variation of the openHomepage.js command.
|
||||
* The command name is the filename and class needs to contain a "command" method.
|
||||
*
|
||||
* Example usage:
|
||||
* browser.openHomepageClass();
|
||||
*
|
||||
* For more information on writing custom commands see:
|
||||
* https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands
|
||||
*
|
||||
*/
|
||||
|
||||
const assert = require("assert");
|
||||
|
||||
module.exports = class {
|
||||
async command() {
|
||||
// Other Nightwatch commands are available via "this.api"
|
||||
this.api.init();
|
||||
this.api.waitForElementVisible("#app");
|
||||
|
||||
const result = await this.api.elements("css selector", "#app ul");
|
||||
assert.strictEqual(result.value.length, 3);
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user