[英]Nightwatch JS: Browser.execute does not execute javascript
The goal of my test is to check if the textfield input is empty 我测试的目标是检查文本字段输入是否为空
When I use the browser.execute() command in Nightwatch and I want to add some simple javascript to check if textfield is empty then the block is being skipped by Nightwatch. 当我在Nightwatch中使用browser.execute()命令时,我想添加一些简单的javascript以检查textfield是否为空,然后Nightwatch会跳过该块。 If I would run the JS code in dev tools, it works but when I transform it into Nightwatch it fails. 如果我可以在开发工具中运行JS代码,则可以运行,但是当我将其转换为Nightwatch时,它将失败。 I could be misunderstanding the concept of browser.execute, so I would hope someone could tell me what I am doing wrong. 我可能会误解browser.execute的概念,所以我希望有人可以告诉我我做错了什么。
Thanks in advance. 提前致谢。
Nightwatch code
this.api.execute(
function() {
let element = document.getElementById('autocomplete-input').value;
console.log(element);
if(element.length == 0 || element === ""){
console.log('Element is empty')
}
})
},
JS code
function testing1() {
let element = document.getElementById('autocomplete-input').value;
console.log(element);
if(element.length == 0 && element === ""){
console.log('Element is empty')
}
}
If you look up .execute() in Nightwatch Docs it requires a body, an array of arguments which will be passed to the function and an optional call back function. 如果您在Nightwatch Docs中查找.execute(),则它需要一个主体,一个将传递给该函数的参数数组和一个可选的回调函数。 Since you've the body, adding an empty array should do the job. 既然有了身体,添加一个空数组就可以了。
browser.execute(function testing1() {
let element = document.getElementById('autocomplete-input').value;
console.log(element);
if(element.length == 0 && element === ""){
console.log('Element is empty')
}
}, [])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.