Python+Appium 实战案例
1.获取连接的设备名称
adb devices
2.获取APP的包名和首页名称 在模拟器获取真机中打开需要测试的APP 输入:adb shell 输入:dumpsys window | grep mCurrentFocus 3.打开Appium-window 4.打开百度APP并进行搜索操作 参考代码
from appium import webdriver
from time import sleep
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1.1'
desired_caps['deviceName'] = '127.0.0.1:62001'
desired_caps['appPackage'] = 'com.baidu.searchbox'
desired_caps['appActivity'] = 'com.baidu.searchbox.MainActivity'
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
driver.find_element_by_class_name('android.widget.LinearLayout').click()
sleep(2)
driver.find_element_by_id("com.baidu.searchbox:id/SearchTextInput").send_keys('liuhao')
sleep(1)
driver.find_element_by_id("com.baidu.searchbox:id/float_search_or_cancel").click()
|