简体   繁体   English

Appium + Python(pytest) 并行测试使用参数化问题

[英]Appium + Python(pytest) Parallel Testing Using Parameterization Problem

I am writing through Google Translate, so the sentence may not be smooth.我是通过谷歌翻译写作的,所以句子可能不流畅。 sorry.对不起。

I'm using appium,pytest to create mobile test automation.我正在使用 appium,pytest 创建移动测试自动化。

Using the "Devices" dictionary使用“设备”字典

I want to freely control the parallel test.我想自由控制并行测试。

During parallel testing,在并行测试期间,

to command "pytest -n 2" I am doing it with命令“pytest -n 2”我正在做

how udid, deviceName, systemPort如何udid,deviceName,systemPort

@pytest.mark.parameterize Can it be delivered individually in??? @pytest.mark.parameterize 可以单独投递吗???

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
import pytest

Devices = [
    {'udid': 'R5CR10GR9CE','deviceName': 'A51','systemPort':'8200'},
    {'udid': '277986c73c017ece','deviceName': 'Note9','systemPort':'8201'},
    {'udid': '52005c484f1515c1','deviceName': 'J7','systemPort':'8202'}
]

usingDevice = Devices

**@pytest.mark.parametrize("udid, deviceName, systemPort",usingDevice)**
def test_app(udid, deviceName, systemPort) :
    caps = {
        "platformName": "Android",
        "appium:appPackage": "com.sec.android.app.popupcalculator",
        "appium:appActivity": "com.sec.android.app.popupcalculator.Calculator",
        "automationName": "uiautomator2",
        "udid" : udid,
        "deviceName" : deviceName,
        "systemPort" : int(systemPort)
    }

    driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_capabilities= caps)
    driver.implicitly_wait(10)
    driver.find_element(MobileBy.ACCESSIBILITY_ID,"3").click()
    driver.find_element(MobileBy.ACCESSIBILITY_ID,"9").click()
    driver.find_element(MobileBy.ACCESSIBILITY_ID,"9").click()
@pytest.mark.parametrize("udid, deviceName, systemPort",[
    ('R5CR10GR9CE','A51','8205'),
    ('52005c484f1515c1','J7','8206')
    ])

I tried with This is achieved by hardcoding.我试过这是通过硬编码实现的。

What should I do to be successful with a form like the attached code???我应该怎么做才能成功使用附加代码这样的表格??? Long post, thank you for reading.文章很长,感谢阅读。

I've found a solution.我找到了解决方案。

If you proceed as follows, the parallel test proceeds normally.如果您进行如下操作,并行测试将正常进行。

However, if you have a better idea, please share...但是,如果您有更好的主意,请分享...

thank you.谢谢你。

Devices = [
    {'udid': 'R5CR10GR9CE','deviceName': 'A51','systemPort':'8204'},
    {'udid': '277986c73c017ece','deviceName': 'Note9','systemPort':'8206'},
    {'udid': '52005c484f1515c1','deviceName': 'J7','systemPort':'8205'}
]

@pytest.mark.parametrize("usingDevice",Devices)
def test_app(usingDevice) :
    # print(usingDevice['udid'])
    # print(usingDevice['deviceName'])
    # print(usingDevice['systemPort'])
    caps = {
        "platformName": "Android",
        "appium:appPackage": "com.sec.android.app.popupcalculator",
        "appium:appActivity": "com.sec.android.app.popupcalculator.Calculator",
        "automationName": "uiautomator2",
        "udid" : usingDevice['udid'],
        "deviceName" : usingDevice['deviceName'],
        "systemPort" : int(usingDevice['systemPort'])
    }

    driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_capabilities= caps)
    driver.implicitly_wait(10)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM