首页 > 解决方案 > 如何使用空手道框架中的功能文件调用 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')

标签: 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 定位器


推荐阅读