如何在空手道中将驱动程序上下文从Android切换到WebView [英] How to switch driver context from Android to webview in karate
问题描述
我正在研究一个使用Karate和appium自动化移动应用程序的项目.我正在处理的应用程序似乎是混合应用程序.当我启动该应用程序时,它会将我重定向到一个Web URL进行登录(Web浏览器),并且我的空手道测试无法找到登录页面下方的元素.
I'm working on a project to automate a mobile application using Karate and appium. The application that I'm working upon seems to be a hybrid one. When I launch the app it redirects me to a web URL to sign-in(web browser) and my karate tests are not able to locate elements present under the sign-in page.
Feature: android test
Background: App Preset
* configure driver = { type: 'android', webDriverUrl : 'xxxxx', start: false, httpConfig : { readTimeout: 120000 } }
Scenario: android mobile app UI tests
Given driver { webDriverSession: { desiredCapabilities : "#(android.desiredConfig)"} }
And driver.click('//android.widget.Button[@text="Get Started"]')
# Sign details
And click('#signInName')
And input('#signInName', 'someone@gmail.com')
And input('#password', '123456')
推荐答案
空手道默认使您保持在本机应用程序上下文中.您可以通过调用移动命令来检查所有可用的上下文,
karate by default keeps you in the native app context. you can check all the context available by invoking a mobile command,
def contexts = driver.script("mobile: getContexts")
或
json contexts = driver.http.path("contexts").get()
和打印上下文
您应该能够按如下所示将上下文切换到网络视图(而不是使用从上一步中获得的各自的网络视图代替 WEBVIEW_1
),
you should be able to switch context to web-view as below (instead of WEBVIEW_1
use your respective web-view which you got from the previous step),
driver.setContext("WEBVIEW_1")
,然后通过以下方式切换回本机应用程序:
and then switch back to native app by
driver.setContext("NATIVE_APP")
如果遇到任何问题,请尝试使用不同的定位器策略
try with different locator strategies if facing any issue
这篇关于如何在空手道中将驱动程序上下文从Android切换到WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!