This commit is contained in:
2020-06-25 23:29:05 +02:00
commit 236ab22e12
24 changed files with 11548 additions and 0 deletions

View 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;
};

View 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);
}
};

View 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);
}
};