Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Nightwatch page objects for native apps #123

Open
hcastro opened this issue Oct 23, 2018 · 1 comment
Open

Nightwatch page objects for native apps #123

hcastro opened this issue Oct 23, 2018 · 1 comment

Comments

@hcastro
Copy link

hcastro commented Oct 23, 2018

Do nightwatch-extra mobile commands for native apps work out of the box when using the Nightwatch page object implementation?

Under the hood, Nightwatch (latest release) switches between xpath, css selector or recursion modes when interpreting page object command methods. However, if I need to to use accessibility id or name locator strategies, for example, there are no global methods (in the same vein as useXpath or useCss) available to do so.

Currently, I'm seeing the following error when triggering a page object command using a mobile custom command:

Error processing the server response:
 Parameters were incorrect. We wanted {"required":["using","value"]} and you sent ["using"]
INFO Response 400 POST /wd/hub/session/5409ec9d-3d45-477c-b241-869020a880fb/element (4ms) { value: -1, error: 'Unexpected token P in JSON at position 0' }
INFO Request: POST /wd/hub/session/5409ec9d-3d45-477c-b241-869020a880fb/element
 - data:  {"using":"LOG IN"}
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":18}
[HTTP] --> POST /wd/hub/session/5409ec9d-3d45-477c-b241-869020a880fb/element
[HTTP] {"using":"LOG IN"}
[debug] [MJSONWP] Bad parameters: BadParametersError: Parameters were incorrect. We wanted {"required":["using","value"]} and you sent ["using"]
[HTTP] <-- POST /wd/hub/session/5409ec9d-3d45-477c-b241-869020a880fb/element 400 1 ms - 90
[HTTP]

PageObject File looks like the following:

  elements: {
    logInButton: {
      locateStrategy: 'name',
      selector: 'LOG IN'
    }
  },

  commands: [{
    clickLoginBtn: function () {
      this.clickMobileEl('@logInButton')

      return this
    }
  }]
}
@pschroeder89
Copy link
Contributor

pschroeder89 commented Dec 11, 2018

Our not-ideal solution to this was:

loginButton: 'abc'

and then call it via:

this.api.getMobileEl('id', this.elements.loginButton.selector);

I agree though, it'd be cool if nightwatch-extra could read a page object element object.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants