[Appium] Hybrid App 에서 Appview ↔️ Webview 모드 전환하는 방법

Soyun Jo·2022년 6월 13일
0

Hybrid application 은 개발 영역에 따라 AppviewWebview 로 나뉘어 있다.

그래서 App Test Automation을 진행할 때,
영역에 따라 각각 Native / Webview에 맞춘 Script를 작성한다면
영역에 따라 Test 세션 속도를 좀 더 빠르게 할 수도 있다.



👉🏼 Context switch 를 통해 Webview로 자동화 전환하기

우선 driver.context 를 통해
현재 노출되는 화면에서의 view contexts 리스트를 리턴받는다.

예를 들어
현재 노출되는 영역이 Native 영역으로만 구성되어 있다면

context의 id list 값은 다음과 같다.

context = driver.contexts

>> context = ['NATIVE_APP']

또한, 현재 노출되는 영역이 Native + Webview 으로 구성되어 있다면

context == driver.contexts

>> context = ['NATIVE_APP', 'WEBVIEW_1']

이런식으로 값이 리턴될 것이다.

Webview context를 사용하게 되면, Selenium commands를 사용할 수 있다는 이점이 있다. 

get("http://some.url.com")와 같은..~ 

해당 값을 받으면 session을 진행하는 영역에 따라 context를 수행해주면 된다!

appview = driver.contexts[0]
webview = driver.contexts[1]

# webview로 session변환
driver.switch_to.context(webview)

# web session 진행 ~~
driver.find_element(By.XPATH, "//button[contains(text(), '장바구니')]").click

# 다시 appview로 컴백!
driver.switch_to.context(appview)

#app session 진행 ~~
driver.find_element(AppiumBy.ID, 'ID placeholder').sendkeys(ID)
driver.quit()


그리고 Webview context에서 session을 시작할 때, 자동으로 webview context 전환해 주는 setting이 따로 있다고 하는데

Desired capabilitiyautoWebview == true 값으로 setting 해놓으면 가능하다고 한다.

자세한건 🔗 Appium documentation 참고 ❗️

profile
생각 10,000 많은 infp 🤔💭

1개의 댓글

comment-user-thumbnail
2022년 10월 15일

네이버 앱을 시도하곤 있는데 안되네요 ㅠㅠ

답글 달기