自行安装好python,注意!安装python3以上的版本
可以通过命令行安装也可以通过在pycharm中找到Python Interpreter中安装Appium-Python-Client
xxxxxxxxxx
# -*- coding:utf8 -*-
import time
from appium import webdriver
from appium.webdriver.common.touch_action import TouchAction
#appium 配置信息
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '8.0.0'
desired_caps['deviceName'] = 'Pixel 2 API 26'
desired_caps['appPackage'] = 'org.asdtm.goodweather'
desired_caps['appActivity']='.MainActivity'
# 启动webdriver执⾏行行测试脚本
# http://0.0.0.0:4723/wd/hub为默认端⼝口,可修改为启动appium时你所设置的端⼝口,例例 如:http://127.0.0.1:2233/wd/hub
driver = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)
driver.implicitly_wait(20)
time.sleep(2)
#testcase0:refresh the weather 根据控件的ID来获取控件
el = driver.find_elements_by_id("org.asdtm.goodweather:id/main_menu_refresh")[0]
el.click() # 点击该控件
time.sleep(4)
#testcase1:graph 根据控件的class_name来获取控件
el = driver.find_elements_by_class_name("android.widget.ImageButton")[0]
el.click()# 点击该控件
time.sleep(2)
el = driver.find_elements_by_id("org.asdtm.goodweather:id/design_menu_item_text")[1]
el.click() # 点击该控件
time.sleep(2)
driver.back()
driver.quit()#退出应用
启动appium,再执⾏测试脚本即可对应⽤进⾏测试。
其中testcase1对应移动应用的执行路径为下图中0-1-2: