Android + Selenium + Python : Testing a web page on mobile
How to test a mobile site (Google for example) with Selenium and Python?
Well that’s how it can happen…
Installation
for python:
pip install selenium
on the phone, you need to install webdriver for android:
download the apk, here: http://code.google.com/p/selenium/downloads/list
plug the phone with usb to your PC (yes, it helps to have its serialId),
On the command line:
adb -s install android-server.apk
Activation of the link between the mobile and your PC:
Launch the application on the phone, and launch from the command line
adb -s forward tcp:8080 tcp:8080
And, there, if there are no errors, we are ready to test.
Testing with Selenium
Below is an example in 7 lines of simple python code which aims to launch a search for the word “Selenium” on Google in the phone’s browser.
from selenium import webdriver
driver=webdriver.Remote('http://localhost:8080/wd/hub',webdriver.DesiredCapabilities.ANDROID)
driver.get('http://www.google.fr')
input=driver.find_element_by_name("q")
input.send_keys('Selenium')
btn=driver.find_element_by_name("btnG")
btn.click()
Which gives in detail
- line 1: import of webdriver from the selenium package into the python environment
- line 2: binding with the phone server
- line 3: open the page
- line 4: search for the input field
- line 5: entry of the word to search
- line 6: find the submit the button
- line 7: click
Simple, no?
That’s all folk !
comments powered by Disqus