Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chaning command issue #1863

Closed
mezderman opened this issue Aug 6, 2018 · 9 comments
Closed

Chaning command issue #1863

mezderman opened this issue Aug 6, 2018 · 9 comments

Comments

@mezderman
Copy link

mezderman commented Aug 6, 2018

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
Copy link

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
Copy link
Author

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
Copy link
Collaborator

aberonni commented Aug 7, 2018

@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

  • saveScreenshot
  • saveScreenshot callback
    • pause(20000)
  • end

Is this not the case?

@mezderman
Copy link
Author

mezderman commented Aug 7, 2018

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
Copy link
Author

mezderman commented Aug 7, 2018

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
Copy link

sandeepthukral commented Aug 8, 2018

@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
Copy link

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
Copy link
Author

mezderman commented Aug 8, 2018

@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
Copy link
Member

This should be fixed in v1.0.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants