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