본문 바로가기
코딩/Mobile 자동화 (new)

appium 자동화 2024 - 8) PC web + Mobile 동시 자동화

by salzzak 2024. 3. 29.
728x90

 

setting.py

import pytest


from appium import webdriver as appium_webdriver
from appium.options.android import UiAutomator2Options
from selenium import webdriver as selenium_webdriver
from selenium.webdriver import Chrome

# appium 세팅
@pytest.fixture(scope="module")
def driver_m():
    capabilities = dict(
        platformName='Android',
        automationName='uiautomator2'
    )

    appium_server_url = 'http://localhost:4723/wd/hub'

    driver = appium_webdriver.Remote(appium_server_url, options=UiAutomator2Options().load_capabilities(capabilities))

    driver.press_keycode(3)

    yield driver
    driver.quit()


@pytest.fixture(scope="module")
def driver_w():
    driver = selenium_webdriver.Chrome()

    yield driver
    driver.quit()

 

이전에는 driver를 하나만 설정했지만,

이번에는 각각 driver_m / driver_w 으로 만들어준다.

 

test_case_01.py

from Basic import *


def test_case_01(driver_m: Chrome, driver_w: Chrome):

    driver_w.get("https://www.naver.com//")
    wait_Element(driver_w,'//*[@id="shortcutArea"]/ul/li[1]/a/span[1]').click()

    wait_Element(driver_m, home_clock).click()
    wait_Element(driver_m, clock_stopwatch).click()
    wait_Element(driver_m, clock_worldtime).click()
    wait_Element(driver_m, clock_timer).click()

    time.sleep(10)

    assert 1;

 

driver_w 는 web 동작 /  driver_m 는 mobile 동작 되는걸 확인할 수 있다.

 

* 참고 wait_Element 함수

def wait_Element(driver, xpath):
    location = xpath

    try:
        element:WebElement = WebDriverWait(driver, 5).until(
            EC.presence_of_element_located((By.XPATH, xpath))
        )
        return element

    except TimeoutException:
        print(xpath + " Timeout!")
        return False

 

 

 

 

 

https://salzzak.tistory.com/100

 

인생레벨이 머리 위에 보이는 만화

 

salzzak.tistory.com

 

댓글