GrayedFox/nightcap

Issue with accessing globals commands from page object/test case

Closed this issue · 3 comments

@GrayedFox The commands/assertions work great! How would you correctly access the globals functions from the test case/page object ? It currently throws a "not a function" if accessing within the test case by browser.globals.globalCommands.{command} and "cannot read property of undefined" if accessing from the page object with this.{the same as test}

Hi there @aamorozov - that part is a bit tricky. To access the shared pageObject functions, you would need to either require the globals file from the pageObject itself, or pass the client (browser) as a parameter to each function that uses it.

I prefer the natural Node require method! Here is an example pageObject using destructuring:

const { globalCommands } = require('../globals')

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

Now you can call the commands/functions from your test file directly, the same as you would any other pageObject function.

I also updated the readme to include instructions on how to use the globalCommands inside of a test file. Closing as resolved, thanks for the question/report

@GrayedFox Thank you very much!