karate - 如何使用空手道框架中的功能文件调用 Android 模拟器
问题描述
在空手道框架中执行功能文件时,我将在模拟器中打开 Google URL。但是由于以下原因,我得到测试用例失败:
17:49:10.459 [ForkJoinPool-1-worker-1] DEBUG c.i.k.driver.android_1593087505311 - poll attempt #20
for port to be ready - localhost:58674
17:49:13.452 [ForkJoinPool-1-worker-1] DEBUG com.intuit.karate - request:
1 > POST http://localhost:58674/session
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Content-Length: 58
1 > Content-Type: application/json; charset=UTF-8
1 > Host: localhost:58674
1 > User-Agent: Apache-HttpClient/4.5.12 (Java/1.8.0_181)
{"capabilities":{"alwaysMatch":{"browserName":"android"}}}
“请给我解决方案”
前提条件:Appium Server 和模拟器正在运行。以下是功能文件。
特点:移动自动化
背景:
* url 'http://localhost:4723/wd/hub'
* configure driver = { type: 'android' }
* def driverCaps = {"browserName": "chrome","newCommandTimeout":180, "platformVersion": "8.0",
"platformName": "Android","deviceName":"emulator-5554", "avd":"Nexus 6P API 26"}
Scenario: Perform additional operation
Given driver 'https://google.com'
And input("input[name=q]", 'karate dsl')
When submit().click("input[name=btnI]")
# this may fail depending on which part of the world you are in !
Then waitForUrl('https://github.com/intuit/karate')
解决方案
您driverCaps
的未使用,因为您在之后定义了它configure
,
使用下面的代码片段,我能够在 Android Emulator 中启动 chrome 浏览器。
Scenario: launch chrome in appium
* configure driver =
"""
{
type: 'android',
webDriverPath : "/wd/hub",
start: true,
httpConfig : { readTimeout: 120000 }
}
"""
* def desiredConfig =
"""
{
"newCommandTimeout" : 300,
"platformVersion" : "9.0",
"platformName" : "Android",
"connectHardwareKeyboard" : true,
"deviceName" : "emulator-5554",
"avd" : "Pixel2",
"automationName" : "UiAutomator2",
"browserName" : "Chrome"
}
"""
* driver { webDriverSession: { desiredCapabilities : "#(desiredConfig)"} }
* driver 'http://google.com'
* driver.input("//input[@name='q']", 'karate dsl')
笔记:
如果您遇到任何 chrome 驱动程序问题,请参考:带有 Appium 的 chromedriver
目前只有 xpath 定位器正在工作,因此请尝试使用 xpath 定位器
推荐阅读
- python - 从 numpy 数组列表中提取具有 0 个元素的行?
- javascript - 获取 json 并在 Scriptable 中刷新
- c# - 如何强制 Identity Server 4 在每个请求上从 /connect/authorize 路由到我的自定义方法?
- r - 是否可以仅在 R 中使用 difftime 函数(即没有 DD/MM)?
- android - 在以编程方式添加的单选组中的单选按钮之间创建分隔线?
- java - MongoDB Aggregation - 如何使用 spring-data-mongodb 将查询表达式应用到匹配阶段?
- android - android中是否有这样的布局方向
- c++ - 为什么代码块要求我添加“;” 在别人的条件之后?如果我添加“:”,仍然存在逻辑错误。(查看问题正文以获取更多详细信息)
- python - 如何在 selenium 中更快地从动态网站读取数据
- powershell - 无法在powershell的数组列表中获取数组到json