Domanda

Sto usando NightwatchJS con Nodejs: http://nightwatchjs.org/api

Ho una finestra di dialogo modale, che può o non può apparire.Ha un #close_button che deve essere cliccato (se il Modal appare) per continuare.

I Impostare il parametro abortOnFailure di waitForElementPresent in false in modo che lo script continui se il Modal non appare.Comunque non riesco a farlo funzionare.

Qualche suggerimento?

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?
    }
}
.

È stato utile?

Soluzione

abortOnFailure funziona bene, tuttavia waitForElementPresent ha un bug ora in cui il callback superato non è chiamato nel contesto corretto.Questo sarà risolto.

Nel frattempo è possibile scrivere il test come questo, con il posizionamento del click esterno, che è la stessa cosa e sembra più pulito:

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
  }
}
.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top