Я пытаюсь сделать POC с новой поддержкой карате 0.9.0.RC4 для автоматизации пользовательского интерфейса.
- Иметь файл функций, который проверяет URL, на котором находится пользователь
- Этот файл функций в качестве фонового шага вызывает другой файл функций, который создает экземпляр драйвера и переходит на веб-страницу
Файл функций, который выполняет проверку, выглядит примерно так:
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'
Содержимое base-page-login.feature выглядит примерно так:
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']
Вот мои санированные журналы:
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
Я ожидал, что если бы я управлял Selenium напрямую, то использовал бы тот же экземпляр Selenium. Поведение, которое я вижу, заключается в том, что драйвер закрывается, когда код достигает точки возврата к файлу «проверки». Поскольку это RC, это может быть известной проблемой или ошибкой с моей стороны, но я хотел получить информацию от сообщества.