質問

NodeJSでNightWatchJSを使用しています。 http://ightwatchjs.org/api

モーダルダイアログを持っているため、表示されない場合があります。クリックする必要がある#close_button(モーダルが表示されている場合)を続ける必要があります。

MODALが表示されない場合、スクリプトが続行されるように、abortOnFailurewaitForElementPresentパラメータを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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top