1

I am attempting to do a POC with Karate 0.9.0.RC4's new support for UI automation.

  • Have a feature file that validates the URL the user is on
  • That feature file, as a background step, calls another feature file that instantiates the driver and navigates to the webpage

The feature file that performs the validation looks something like this:

Feature: Browser Automation

  Background:
  * callonce read('base-page-login.feature') { url: pageUrl, username: adminUserName, password: adminPassword}


  Scenario: Login and test location

    Then match driver.location == webUrlBase + '/something/topframe.jsp'

The content of base-page-login.feature looks something like this:

Feature: Open page and login

  Background:
  * configure driver = { type: 'chromedriver', port: 9515, executable: '/Users/me/Code/Library/Drivers/chromedriver' }


  Scenario: Login and test location

    Given location url
    And input //input[@name='username'] = #(username)
    And input //input[@name='password'] = #(password)
    When submit //input[@name='submit']

Here are my sanitized logs:

21:41:48.458 [command-1541133708458] DEBUG c.intuit.karate.shell.CommandThread - command: [/Users/me/Code/Library/Drivers/chromedriver, --port=9515, --user-data-dir=/Users/me/Code/../target/1541133708457-chrome]
21:41:48.462 [main] DEBUG com.intuit.karate.web.DriverUtils - poll attempt #0 for port to be ready - localhost:9515
21:41:48.505 [command-1541133708458] DEBUG com.intuit.karate.web.WebDriver - Starting ChromeDriver 2.43.600229 (3fae4d0cda5334b4f533bede5a4787f7b832d052) on port 9515
21:41:48.506 [command-1541133708458] DEBUG com.intuit.karate.web.WebDriver - Only local connections are allowed.
21:41:48.507 [command-1541133708458] DEBUG com.intuit.karate.web.WebDriver - [1541133708.503][SEVERE]: bind() returned an error, errno=0: Address already in use (48)
21:41:48.507 [command-1541133708458] DEBUG com.intuit.karate.web.WebDriver - IPv4 port not available. Exiting...
21:41:48.508 [command-1541133708458] DEBUG c.intuit.karate.shell.CommandThread - command complete, exit code: 1 - [/Users/me/Code/Library/Drivers/chromedriver, --port=9515, --user-data-dir=/Users/me/Code/../target/1541133708457-chrome]
21:41:48.812 [main] DEBUG com.intuit.karate - request:
1 > POST http://localhost:9515/session
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Content-Length: 48
1 > Content-Type: application/json; charset=UTF-8
1 > Host: localhost:9515
1 > User-Agent: Apache-HttpClient/4.5.5 (Java/11.0.1)
{"desiredCapabilities":{"browserName":"Chrome"}}

21:41:49.890 [main] DEBUG com.intuit.karate - response time in milliseconds: 1077
1 < 200
1 < Content-Length: 903
1 < Content-Type: application/json; charset=utf-8
{"sessionId":"984ad3ef0692e6fa9f258c09c0f2bad3","status":0,"value":{"acceptInsecureCerts":false,"acceptSslCerts":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedriverVersion":"2.43.600229 (3fae4d0cda5334b4f533bede5a4787f7b832d052)","userDataDir":"/var/folders/sh/0xyv3y814d974vbvtkljdxfd603qvc/T/.org.chromium.Chromium.iROiLz"},"cssSelectorsEnabled":true,"databaseEnabled":false,"goog:chromeOptions":{"debuggerAddress":"localhost:57276"},"handlesAlerts":true,"hasTouchScreen":false,"javascriptEnabled":true,"locationContextEnabled":true,"mobileEmulationEnabled":false,"nativeEvents":true,"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platform":"Mac OS X","rotatable":false,"setWindowRect":true,"takesHeapSnapshot":true,"takesScreenshot":true,"unexpectedAlertBehaviour":"","version":"70.0.3538.67","webStorageEnabled":true}}

21:41:49.894 [main] DEBUG com.intuit.karate.web.WebDriver - init session id: 984ad3ef0692e6fa9f258c09c0f2bad3
21:41:49.904 [main] DEBUG com.intuit.karate - request:
2 > GET http://localhost:9515/session/984ad3ef0692e6fa9f258c09c0f2bad3/window
2 > Accept-Encoding: gzip,deflate
2 > Connection: Keep-Alive
2 > Host: localhost:9515
2 > User-Agent: Apache-HttpClient/4.5.5 (Java/11.0.1)

21:41:49.912 [main] DEBUG com.intuit.karate - response time in milliseconds: 8
2 < 200
2 < Content-Length: 111
2 < Content-Type: application/json; charset=utf-8
{"sessionId":"984ad3ef0692e6fa9f258c09c0f2bad3","status":0,"value":"CDwindow-A22B34D78516DB02E2D6D75AB5FB6F73"}

21:41:49.913 [main] DEBUG com.intuit.karate.web.WebDriver - init window id: CDwindow-A22B34D78516DB02E2D6D75AB5FB6F73
21:41:49.932 [main] DEBUG com.intuit.karate - request:
3 > POST http://localhost:9515/session/984ad3ef0692e6fa9f258c09c0f2bad3/url
3 > Accept-Encoding: gzip,deflate
3 > Connection: Keep-Alive
3 > Content-Length: 28
3 > Content-Type: application/json; charset=UTF-8
3 > Host: localhost:9515
3 > User-Agent: Apache-HttpClient/4.5.5 (Java/11.0.1)
{"url":"https://something.com"}

21:41:52.950 [main] DEBUG com.intuit.karate - response time in milliseconds: 3018
3 < 200
3 < Content-Length: 72
3 < Content-Type: application/json; charset=utf-8
{"sessionId":"984ad3ef0692e6fa9f258c09c0f2bad3","status":0,"value":null}

21:41:52.952 [main] DEBUG com.intuit.karate - request:
4 > DELETE http://localhost:9515/session/984ad3ef0692e6fa9f258c09c0f2bad3/window
4 > Accept-Encoding: gzip,deflate
4 > Connection: Keep-Alive
4 > Host: localhost:9515
4 > User-Agent: Apache-HttpClient/4.5.5 (Java/11.0.1)

21:41:53.058 [main] DEBUG com.intuit.karate - response time in milliseconds: 105
4 < 200
4 < Content-Length: 70
4 < Content-Type: application/json; charset=utf-8
{"sessionId":"984ad3ef0692e6fa9f258c09c0f2bad3","status":0,"value":[]}

21:41:53.060 [main] DEBUG com.intuit.karate - request:
5 > DELETE http://localhost:9515/session/984ad3ef0692e6fa9f258c09c0f2bad3
5 > Accept-Encoding: gzip,deflate
5 > Connection: Keep-Alive
5 > Host: localhost:9515
5 > User-Agent: Apache-HttpClient/4.5.5 (Java/11.0.1)

21:41:53.079 [main] DEBUG com.intuit.karate - response time in milliseconds: 19
5 < 200
5 < Content-Length: 40
5 < Content-Type: application/json; charset=utf-8
{"sessionId":"","status":0,"value":null}

21:41:53.080 [main] DEBUG c.intuit.karate.shell.CommandThread - closing command: 1541133708458
Exception in thread "main" java.lang.NullPointerException
    at com.intuit.karate.IdeUtils.details(IdeUtils.java:143)
    at com.intuit.karate.IdeUtils.log(IdeUtils.java:165)
    at com.intuit.karate.IdeUtils.exec(IdeUtils.java:66)
    at cucumber.api.cli.Main.main(Main.java:36)

Process finished with exit code 1

My expectation, if I were managing Selenium directly, would be that the same Selenium instance would be used. The behavior that I see is that the driver closes when the code reaches the point of going back to the "validation" feature file. Being that this is an RC, it could be a known issue or a mistake on my part but I wanted to get input from the community.

1 Answers1

0

You are right, this needs to be fixed. As of now the webdriver instance is auto-closed after any scenario and the solution here is to NOT do it in case where a) it is a called scenario and b) shared scope is being used

I'll incorporate this and we should be looking at a RC5 release within a week.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248