Command 在nightwatch.js中调用自定义命令
好的,我想做的是在nightwatch.js中的另一个自定义命令中调用一个自定义命令(目的是降低测试的脆弱性) 例如,在我的第一个自定义命令(message1.js)中,我可以有以下代码Command 在nightwatch.js中调用自定义命令,command,nightwatch.js,add-custom-command,Command,Nightwatch.js,Add Custom Command,好的,我想做的是在nightwatch.js中的另一个自定义命令中调用一个自定义命令(目的是降低测试的脆弱性) 例如,在我的第一个自定义命令(message1.js)中,我可以有以下代码 exports.command = function(browser) { this browser console.log('display this first') return this; 随后在我的第二个自定义命令(message2.js)中,我想首先调用message1.
exports.command = function(browser) {
this
browser
console.log('display this first')
return this;
随后在我的第二个自定义命令(message2.js)中,我想首先调用message1.js命令,然后执行其余代码
比如,
exports.command = function(browser) {
this
browser
//call the message1.js command
console.log('display the second message')
return this;
我试着用这个方法调用它
exports.command = function(browser) {
this
browser
.message1();
console.log('display the second message')
return this;
但这不起作用
所以我的问题是,
是否可以在另一个自定义命令中调用一个自定义命令
如果没有,还有别的方法吗
非常感谢是的,您可以将自定义命令链接在一起或与其他夜间监视方法结合使用: 自定义方法
openUrl.js
:
exports.command = function(url) {
const browser = this;
browser.url(url);
return this;
exports.command = function(url) {
const browser = this;
browser.openUrl(url).waitForElementVisible('#submit-button');
return this;
}
}
调用openUrl.js
的自定义方法openStackOverflow.js
:
exports.command = function(url) {
const browser = this;
browser.url(url);
return this;
exports.command = function(url) {
const browser = this;
browser.openUrl(url).waitForElementVisible('#submit-button');
return this;
}
在测试中使用它们:
'Open Stack Overflow': browser => {
browser.openStackOverflow(`https://stackoverflow.com`);
},