J
J
jehord2015-06-16 19:05:03
JavaScript
jehord, 2015-06-16 19:05:03

How to use loops in nightwatch.js?

There is such a function in pageObject

this.openFilmPage = function () {
         browser.waitForElementVisible("div[class='pg'", 1000);
         for (var i = 0; i < 4; i += 1) {
             console.log('Итерация № ' + i);

             browser.waitForElementVisible("div[class='app'] > div[class='pg'] > div[class='home carousel'] > div[class='home-lst carousel-lst'] > div[class*='home-lst-itm nav-itm']:nth-of-type(" + i + ") > div[class='badge badge-currency']", 100, function (result) {
                 if (result.value) {
                     return browser;
                     console.log('Платный фильм обнаружен');
                 } else {
                     return browser;
                     console.log('Платный фильм отсутствует');
                 }
             });

         } return browser;
     }

There is a call in the test itself
'TC67 Переход на страницу платного фильма': function (browser) {
      browser
      .page.App().open()
      .page.App().openFilmPage()
      .end();     
  }

After the launch, I get
Running: TC67 Going to the paid movie
page Iteration No. 0
Iteration No. 1
Iteration No. 2
Iteration No. 3
After that, it is checked, once, with a zero position, the test fails because the expected element is not at this position.
I expected that all checks will be performed one by one and as a result I will get an element that matches the specified css path.
But as practice has shown, this is not the case, the cycles are apparently executed in asynchronous mode, how can this be overcome?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question