1

I was trying to add an additional url attribute as a function to my page-object while using nightwatchjs.

Like:

module.exports = {
  url: function() {
      return this.api.launchUrl + '/content/site1.xhtml';
  },
  cancelUrl: function() {
      return this.api.launchUrl + '/content/cancel_site1.xhtml';
  }
}

Anyhow nightwatch is not able to get that 2nd attribute cancelUrl, ie undefined.

Why is that so? Shouldn't nightwatch be able to access that attribute as it is nothing more than a function call returning a string or am I misunderstanding a javascript or special page-object concept?

-- I am aware that there should be a page-object for each site so there should not be a 2nd site. Anyhow I would like to understand why this is not working technically.

1 Answer 1

1

Not sure I can answer the "why" (other than to say that when nightwatch loads up your page objects as globally available it must be wrapping your js file and filtering on 'known' functions) but I can offer a solution: add a command to your page object with the desired function. For example:

let pageCommands = {
    cancelUrl: function() {
        return this.api.launchUrl + '/content/cancel_site1.xhtml';
    }
};

module.exports = {
    commands: [pageCommands],
...
}

It's not the typical use of page commands, but your test would then be able to access the cancelUrl function on the page object instance.

More on page commands here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.