.waitForElementNotVisible() 編集の提案
waitForElementVisible
と反対です。ページで要素が表示されなくなる(つまり、非表示だが存在する)まで、ミリ秒単位で指定された時間(デフォルトは 5000 ミリ秒)待機してから、他のコマンドやアサーションを実行します。
指定された時間内に要素が非表示にならない場合、テストは失敗します。
nightwatch.json
または外部グローバルファイルでグローバルプロパティとして、waitForConditionPollInterval
プロパティ(ミリ秒単位)を定義することで、ポーリング間隔を変更できます。
同様に、デフォルトのタイムアウトは、グローバルwaitForConditionTimeout
プロパティ(ミリ秒単位)として指定できます。
使用方法
.waitForElementNotVisible([using], selector, [timeout], [pollInterval], [abortOnAssertionFailure], [callback], [message]);
例
module.exports = {
'demo Test': function(browser) {
// with default implicit timeout of 5000ms (can be overwritten in settings under 'globals.waitForConditionTimeout')
browser.waitForElementNotVisible('#dialog');
// specify the locate strategy (css selector/xpath) as the first argument
browser.waitForElementNotVisible('css selector', '#dialog');
// with explicit timeout (in milliseconds)
browser.waitForElementNotVisible('#dialog', 1000);
// continue if failed
browser.waitForElementNotVisible('#dialog', 1000, false);
// with callback
browser.waitForElementNotVisible('#dialog', 1000, function() {
// do something while we're here
});
// with custom output message - the locate strategy is required
browser.waitForElementNotVisible('css selector', '#dialog', 'The dialog container is not visible.');
// with custom Spanish message
browser.waitForElementNotVisible('#dialog', 1000, 'elemento %s no era visible en %d ms');
// many combinations possible - the message is always the last argument
browser.waitForElementNotVisible('#dialog', 1000, false, function() {}, 'elemento %s no era visible en %d ms');
},
'demo Test with selector objects': function(browser) {
browser.waitForElementNotVisible({
selector: '#dialog',
timeout: 1000
});
browser.waitForElementNotVisible({
selector: '#dialog',
locateStrategy: 'css selector'
}, 'Custom output message');
browser.waitForElementNotVisible({
selector: '.container',
index: 2,
retryInterval: 100,
abortOnFailure: true
});
}
'page object demo Test': function (browser) {
var nightwatch = browser.page.nightwatch();
nightwatch
.navigate()
.assert.titleContains('Nightwatch.js');
nightwatch.waitForElementNotVisible('@mainDialog', function(result) {
console.log(result);
});
}
}
パラメータ
名前 | 型 | 説明 |
---|---|---|
使用 オプション |
文字列 | 使用するロケーター戦略。W3C Webdriver - ロケーター戦略を参照してください。 |
セレクター |
文字列 | オブジェクト | 要素を特定するために使用されるセレクター(CSS/XPath)。文字列、または要素プロパティを指定するオブジェクトのいずれかです。 |
time=waitForConditionTimeout オプション |
数値 | 失敗するまでの待ち時間(ミリ秒単位)。 |
poll=waitForConditionPollInterval オプション |
数値 | チェック間の待ち時間(ミリ秒単位)。timeパラメータも指定した場合のみ使用できます。 |
abortOnFailure=abortOnAssertionFailure オプション |
ブール値 | デフォルトでは、要素が見つからない場合、テストは失敗します。アサーションが失敗してもテストを続行する場合は、falseに設定します。グローバルに設定するには、globalsに |
callback オプション |
関数 | コマンドが完了したときに呼び出されるオプションのコールバック関数。 |
message オプション |
文字列 | 出力に表示されるオプションのメッセージ。このメッセージは、現在のセレクターを表す%sと時間を表す%dの2つのプレースホルダーをサポートしています(例:要素%sは%dミリ秒間ページに存在しませんでした)。 |