他のコマンドまたはアサーションを実行する前に、要素がページに表示されるまで、指定された時間(デフォルトは5000ミリ秒)待機します。

指定された時間内に要素が表示されない場合、テストは失敗としてマークされ、通常、テストケース/セクション内の後続の手順/コマンドは実行されません。ただし、`abortOnFailure` を `false` に設定することで、残りの手順/コマンドがスキップされないようにすることができます。

`nightwatch.json` または外部グローバルファイルでグローバルプロパティとして `waitForConditionPollInterval` プロパティ(ミリ秒単位)を定義することで、ポーリング間隔を変更できます。

同様に、デフォルトのタイムアウトは、グローバル `waitForConditionTimeout` プロパティ(ミリ秒単位)として指定できます。

Nightwatch での DOM 要素の操作の詳細については、DOM 要素の検索と操作ガイドページを参照してください。

使用方法

                    .waitForElementVisible([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.waitForElementVisible('#index-container');

    // specify the locate strategy (css selector/xpath) as the first argument
    browser.waitForElementVisible('css selector', '#index-container');

    // with explicit timeout (in milliseconds)
    browser.waitForElementVisible('#index-container', 1000);

    // continue if failed
    browser.waitForElementVisible('#index-container', 1000, false);

    // with callback
    browser.waitForElementVisible('#index-container', 1000, function() {
      // do something while we're here
    });

    // with custom output message - the locate strategy is required
    browser.waitForElementVisible('css selector', '#index-container', 'The index container is found.');

    // with custom Spanish message
    browser.waitForElementVisible('#index-container', 1000, 'elemento %s no era presente en %d ms');

    // many combinations possible - the message is always the last argument
    browser.waitForElementVisible('#index-container', 1000, false, function() {}, 'elemento %s no era visible en %d ms');
  },

  'demo Test with selector objects': function(browser) {
     browser.waitForElementVisible({
       selector: '#index-container',
       timeout: 1000
     });

     browser.waitForElementVisible({
       selector: '#index-container',
       locateStrategy: 'css selector'
     }, 'Custom output message');

     browser.waitForElementVisible({
       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.waitForElementVisible('@featuresList', function(result) {
       console.log(result);
     });
  }
}

パラメータ

名前 タイプ 説明
using
オプション
文字列

使用するロケータ戦略。 W3C Webdriver - ロケータ戦略を参照してください。

selector 文字列 | オブジェクト

要素を見つけるために使用されるセレクター(CSS/Xpath)。文字列、または要素プロパティを指定するオブジェクトを指定できます。

time=waitForConditionTimeout
オプション
数値

失敗するまでの待機時間(ミリ秒単位)。

poll=waitForConditionPollInterval
オプション
数値

チェック間の待機時間(ミリ秒単位)。これは、time パラメータも指定した場合にのみ使用できます。

abortOnFailure=abortOnAssertionFailure
オプション
真偽値

デフォルトでは、要素が見つからない場合、テストは失敗します。アサーションが失敗した場合でもテストを続行するには、これを false に設定します。これをグローバルに設定するには、グローバルに `abortOnAssertionFailure` プロパティを定義します。

callback
オプション
関数

コマンド完了時に呼び出されるオプションのコールバック関数。

message
オプション
文字列

出力に表示されるオプションのメッセージ。メッセージは2つのプレースホルダーをサポートします:現在のセレクターの場合は%s、時間の場合は%d(例:要素%sは%dミリ秒 동안 ページにありませんでした)。