Closed mezderman closed 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
});
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
})
@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?
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)
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!
@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.
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
@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.
This should be fixed in v1.0.11.
I am trying to create a chain commands as follow: