Change the future

Saturday 12:10 p.m.–12:40 p.m.

Mobile Application Testing with Python and Selenium

Jason Carr

Audience level:


Selenium has grown to be a mature platform on the desktop, but with 'mobile now' being the mantra for so many companies, can we use Selenium to effectively test mobile apps? What about Native apps? This talk will cover using Python to test mobile web applications with Selenium, as well as an in depth overview of the future of Selenium to test Native iOS and Android applications.


What is Selenium? (1m)

  • Open Source Framework for browser automation.
  • "Selenium Automates Browsers": Goal is every platform/browser.
  • Used widely for functional testing for web apps
  • Selenium v. Webdriver

How Does it Work? (3m)

  • Selenium 1 used a sandboxed javascript environment to 'inject' events into the browser.
  • Webdriver simulates the input to the browser (this is called 'Native Events').
  • This depends on the cooperation of the OS and the Browser so sometimes it can't be done and Selenium falls back to 'synthetic' events.
  • (Diagram) Selenium Script <-> Selenium Server <-> Browser
  • Sometimes the 'Selenium Server' isn't there, like with running one instance of Firefox or Chrome, in which case it's built into the browser.
  • (Diagram) Selenium Grid - many browsers, one hub.

Python Bindings (1m)

  • Many different bindings. All speak the JSON protocol over HTTP to the Selenium Server
  • Of course the right ones to use are the fabulous Python bindings.
  • They support Advanced User Interactions API

Desktop Selenium Example (3m)

  • Simple Flask Blog Application
  • (Code Sample) Here's a selenium test in Python. Talk through (2m)
  • Run test and show selenium clicking and typing away.

How Does Mobile Selenium Work? (3m)

  • (Diagram) Substitute in an application for the sever/browser
  • 'iPhoneDriver' and 'AndroidDriver' run entirely on webdriver spec.
  • But, not all native events - some still synthetic.
  • (Diagram) What happens when you send a 'click' vs. a 'tap' to iPhoneDriver and AndroidDriver?
  • What's not supported?

Demo of Mobile Selenium (3m)

  • Runs on real devices or emulator/simulator
  • Launch iOS app in Sim
  • Run tests against local flask app but in Simulator
  • (Slide) Walk through test and talk about 'hardening' your tests for mobile. Have specific examples of where test would pass on desktop but fail in mobile and what to do to fix it (usually elements being out of viewport). Zooming. Panning.
  • iOS simulator limitations
  • But it does work. We're making it better.

Touches Flicks and Swipes, Oh My! (3m)

  • Advanced User Interaction API. Touches, Swipes, Flicks, etc. Multitouch even!
  • Works in Python bindings.
  • (Slide) Some code showing the constructor pattern for the API
  • Demo a test with tap, flick, swipe.
  • Still to do: non-touch actions. Prerecorded voice/video? Shakes/accelerometer.

Native Apps (3m)

  • Not a new idea to use selenium for native
  • NativeDriver worked by putting a server inside the application, then talking to it.
  • Problem: you had to have two versions of your application
  • Never took off, not a whole lot of people using it still (dead since 09)
  • But their logic was good - WebDriver API is Extensible, all UIs are trees, many operations are universal between all UIs.
  • Now we have the Advanced User Interactions API.
  • Many people working to solve this problem. Applecart is one project, but there are many others (example: ios-driver). Not all are Python but use the WebDriver API under the hood so we could support them with Python.

Demo of testing a mobile app (3m)

  • Show it off.