TA Basics: Website Test Automation on mobile devices via Appium server

Recently I have been focussing on test automation with mobile devices. Specifically Android and iOS (no Windows phone because that platform is as good as dead at the moment). I first wanted to make a complete manual from setting up software and devices/simulators up to a small test script. But due to lack of time I'll focus on specific parts. If you have any questions reguarding the setup, feel free to contact me.

So all that said, let's get to the point. The internet is full of blogposts, video's and examples of people testing mobile apps. However I don't test an app, I want to do some web test automation on mobile devices. It took me quiet some time to figure out what exactly I had to use to get it all to work as needed for my project.

Setup

  • Mac mini running OSX 10.13.4 High Sierra (Mac machine is needed for iOS simulation)
  • Ruby version 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]
  • Appium desktop version 1.4.1 (with Appium server 1.7.2)
  • lapis_lazuli ruby gem version 2.1.3 (gem install lapis_lazuli) *
    • This will also install Watir (6.10.3 for me) and Selenium (3.10.0 for me) 
  • appium_lib ruby gem version 9.10.0 (gem install appium_lib)
  • [Android/Chrome specific]
    • Android Studio version 3.3 (with Gradle 4.4)
    • Latest chromedriver (version 2.37 on moment of writing) for latest chrome app (Android chrome v65 at moment of writing) (chrome driver https://sites.google.com/a/chromium.org/chromedriver/)
  • [iOS/Safari specific]
    • Xcode version 9.2 (9C40b)
    • Simulator version 10.0
    • Brew [Homebrew 1.5.13 | Homebrew/homebrew-core (git revision 727f; last commit 2018-03-29)]
    • Carthage version 0.29.0 (brew install carthage)
Android emulation could also be done on Windows, but iOS can only be connected via Xcode tools which is only available on OSX, so you're stuck to Mac hardware for that. There is not much difference between an Android emulator and a real Android device so choose whatever you want, just make sure it's visible when you run the 'adb devices' command in terminal. For iOS you need Xcode. I use Ruby 2.5.0 with the following gems.

* One thing to keep in mind for the LapisLazuli gem to work (for now), is that you have a project (see previous blogposts how to easily create one) and in the terminal you make sure you browse to this project folder before starting IRB, see this issue https://github.com/spriteCloud/lapis-lazuli/issues/100  This will be fixed in a later version of the lapis_lazuli gem, but just keep this in mind. in case you get the "stack too deep" error message.

Now we can start the fun...

Boot up the Android device (is usb/wifi make sure it's connected over usb) and make sure you see it when you run the 'adb devices' command in terminal. If someone knows a trick to boot the Android device like the iOS simulator, let me know in the comments. For now just assume it needs to be prebooted and visible via adb devices.
Boot up an iPhone X simulator with iOS 10.3 manually, just to make sure this works, this one you can shutdown if you want, does not need to be booted.
Boot up Appium Desktop and hit the Start Server button (no extra settings/setup needed for this example), meaning it will be accessible via http://0.0.0.0/wd/hub but that is for later.
Open up a terminal and navigate to the project folder and start IRB *

*Just to be sure nothing from the previous session is still active/present I close irb and start it up again. I remember that otherwise you might need to define each browser session with a unique name or something, but I'm lazy. So if the wrong browser starts up or if things don't work, just restart irb and try again.

Session examples

This next part actually took me quiet some time to figure out since not many online resources are mentioning these things. So hopefully you bump into this blogpost because of that and now you ave a working example.

Appium_lib example

Watir example

Lapis_Lazuli example

Another way to define capabilities and use them with LL/Watir

Problems you might encounter

Android/Chrome/Emulator problems

  • Problem: Android studio does not seem to be able to open the AVD manager (grayed out) in the top right corner
  • Solution: Look for cradle error at the bottom, I don't recall the actual message but I think it was something that needed to be synced/installed/updated, if done correctly the top AVD manager icon should become available
  • Problem: org.openqa.selenium.WebDriverException: unknown error: call function result missing ‘value’
  • Solution: Make sure you run the latest chrome driver on Appium, see: https://discuss.appium.io/t/how-to-upgrade-the-chromedriver-associated-with-appium/21463
  • Problem: You get an error/warning that you need to add variables to your profile/PATH
  • Solution: Then we need to add some lines to our PATH variable (OSX): https://stackoverflow.com/questions/19986214/setting-android-home-enviromental-variable-on-mac-os-x 
  • Problem: Selenium::WebDriver::Error::UnknownError: unknown error: operation is unsupported on Android (and in the stack trace it says "from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/watir-6.10.3/lib/watir/window.rb:68:in `resize_to'")
  • Solution: (LapisLazuli issue) when you open IRB in the test folder and the default device in your config.yml is one that requires a resize of the window. Make sure you add a device with no values and make that one the default in your config.yml before you start testing manually with IRB. If you run the cucumber command instead of an IRB session, just enter it after the cucumber command (e.g. cucumber DEVICE=<name_in_devices.yml_with_empty_values>
  • Problem: I have multiple phones, but Appium does not connect to the correct one
  • Solution: Start the server with certain capabilities and start the session with certain capabilities, see: https://stackoverflow.com/questions/47017543/how-to-make-sure-the-appium-node-is-connected-to-only-one-phone
  • Problem: Selenium::WebDriver::Error::UnknownError (unknown error: unhandled inspector error: {"code":-32000,"message":"Cannot navigate to invalid URL"}
  • Solution: Use a valid url, see: https://stackoverflow.com/questions/18429680/selenium-error-cannot-navigate-to-invalid-url

iOS/Safari/Simulator problems

  • Problem: Selenium::WebDriver::Error::UnknownError (An unknown server-side error occurred while processing the command. Original error: Could not get Xcode version. /Library/Developer/Info.plist does not exist on disk.)
  • Solution: https://stackoverflow.com/questions/32724616/appium-error-could-not-get-xcode-version
  • Problem: Selenium::WebDriver::Error::SessionNotCreatedError (A new session could not be created. Details: Appium's IosDriver does not support xcode version 9.2. Apple has deprecated UIAutomation. Use the "XCUITest" automationName capability instead.)
  • Solution: Add this capability "automationName: 'XCUITest'," (without the "" quotes see example above)
  • Problem: Selenium::WebDriver::Error::UnknownError (An unknown server-side error occurred while processing the command. Original error: Could not create simulator with name 'appiumTest-bb60b459-e9b1-4ddc-9dd5-eb530707d0dd', device type id 'iPhone' and runtime id '11.2'. Reason: 'simctl error running 'create': Invalid device type: iPhone')
  • Solution:        Use the correct device name, in my case 'iPhone' needed to be 'iPhone X'
  • Problem: Selenium::WebDriver::Error::UnknownError (An unknown server-side error occurred while processing the command. Original error: Unable to launch WebDriverAgent because of xcodebuild failure: "Carthage binary is not found. Install using `brew install carthage` if it is not installed and make sure the root folder, where carthage binary is installed, is present in PATH environment variable. The current PATH value: '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/node_modules/.bin:/Applications/Appium.app/Contents/MacOS'".)
  • Solution: Install carthage as mentioned in the error itself.

Generic problems

End word

I hope this collection of information (how to setup the session) and issues I had to fix is helping you in the right direction to get things up and running. If this is useful to you, please share/like it. If you have any question about a specific part, feel free contact me.

Comments

  1. Great blog post. Loved the layout, will be recommending others to read these.

    Think for the emulator stuff if you can physically have a 10-20second video of the actual device doing stuff - Just helps people understand what you've coded.

    ReplyDelete
    Replies
    1. Super late reply (only now I noticed your comment had to be approved first). Thanks for your response.

      What did you mean with the 10-20 second video? I've added video and shared the code that is used.

      Delete

Post a Comment

Popular posts from this blog

PowerShell - How to overcome Azure VM's fixed resolution limitation

TA: Who doesn't like proxies? Me!