How to invoke Android emulator by using feature file in Karate Framework

Viewed 369

Am going to open Google URL in emulator when execute feature file in karate framework. But i getting test case is failed due to following reason:

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"}}}

"Please provide me solution"

Pre-condition: Appium Server and emulator is running. and below is feature file.

Feature: Mobile automation

Background:

 * 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')
1 Answers

your driverCaps is unused as you have defined it after configure,

using the below snippet I was able to launch a chrome browser in Android Emulator.

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')

Note:

if you are facing any chrome driver issue please refer : chromedriver with Appium
currently only xpath locator are working so try with xpath locators

Related