github.com/covergates/covergates@v0.2.2-0.20201009050117-42ef8a19fb95/web/tests/e2e/custom-commands/customExecute.js (about) 1 /** 2 * A very basic Nightwatch custom command. The command name is the filename and the 3 * exported "command" function is the command. 4 * 5 * Example usage: 6 * browser.customExecute(function() { 7 * console.log('Hello from the browser window') 8 * }); 9 * 10 * For more information on writing custom commands see: 11 * https://nightwatchjs.org/guide/extending-nightwatch/#writing-custom-commands 12 * 13 * @param {*} data 14 */ 15 exports.command = function command(data) { 16 // Other Nightwatch commands are available via "this" 17 18 // .execute() inject a snippet of JavaScript into the page for execution. 19 // the executed script is assumed to be synchronous. 20 // 21 // See https://nightwatchjs.org/api/execute.html for more info. 22 // 23 this.execute( 24 // The function argument is converted to a string and sent to the browser 25 function (argData) { return argData; }, 26 27 // The arguments for the function to be sent to the browser are specified in this array 28 [data], 29 30 function (result) { 31 // The "result" object contains the result of what we have sent back from the browser window 32 console.log('custom execute result:', result.value); 33 } 34 ); 35 36 return this; 37 };