Tuesday, January 20, 2015

Appium - iOS and Android webview context

I encountered another thing I wasn't expecting with Appium related to the webview context.  For iOS the context was WEBVIEW_1, but for Android it was WEBVIEW_.  I'll confess to not having dug into the context very much and how and why it might be named.  However, I was expecting them to have the same name.  So instead of just calling AppiumDriver.context("WEBVIEW_1") I ended up looping through the available contexts and finding one that starts with "WEBVIEW" and selecting that one.

Monday, January 19, 2015

Fixing Appium functional tests

Lately I've been trying to get functional testing for our mobile application up and running.  Some initial work was done for it, making use of Cucumber and Appium.  Sadly, it hasn't been a focus so while we had things working for a bit we messed things up with the upgrade to Xcode 6, which caused a delay while Appium was updated to be able to work with some changes.

One of the interesting side effects was that calling click() on the WebElement used to work, but after the upgrade those tests failed.  For which I found this discussion that led me into trying to use tap().  I fumbled for a little since:

  • We have a hybrid app and we've focused all our work in the WEB_VIEW context.  Turns out calling tap in that context doesn't work and you have to switch to NATIVE_APP context.
  • Then I tried using the tap(fingers, WebElement, duration) variation of the method, but that would crash Appium an error "uncaughtException: Cannot read property 'x' of undefined".
    • I haven't nailed this down, but I'm guessing this is because I found the WebElement in the WEB_VIEW context, then switched to NATIVE_APP context to tap.
  • Finally used the x, y coordinates of the WebElement and used the tap(fingers, x, y, duration) method to actually do the tap.
Then I ran into another issue - the location of the WebElement wasn't quite right.  First off we are still running in compatibility mode which caused the location of things to be fairly far off when using the iPhone 6 simulator - at least that's our current theory.  When using the iPhone 5 simulator things seemed more consistent.  The y coordinate was still off by a little that we had to add as an offset - 26 pixels.  The theory we have for this is that the changes in iOS 7 to make the status bar transparent might be behind this.