pytest跑appium server用例

安装激活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跑用例

当在测试用例左侧出现三角按钮,就可以执行用例
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值