Last active
June 5, 2018 15:28
-
-
Save bhishan/4dce39e2d4bcbd76f9a329cb5aeab477 to your computer and use it in GitHub Desktop.
Starting with Appium-Python-Client
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
from appium import webdriver | |
def make_navigation_driver(apk_path, package_name, initial_activity, platform='Android', platform_version='8.1.0', device_id='emulator-5554', server_api='http://localhost:4723/wd/hub', **kwargs): | |
""" | |
:param apk_path: | |
:param package_name: | |
:param initial_activity: | |
:param platform: | |
:param platform_version: | |
:param device_id: | |
:param server_api: | |
:param kwargs: Probably will use for setting custom timeout and other capabilities. Implement later? | |
:return: | |
""" | |
desired_caps = { | |
'platformName': platform, | |
'platformVersion': platform_version, | |
'deviceName': device_id, | |
# 'app': apk_path, # Saving apk travel time to device since it is already installed on the device. | |
'appPackage': package_name, | |
'appActivity': initial_activity | |
} | |
return webdriver.Remote(server_api, desired_caps) | |
def perform_simple_automation(driver): | |
""" | |
:param driver: | |
:return: | |
""" | |
clickables = driver.find_elements_by_android_uiautomator('new UiSelector().clickable(true)') | |
# navigate to next activity or view via clicking on the first clickable. | |
if len(clickables): | |
clickables[0].click() | |
if __name__ == '__main__': | |
platform = "Android" | |
platform_version = "7.1.1" | |
device_id = "367e7aa0" | |
apk_path = "/Users/bhishan/Downloads/udemy.apk" | |
package_name = "com.udemy.android" | |
initial_activity = ".SplashActivity" | |
driver = make_navigation_driver(apk_path, package_name, initial_activity, platform=platform, | |
platform_version=platform_version, device_id=device_id) | |
perform_simple_automation(driver) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment