我使用NightwatchJS和NodeJS:http://nightwatchjs.org/api
我有一个模态对话框,它可能出现也可能不会出现。它有一个需要点击的#close_button (如果模式出现的话)来继续。
我将waitForElementPresent的waitForElementPresent参数设置为false,以便如果该模式不出现,脚本将继续。但是我不能让它起作用。
有什么建议吗?
module.exports = {
"Test" : function (browser) {
browser
.url("http://domain.com/")
.waitForElementPresent('#close_button', 5000, false, function() {
this.click('#close_button')
})
.setValue('#username', 'test@email.com')
//more code here
.end(); //does end() go here or inside .waitForElementPresent() above?
}
}发布于 2014-02-26 08:50:26
abortOnFailure运行良好,但是waitForElementPresent现在有一个错误,在这个错误中,您传递给它的回调没有在正确的上下文中调用。那会被解决的。
同时,您可以这样编写测试,并将click放在外部,这与此相同,而且看起来更干净:
module.exports = {
"Test" : function (browser) {
browser
.url("http://domain.com/")
.waitForElementPresent('#close_button', 5000, false)
.click('#close_button')
.setValue('#username', 'test@email.com')
//more code here
.end(); // end() goes here
}
}发布于 2016-02-26 18:53:28
我遇到了一些类似的东西,我在等待一个iframe的出现。我创建了一个函数来实际关闭它:
pageObject函数:
Home.prototype.closeIframe = function(browser) {
var self = this;
console.log('Checking for iframe');
this.browser
.isVisible(iframeSelectors.iframe, function(result) {
if (result.value === true) {
self.browser
.log('iframe visible')
.frame(iframeSelectors.name)
.waitForElementVisible(iframeSelectors.closeLink)
.click(iframeSelectors.closeLink)
.assert.elementNotPresent(iframeSelectors.iframe)
.frame(null)
.pause(2000); //allow for proper frame switching
} else {
console.log('iframe is not visible');
}
});
return this;在我的测试中,我在执行上述函数之前等待页面完全加载。
https://stackoverflow.com/questions/22030344
复制相似问题