【python自动化测试】appium参数化用例
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了【python自动化测试】appium参数化用例,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1662字,纯文字阅读大概需要3分钟。
内容图文
![【python自动化测试】appium参数化用例](/upload/InfoBanner/zyjiaocheng/608/f7d8f00c24b6468d8e277bf9687f5bff.jpg)
在实际测试过程中,有很多测试步骤一样但参数不同的情况。这种情况下,我们可以通过参数化实现编写一个测试,该测试用例可以完成所有相同步骤的测试。
参数化需要用到pytest的装饰器:@pytest.mark.parametrize()
参数化实例:
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from hamcrest import *
import pytest
class TestHamcrest:
def setup(self):
desire_cap = {
"platformName": "Android",
"deviceName": "mvq8aaw4ca5tcamn",
"appActivity": ".view.WelcomeActivityAlias",
"appPackage": "com.xueqiu.android",
"skipServerInstallation": "true",
"noReset": "true",
"unicodeKeyBoard": "true",
"resetKeyBoard": "true"
}
self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desire_cap)
self.driver.implicitly_wait(10)
def teardown(self):
pass
@pytest.mark.parametrize('searchkey,stockCode,expect_price', [
('千百度', '01028', 265),
('小米', '01810', 28)
])
def test_param(self, searchkey, stockCode, expect_price):
self.driver.find_element(MobileBy.ID, "com.xueqiu.android:id/home_search").click()
self.driver.find_element(MobileBy.ID, "com.xueqiu.android:id/search_input_text").send_keys(searchkey)
self.driver.find_element(MobileBy.XPATH,
'//*[@resource-id="com.xueqiu.android:id/listview"]/android.widget.RelativeLayout[1]').click()
price = self.driver.find_element(MobileBy.XPATH,
f"//*[@text={stockCode}]/../../..//*[@resource-id='com.xueqiu.android:id/current_price']")
current_price = float(price.text)
print(current_price)
print(current_price)
print(current_price)
assert_that(current_price, close_to(expect_price, expect_price * 0.1))
- appium的配置中:
-
"unicodeKeyBoard": "true", "resetKeyBoard": "true"
- 是为了能在send_key时输入中文字符,结束后恢复原来的键盘状态。
-
内容总结
以上是互联网集市为您收集整理的【python自动化测试】appium参数化用例全部内容,希望文章能够帮你解决【python自动化测试】appium参数化用例所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。