TestArmada / nightwatch-extra

MIT License
30 stars 25 forks source link

Nightwatch page objects for native apps #123

Open hcastro opened 6 years ago

hcastro commented 6 years ago

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 commented 5 years ago

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.