如何在空手道中将驱动程序上下文从 Android 切换到 webview [英] How to switch driver context from Android to webview in karate

查看:22
本文介绍了如何在空手道中将驱动程序上下文从 Android 切换到 webview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开展一个项目,该项目使用 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")

然后通过

driver.setContext("NATIVE_APP")

如果遇到任何问题,请尝试使用不同的定位器策略

try with different locator strategies if facing any issue

这篇关于如何在空手道中将驱动程序上下文从 Android 切换到 webview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆