在带有appium的1个android设备上并行运行测试

时间:2020-06-30 19:15:28

标签: appium pytest appium-android python-appium xdist

Im using pycharm/python 3,7/appium desktop/windows/pytest/xdist 
I want to run 2 testa in parallel in the same android device.
When running them one by one,eveything works well.
When i adding to arguments in pycharm -n 2 (to have 2 workers)
Only 1 test run while the other one stuck.in appium log i see no uiautomator found message

Question 1 is if there is an option to run 2 tests in parralel on android device for instance -so another artical which says no option to run more than 1 driver session on device 

Question 2
If its possible
Understood there is an option to run 2 appiums instances with 2 diff ports.
Is this the approach?

If so how can i initiate the driver in code twice ( 2 ports) and each test to take other driver 

代码: 所需的上限: “ desiredCap”:{ 'platformName':'Android', 'platformVersion':'9', 'deviceName':'POCOPHONE F1', 'browserName':'Chrome', 'chromedriverExecutable':f'{chrome_driver_path} chromedriver.exe', 'automationName':'UiAutomator1'

}

装置:

@pytest.fixture(scope="module")
def setup():
    # ======================= setup for test -can be generic
    now = datetime.datetime.now()
    time_stamp = f"{now.year}{now.month}{now.day}{now.hour}{now.minute}{now.second}"

    # ======================= create folder for logs for specific run
    if not os.environ.get('RUN_TIME_STAMP'):
        time.sleep(1)
        os.environ['RUN_TIME_STAMP'] = f'run_{time_stamp}/'
        new_log_directory = f"{Path(__file__).cwd().parent}/log/{os.environ.get('RUN_TIME_STAMP')}"
        if not os.path.exists(new_log_directory):
            try:
                os.makedirs(new_log_directory)
            except FileExistsError:
                pass
    os.environ['RUNNING_TEST_NAME'] = (os.path.basename(__file__))[:-3] + time_stamp

    # ======================= set logger
    logger = setup_logger()
    logger.info('counting')

    # ======================= device to be tested
    device_tested = all_devices_configuration['pocophone_f1_device']

    # ======================= check if to test device using usb or over the wifi
    # currently when want to work with wifi, run script
    # if usb_or_wifi == 'wifi':
    #     adb_commands = AdbCommand(logger, device_tested)
    #     adb_commands.connect_phone_over_wifi()

    # ======================= check appium is up and return 200 ok
    built_url = f"{protocol}://{appium_server}:{appium_port}/wd/hub/status"
    appium_response = requests.get(built_url)
    appium_http_response = appium_response.status_code
    assert appium_http_response == 200, AssertionFlow(logger, f'appium response is {appium_http_response} instead 200',
                                                      take_screen_shot=False)

    # ======================= init web driver
    desired_capabilities = device_tested['desiredCap']
    driver = webdriver.Remote(f'{protocol}://{appium_server}:{appium_port}/wd/hub', desired_capabilities)
    logger.info('setup completed successfully, starting run tests...')
    yield driver, logger
    tear_down(driver, logger)


def tear_down(driver, logger):
    logger.info('tests run finished')
    driver.close()

2个相同的测试,只是获取差异网址以供检查

def test_chrome_check111(setup):
    # ======================= setup for test -can be generic
    now = datetime.datetime.now()
    time_stamp = f"{now.year}{now.month}{now.day}{now.hour}{now.minute}{now.second}"

    # ======================= create dedicated log for test name
    os.environ['RUNNING_TEST_NAME'] = (os.path.basename(__file__))[:-3] + time_stamp
    # ======================= set logger
    logger = setup_logger()

    # ======================= get url to be tested
    web_driver = setup[0]
    web_driver.get(f'{protocol}://{web_url_tested}')
    inputElement = web_driver.find_element_by_xpath('//*[@id="username"]')
    inputElement.send_keys("bla bla ")

    time.sleep(6)
    print('test passed successfully print')
    logger.

info(“测试成功通过”)

在同一台1台android设备上并行运行2个测试时的

appium日志(第一个测试通过,第二个卡住) (第二次测试卡住后最后一行)

debug] [35m[UiAutomator][39m UiAutomator shut down normally
[debug] [35m[UiAutomator][39m Moving to state 'stopped'
[debug] [35m[ADB][39m Attempting to kill all uiautomator processes
[debug] [35m[ADB][39m Getting IDs of all 'uiautomator' processes
[debug] [35m[ADB][39m Running 'C:\Users\ohad.shay\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s 87f0a109 shell pgrep -f uiautomator'[info] [35m[ADB][39m No 'uiautomator' process has been found
[debug] [35m[UiAutomator][39m Moving to state 'stopped'
[debug] [35m[Logcat][39m Stopping logcat capture
[debug] [35m[ADB][39m Running 'C:\Users\ohad.shay\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s 87f0a109 shell am force-stop io.appium.unlock'

0 个答案:

没有答案