安装激活pycharm
官网下载安装
激活 https://blog.csdn.net/harrain/article/details/106059067
安装pytest
pip3 install -U pytest
查看pytest 版本
pytest --version
改造用例
# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python
from appium import webdriver
class TestDemo:
def setup(self):
caps = {}
caps["appActivity"] = ".HomeActivity"
caps["platformName"] = "Android"
caps["deviceName"] = "JTK5T19917028084"
caps["appPackage"] = "com.xxx"
self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
def test_demo(self):
el3 = self.driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ListView/android.widget.RelativeLayout[1]/android.widget.TextView")
el3.click()
el4 = self.driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.GridView/android.widget.LinearLayout[2]/android.widget.ImageView")
el4.click()
el5 = self.driver.find_element_by_id("com.xxx.sdk.demo:id/xxx_native_showvideo")
el5.click()
def teardown(self):
self.driver.quit()
pycharm设置pytest 测试环境
PyCharm - Preference - Tools - Python Integrated Tool, 将Testing切换到pytest
启动Appium Server
appium -g ~/temp/appium_log #log存储到appium_log文件
如果不启动appium server就执行用例,会报错:
/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py:74: ConnectionRefusedError
During handling of the above exception, another exception occurred:
self = <urllib3.connectionpool.HTTPConnectionPool object at 0x10f154470>
method = ‘POST’, url = ‘/wd/hub/session’
body = ‘{“capabilities”: {“firstMatch”: [{“platformName”: “ios”, “appium:automationName”: “xcuitest”, “appium:app”: “/Users/d…cxwezzxd/Build/Products/Debug-iphonesimulator/MTGSDKSample.app”, “deviceName”: “iPhone 8”, “platformVersion”: “13.3”}}’
headers = {‘Accept’: ‘application/json’, ‘Connection’: ‘keep-alive’, ‘Content-Type’: ‘application/json;charset=UTF-8’, ‘User-Agent’: ‘appium/python 0.52 (selenium/3.141.0 (python mac))’, …}
pytest跑用例
当在测试用例左侧出现三角按钮,就可以执行用例