Last active
June 4, 2016 10:55
-
-
Save Telewa/4c407338486426b50932d18d266e1877 to your computer and use it in GitHub Desktop.
This is code in python to test android hybrid applications using appium/selenium. The device in context is android 5.0 emulator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This is code in python to test android hybrid applications using appium/selenium | |
The device in context is android 5.0 emulator. | |
Preconditions: | |
Install python appium client: pip install Appium-Python-Client source: https://github.com/appium/python-client | |
Install appium: npm install -g [email protected] | |
Install selenium: pip install -U selenium | |
On your terminal, run appium: appium | |
""" | |
from appium import webdriver | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support import expected_conditions | |
from selenium.webdriver.support.ui import WebDriverWait | |
desired_capabilities = {"deviceName": "Android", | |
"deviceName": "Android Emulator", | |
"takesScreenshot": "true", | |
"platformName": "Android", | |
"platformVersion": "5.0", | |
"app": "/home/user/Downloads/myApp.apk"} | |
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_capabilities) | |
driver.implicitly_wait(30) | |
try: | |
#we need to go to web view context | |
for context in driver.contexts: | |
if "WEBVIEW" in context: | |
driver.switch_to.context(context) | |
print driver.current_context | |
#normal selenium code from here onwards | |
try: | |
#wait 10 seconds for this one | |
WebDriverWait(driver, 10).until(expected_conditions.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Sign in"))) | |
#repace the USERNAME and PASSWORD with actual values | |
driver.find_element(By.ID, 'Username').send_keys(USERNAME) | |
driver.find_element(By.ID, 'Password').send_keys(PASSWORD) | |
driver.find_element(By.PARTIAL_LINK_TEXT, "Sign in").click(); | |
#wait 60 seconds for this one | |
WebDriverWait(driver, 60).until(expected_conditions.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Collect"))) | |
except: | |
print "error" | |
finally: | |
#close the driver when we are done | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment