tacoss / grunt-nightwatch

Run your Nightwatch.js tests with Grunt
50 stars 22 forks source link

Add support for Nightwatch feature page_objects_path #44

Closed whawker closed 9 years ago

whawker commented 9 years ago

Nightwatch supports page objects which are configured through an option page_objects_path

nightwatch.json

{
  "src_folders": "./e2e/tests",
  "globals_path": "./e2e/globals.js",
  "page_objects_path": "./e2e/pages", //<--
  //...
}

This allows you to shorthand several commands into a reusable method

I.e. /e2e/pages/login.js

module.exports = function(browser) {
    return {
       attemptLoginWithCredentials: function (username, password) {
            return browser.setValue('input[name="username"]', username)
                .setValue('input[name="password"]', password)
                .click('button[type="submit"]');
        },
        //otherMethodsHere: function (....
    }
}

And you use them like this

module.exports = {
    'I can log in with a correct username and password': function (browser) {
        browser
            .page.login().visitLoginPage() // login() as page filename is login.js
            .page.login().attemptLoginWithCredentials('bob', 'bob_is_awesome')
            .page.login().assertLoggedIn();
    }
}

Can support for this be added?

whawker commented 9 years ago

I'm working on old information, they are documented now