nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.79k stars 1.31k forks source link

Chaning command issue #1863

Closed mezderman closed 6 years ago

mezderman commented 6 years ago

I am trying to create a chain commands as follow:


browser
      .url(testPages.landing)
      .waitForElementVisible('body')
      .saveScreenshot(imgPath + '.png', function(data) {
        browser.pause(20000)
      })
      .end()

I am expecting the browser.pause(20000) will get injected after .saveScreenshot() and .end() however it doesn't seems like the case. The browser gets closed immediately.

This following code works but not exactly what I nee:

browser
      .url(testPages.landing)
      .waitForElementVisible('body')
      .saveScreenshot(imgPath + '.png', function(data) {
      })
      .pause(20000)
      .end()

Is it an issue with nightwatch or I am doing something wrong?

Thanks
- Mo
sandeepthukral commented 6 years ago

The following code might work

browser
      .url(testPages.landing)
      .waitForElementVisible('body')
      .saveScreenshot(imgPath + '.png', function(data) {
      })
      .pause(20000);
browser.perform(function(browser, done){
      browser.end();
      done
});
mezderman commented 6 years ago

Thank you @sandeepthukral but I pupously try to pause in the saveScreenshot call back since I am doing few things there that will require some access to nightwatch api

For example:


browser
      .url('http://www.yahoo.com')
      .waitForElementVisible('body')
      .saveScreenshot(imgPath + '.png', function(data) {
        browser.url('http://www.google.com')
      })

    browser.perform(function(browser, done) {
      browser.end()
      done
    })
aberonni commented 6 years ago

@mezderman I'm not sure I understand the original question.

I am expecting the browser.pause(20000) will get injected after .saveScreenshot() and .end() however it doesn't seems like the case.

If I have understood correctly, that is an incorrect assumption.

With the following code from your example:

browser
      .url(testPages.landing)
      .waitForElementVisible('body')
      .saveScreenshot(imgPath + '.png', function(data) {
        browser.pause(20000)
      })
      .end()

The order of execution should be

Is this not the case?

mezderman commented 6 years ago

Correct @aberonni . That's not the case for me. What I am really trying to do is something like that


browser
      .url(testPages.landing)
      .waitForElementVisible('body')
      .saveScreenshot(imgPath + '.png', function(data) {
        browser.url('www.google.com')
      })

But I am getting and navigateTo error in the callback

I am expecting the order of command to be:
saveScreenshot
url(google)
end

But it looks like it does:
saveScreenshot
end
url(google)
mezderman commented 6 years ago

I created a repo with simple implementation of what I am trying to do @aberonni @sandeepthukral : https://github.com/mezderman/nightwatch-test

File: https://github.com/mezderman/nightwatch-test/blob/master/tests/fixtures/simpleTest.js

Thank you!

sandeepthukral commented 6 years ago

@mezderman you need to understand the command queue. Read this page as many times as needed. For me the third time made this click https://github.com/nightwatchjs/nightwatch/wiki/Understanding-the-Command-Queue

When you put something in a callback, it happens in a different queue and in a different timeline.

sandeepthukral commented 6 years ago

Ok, I had added some code from my understanding, but that code did not work when I forked your repo. So I edited my previous comment.

I have some code that is working as expected. This is it

browser
      .url('https://github.com/mezderman')
      .saveScreenshot('reports/screenshots/github.png', function (data) {
        console.log('image saved')
        browser.url('http://www.google.com')
      })

    browser.perform((browser, done) => {
      browser.end()
      done()
    })

Here is the output of this code

$ yarn integration-test                                                                        843  11:04:17
yarn run v1.9.4
warning package.json: No license field
$ nightwatch
Starting selenium server... started - PID:  58375

[Simple Test] Test Suite
============================
Executing the global `beforeEach`

Running:  Github Repositories Navigation
image saved
No assertions ran.

Error writing log file to: /private/tmp/nightwatch-test/logs/selenium-debug.log
✨  Done in 4.62s.

The issue here is that this code works on nightwatch version 0.9.21 but not on 1.0.8

mezderman commented 6 years ago

@sandeepthukral Thank you for your help! If you are not able to fork feel free to commit to master I downgrade to version 0.9.21 but I still don't get the same order of execution. It drives me crazy. I update my test on the repo. It looks like all commands are in right order except the save image call back


Starting selenium server... started - PID:  45585

[Simple Test] Test Suite
============================
Executing the global `beforeEach`

Running:  Github Repositories Navigation
go to url
got body
end
image saved
No assertions ran.
beatfactor commented 6 years ago

This should be fixed in v1.0.11.