0

I am writing through Google Translate, so the sentence may not be smooth. sorry.

I'm using appium,pytest to create mobile test automation.

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

how udid, deviceName, systemPort

@pytest.mark.parameterize Can it be delivered individually in???

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.

2 Answers2

0

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)
0

You can also try this

from appium.options.android import UiAutomator2Options

DEVICES_LIST = [
{
    "device": "Google Pixel 3 - 1",
    "os_version": "9.0",
    "ud_id": "Add ud id",
    "platform": "Android",
    "systemPort": "8200",
    "chromeDriverPort": "8101",
},
{
    "device": "Google Pixel 3 - 2",
    "os_version": "9.0",
    "ud_id": "Add ud id",
    "platform": "Android",
    "systemPort": "8201",
    "chromeDriverPort": "8102",
},]




@pytest.fixture(scope="session", params=DEVICES_LIST)
def driver(request):
    device = request.param.get("device")
    os_version = request.param.get("os_version")
    ud_id = request.param.get("ud_id")
    platform = request.param.get("platform")
    system_port = request.param.get("systemPort")

    options = UiAutomator2Options().load_capabilities(
    {
        "app": APP_URL,
        "platformVersion": os_version,
        "device": device,
        "udid": ud_id,
        "autoGrantPermissions": True,
        "appPackage": "com.sample",
        "appActivity": "activities.Splash",
        "platformName": platform,
        "deviceName": device,
        "systemPort": system_port,
        "chromedriverPort": chrome_driver_port,
    }
    )
    driver = webdriver.Remote(APPIUM_SERVER, options=options)

Let me know if you want more details.

Apart from this, you can also modify in such a way that it does construct this DEVICES_LIST automatically from an adb command.

Nithin Mohan
  • 372
  • 1
  • 9