dwyl / learn-nightwatch

:last_quarter_moon_with_face: Learn how to use Nightwatch.js to easily & automatically test your web apps in *real* web browsers.
585 stars 215 forks source link

Page objects #25

Open des-des opened 8 years ago

des-des commented 8 years ago

Page objects allow the user to create custom selectors and sequences of selenium commands for a particular page on the site. This allows us to keep the tests dry while keeping the namespacing the commands/selectors to a particular page.

This feature is quickly becomes useful as the size of the tests grows.

http://nightwatchjs.org/guide#page-objects

happy to write this up with examples and make a pull

nelsonic commented 8 years ago

Yeah, page objects are really useful. if you have time to write up an example please do. 🚀

rchovatiya88 commented 7 years ago

Finally got the page objects to work! I came across this project on my learning journey. Thought i would share my findings :)

The Idea is to have the elements of the page in different file so you can re-use it and if the element changes then we only have to fix at one spot and it'll fix for rest of your tests.

Test case - Go to the site, Assert Main Logo is working, Add a test user and Log out.

There will be Two files - tests.js (tests) & utils.js(elements)

screen shot 2016-11-30 at 5 11 00 pm

Notice the correlation

In utils the function - this.mainLogo = function () { browser .click('body > nav > a'); browser.assert.containsText('.style1>strong', 'Testing'); return browser; };

In test the function to call - utils(browser).mainLogo();

Hopefully this helps.. Thanks @nelsonic and team for a great project and helping others.

nelsonic commented 7 years ago

@rchovatiya88 this is a great addition! would you mind sending us a Pull Request adding this to the tutorial? you've been invited to be a Collaborator on the repository we'd ❤️ to include your learnings! thanks! 🎉

peacetrader commented 6 years ago

how to run the pageobjects tests from Pom folder?. Thanks.

rchovatiya88 commented 6 years ago

@purnimashanti Try adding the path of where the file is form first line - like 'require(../pom/utils'