A page I am testing has a button that takes you to a different page on the same site. After clicking on that button, I want to wait for that page to load before continuing. Normally, I would just wait for some element on that page to load, but since I recently updated nightwatch/selenium, that waitForElementPresent() test has stopped working. In the process of debugging the problem, I thought it made sense to wait for the new URL to load, but I don't see a nightwatch way to do that. I can hard code a wait with a pause() followed by an assert.urlContains(), but there's got to be a better way. Any suggestions?
What used to work:
this.waitForElementVisible(runCSS,3000)
.click(runCSS)
.waitForElementPresent(newPageElementCSS,5000)
but now it times out on the second wait, even though I can clearly see the new page on the browser display (Firefox 45.0.1 on Windows 8.1).
There is a way in Nightwatch but you didn't notice that, simply use browser. url() without argument but a callback can get the current URL.
You can add Nightwatch to your project simply by running npm install nightwatch --save-dev . This places the Nightwatch executable in your ./node_modules/.
You can use the selenium API moveTo command. It will move the mouse to the given element and it should stay over that element until the next command involving the mouse is used. Just pause for the amount of time you would like to hover for.
Nightwatch. js is an easy to use Node. js based End-to-End (E2E) testing solution for browser based apps and websites. It uses the powerful Selenium WebDriver API to perform commands and assertions on DOM elements.
For such tests you can use the URL related wait methods from ‘thewaiter’ library, to wait until the URL is the correct one, before performing the rest of the test.
In Nightwatch, it is really simple and can be done using one .click () function call where as the only argument the selector has to be passed. To read more about the function, check out Nightwatch documentation about it. As the final step, let’s take a screenshot of our result using .saveScreenshot () function.
Nightwatch.js is an open-source (check their GitHub repo and their home page) end-to-end framework that was initially released in 2014 by Andrei Rusu. Since then it has grown dramatically and is still moving forward.
Since Loadero extends vanilla Nightwatch.js functionality with various custom commands and has additional steps inside module.exports to provide you with insightful data that can be analyzed after test execution, you can’t just copy-paste the script from our local text editor.
Wait for something (a selector) that is unique to the page that will be loaded after the click. It can be anything as long as it doesn't exist on the current page.
For example,
This would wait for <div name="Thingy">
anywhere on the page:
client.waitForElementVisible('div[name="Thingy"]',3000)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With