Appium连接真机

2019-01-30  本文已影响14人  jinxi197

配置参数

测试案例

python代码

from appium import webdriver  #导入webdriver库
import time #导入时间模块

desired_caps = {} #配置参数的字典
desired_caps['platformName'] = 'Android' 
desired_caps['platformVersion'] = '6.0'
desired_caps['deviceName'] = 'OPPO R17 Pro'
desired_caps['appPackage'] = 'com.android.calculator2'
desired_caps['appActivity'] = 'com.android.calculator2.Calculator'
desired_caps['udid'] = 'xxxx' #xxxx不是真的udid,写真的udid
desired_caps['noReset'] = 'True'

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) #第一个参数是默认的,不需要更改(wd 可以理解是WebDriver 的缩写)

driver.find_element_by_id("com.android.calculator2:id/digit_1").click()   #通过id找到数字1并且点击
driver.find_element_by_id("com.android.calculator2:id/digit_5").click()
driver.find_element_by_id("com.android.calculator2:id/digit_9").click()
driver.find_element_by_id("com.android.calculator2:id/del").click() #点击删除键
driver.find_element_by_id("com.android.calculator2:id/digit_9").click()
driver.find_element_by_id("com.android.calculator2:id/digit_5").click()
driver.find_element_by_id("com.android.calculator2:id/op_add").click() #点击‘+’
driver.find_element_by_id("com.android.calculator2:id/digit_6").click()
driver.find_element_by_id("com.android.calculator2:id/eq").click() #点击‘=’

time.sleep(5) #这个是为了能够看清结果,可删除
driver.quit()
上一篇下一篇

猜你喜欢

热点阅读