NightWatchJS。WaitForelementPresent AbortonFailureが働いていません
-
21-12-2019 - |
質問
NodeJSでNightWatchJSを使用しています。 http://ightwatchjs.org/api
モーダルダイアログを持っているため、表示されない場合があります。クリックする必要がある#close_button
(モーダルが表示されている場合)を続ける必要があります。
MODALが表示されない場合、スクリプトが続行されるように、abortOnFailure
の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?
}
}
. 解決
abortOnFailure
はうまくいきますが、waitForElementPresent
には、渡したコールバックが正しいコンテキストで呼び出されないバグがあります。それは固定されます。
このようにあなたのテストを書くことができます。
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
}
}
. 他のヒント
I ran into something similar, I was waiting for an iframe to be present. I created a function to actually close it:
pageObject function:
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;
In my test I wait for the page to fully load before executing the above function.
所属していません StackOverflow