我正在尝试创建一个函数,我可以从任何测试中调用它来查看正在传递的元素(链接文本、Css 选择器、Xpath、ID),单击该元素,然后验证它之后出现的 URL负载。我遇到的问题是它在函数完成之前返回。
我知道我需要实现异步和回调,但我很难理解结构。
clickIDverifyURL: function clickByID (elementVar, elementURL){
var rem = this.remote;
// if statements to look at elementVar and select the right one.. example:
// rem.setFindByTimeout(10000)
// .findByXpath (elementVar)
// .click()
// .end()
return this.remote
// if I code it right, I shouldn't need this sleep right?
.sleep(30000)
.getCurrentUrl()
.then(function(currURL) {
console.log(currURL);
try {
assert.strictEqual(currURL, elementURL, "This test checks to see if the current URL is correct.")
}
catch (e)
{
console.log(e)
}
});
}
感谢任何帮助或评论。