Ui Automation - java.net.SocketTimeoutException: Read timed out for "driver url" - karate

My web page is very slow and taking approx 1 minute to load page. Hence causing below line to fail.
* configure driver = { type: 'chromedriver', executable: '/Users/vikas/Apps/chromedriver', showDriverLog: true }
* driver 'http://XXXX.XXX'
I configured readTimeout in karate-config.js but no help:
karate.configure('readTimeout', 60000);
Error Message:
ERROR com.intuit.karate - java.net.SocketTimeoutException: Read timed out, http call failed after 30003 milliseconds for URL: http://localhost:9515/session/c7c09b611f294b8d13ef7d63668b2677/url
ERROR com.intuit.karate - http request failed:
java.net.SocketTimeoutException: Read timed out
For Selenium WebDriver there is infinite timeout for driver.get(url) which can be changed by pageLoadTimeout() .
Is there anything with Karate Core to handle such long page loading.

Yes, the config for the HTTP client used for the UI driver is separate. So you do something like this:
* configure driver = { httpConfig: { readTimeout: 120000 } }
Just add httpConfig to your existing driver configuration.
Refer: https://github.com/intuit/karate/tree/master/karate-core#configure-driver

Related

cannot start mozilla using custom profile in karateUI

I'm using karate 1.3.0 and I'm stuck trying to launch mozilla Firefox v105.0.2 using a specific SSL client certificate.
As a mention, I developed this scenario before, successfuly using Java + Selenium, but now I need to integrate UI functional tests in my API test suite that is using Karate.
I wrote this code:
Scenario:
* def session = {'capabilities': {'alwaysMatch': {'acceptInsecureCerts':true, 'moz:firefoxOptions': {'profile': 'classpath:FFProfile/ste7rob0.zip.b64','log': {'level': 'debug'}}}}}
* def driverConfig = { type: 'geckodriver', showBrowserLog: true, showProcessLog: true, showDriverLog: true, executable: './src/test/resources/driver/mozilla/win64/geckodriver.exe'}
* driverConfig.webDriverSession = session
* configure driver = driverConfig
Given driver monitorUrl
And I was expecting to get a webdriver to access monitorUrl using the profile specified. The profile folder was customized manually, zipped and encoded to base64 on the development machine.
But the result was:
18:20:16.267 [main] WARN com.intuit.karate - http response code: 500, response: {"value":{"error":"unknown error","message":"Invalid byte 58, offset 9.","stacktrace":""}}, request: POST http://localhost:4444/session
18:20:16.268 [main] ERROR c.intuit.karate.driver.DriverOptions - webdriver session create status 500, {"value":{"error":"unknown error","message":"Invalid byte 58, offset 9.","stacktrace":""}}
18:20:16.269 [main] ERROR com.intuit.karate - driver config / start failed: webdriver session create status 500, {"value":{"error":"unknown error","message":"Invalid byte 58, offset 9.","stacktrace":""}}, options: {type=geckodriver, showBrowserLog=true, showProcessLog=true, showDriverLog=true, executable=./src/test/resources/driver/mozilla/win64/geckodriver.exe, webDriverSession={capabilities={alwaysMatch={acceptInsecureCerts=true, moz:firefoxOptions={profile=classpath:FFProfile/ste7rob0.zip.b64, log={level=debug}}}}}, target=null}
java.lang.RuntimeException: webdriver session create status 500, {"value":{"error":"unknown error","message":"Invalid byte 58, offset 9.","stacktrace":""}}
at com.intuit.karate.driver.WebDriver.<init>(WebDriver.java:67)
at com.intuit.karate.driver.firefox.GeckoWebDriver.<init>(GeckoWebDriver.java:42)
at com.intuit.karate.driver.firefox.GeckoWebDriver.start(GeckoWebDriver.java:48)
at com.intuit.karate.driver.DriverOptions.start(DriverOptions.java:316)
at com.intuit.karate.core.ScenarioEngine.driver(ScenarioEngine.java:881)
at com.intuit.karate.ScenarioActions.driver(ScenarioActions.java:426)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at com.intuit.karate.core.StepRuntime.execute(StepRuntime.java:296)
at com.intuit.karate.core.ScenarioRuntime.execute(ScenarioRuntime.java:449)
at com.intuit.karate.core.ScenarioRuntime.run(ScenarioRuntime.java:400)
at com.intuit.karate.core.FeatureRuntime.processScenario(FeatureRuntime.java:199)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at com.intuit.karate.core.ScenarioIterator.tryAdvance(ScenarioIterator.java:162)
at java.base/java.util.Spliterator.forEachRemaining(Spliterator.java:332)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:310)
at java.base/java.util.Spliterators$1Adapter.forEachRemaining(Spliterators.java:706)
at com.intuit.karate.core.FeatureRuntime.run(FeatureRuntime.java:182)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at com.intuit.karate.core.SyncExecutorService.execute(SyncExecutorService.java:70)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:123)
at com.intuit.karate.Suite.run(Suite.java:237)
at com.intuit.karate.Runner$Builder.parallel(Runner.java:496)
at com.intuit.karate.cli.IdeMain.main(IdeMain.java:60)
at cucumber.api.cli.Main.main(Main.java:34)
18:20:16.270 [main] ERROR com.intuit.karate - src/test/java/splmonitor/TC3.acces_autorizat.feature:12
Given driver monitorUrl
driver config / start failed: webdriver session create status 500, {"value":{"error":"unknown error","message":"Invalid byte 58, offset 9.","stacktrace":""}}, options: {type=geckodriver, showBrowserLog=true, showProcessLog=true, showDriverLog=true, executable=./src/test/resources/driver/mozilla/win64/geckodriver.exe, webDriverSession={capabilities={alwaysMatch={acceptInsecureCerts=true, moz:firefoxOptions={profile=classpath:FFProfile/ste7rob0.zip.b64, log={level=debug}}}}}, target=null}
src/test/java/splmonitor/TC3.acces_autorizat.feature:12
18:20:16.270 [geckodriver_1674836415732] WARN com.intuit.karate.shell.Command - exit code was non-zero: 1 - [C:\QA\workspace2022\aliaspay-test-engine\.\src\test\resources\driver\mozilla\win64\geckodriver.exe, --port=4444] working dir: target\geckodriver_1674836415732

Selenium tests error: WebDriverError: unknown error: net::ERR_CONNECTION

I'm trying to run selenium tests but I get this error:
Error: WebDriverError: unknown error: net::ERR_CONNECTION_REFUSED
(Session info: chrome=98.0.4758.102)
(Driver info: chromedriver=98.0.4758.80 (7f0488e8ba0d8e019187c6325a16c29d9b7f4989-refs/branch-heads/4758#{#972}),platform=Windows NT 10.0.19042 x86_64)
...
From: Task: WebDriver.navigate().to(https://localhost:4200/asd)
I tried to update webdriver but still not working. I really know what to do because I'm really new to Protractor etc. How can I solve this issue?
It looks like you are trying to send the browser to https://localhost:4200/asd. This is a URL that is passed to selenium. If you use Selenium Grid make sure that the URL can be reached from there. This especially means no localhost or 127.0.0.1 URLs, as they resolve to the selenium-grid-host.
If you need to detect the local network-IP you can try a variation of (node.js)
var address,
ifaces = require("os").networkInterfaces();
for (const dev in ifaces) {
ifaces[dev].forEach((details) => {
if (details.family === "IPv4" && details.internal === false) {
address = details.address;
}
});
}
and build the URLs with the detected address.

Karate - How to terminate driver instance when mixed with robot?

I have a test that combines the use of a driver and robot. However, I need to terminate the driver instance before invoking robot. Even if I use the explicit driver.close(), the instance remains active. Here's an example (create-input.feature invokes the driver):
Feature: mixing driver and robot
Background:
* call read('../../../../actions/workflow/general/create-input.feature') {sample-id: sampleId}
* configure afterScenario = function(){ karate.call('../../../../actions/auth/signout.feature'); }
Scenario: terminate driver before invoking robot
* print '>>>>>>>>>>>>>>>>>>>BEFORE CLOSE>>>>>>>>>>>>>>', driver
* driver.close()
* print '>>>>>>>>>>>>>>>>>>>AFTER CLOSE>>>>>>>>>>>>>>', driver
* robot { window: '#(windowName)', fork: '#(appPath)', retryCount: '#(retryCount)', autoClose: '#(autoClose)', highlight: '#(highlight)', highlightDuration: '#(highlightDuration)' }
* window(windowName)
* call read('../../../../actions/auth/signin.feature')
After the explicit close, the driver instance remains active:
INFO com.intuit.karate - [print] >>>>>>>>>>>>>>>>>>>BEFORE CLOSE>>>>>>>>>>>>>> com.intuit.karate.driver.chrome.Chrome#d3324b
09:47:24.064 [main] DEBUG c.intuit.karate.driver.DriverOptions - >> {"id":83,"method":"Page.close"}
09:47:24.069 [nioEventLoopGroup-2-1] DEBUG c.intuit.karate.driver.DriverOptions - << {"id":83,"result":{}}
09:47:24.072 [main] INFO com.intuit.karate - [print] >>>>>>>>>>>>>>>>>>>AFTER CLOSE>>>>>>>>>>>>>> com.intuit.karate.driver.chrome.Chrome#d3324b
And when the robot logic is reached, it throws an error:
* window(windowName)
>>>> js failed:
01: window(windowName)
<<<<
org.graalvm.polyglot.PolyglotException: ReferenceError: "window" is not defined
- <js>.:program(Unnamed:1)
09:47:27.917 [main] DEBUG c.intuit.karate.driver.DriverOptions - >> {"id":84,"method":"Page.captureScreenshot"}
09:47:57.919 [main] ERROR c.intuit.karate.driver.DriverOptions - << timed out after milliseconds: 30000 - [id: 84, method: Page.captureScreenshot]
* window(windowName)
scenario [run] failed
failed to get reply for: [id: 84, method: Page.captureScreenshot]
09:47:58.056 [main] WARN com.intuit.karate - 'driver' is active, use 'robot.' prefix for robot methods
I realize that I need to prepend the window() method with robot to make it work, but I'd prefer to just terminate the driver instance prior to invoking robot. Reason being is that I later call other features with assertions specific to robot and with the driver still being active, it causes further issues.
Any suggestions will be greatly appreciated.
Did you try driver.quit() ? https://github.com/intuit/karate/tree/master/karate-core#quit
If that doesn't work (it should !) you can submit an issue, but I insist that you provide a way to replicate: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
As a workaround - you could experiment if using the Java API directly gives you the control you need: https://github.com/intuit/karate#java-api
As always, thanks Peter for a prompt response and turnaround. I tested it with your fix applied and it works as expected. Following is the simplified test I used:
Feature: mixing driver and robot
Background:
* configure driver = { type: 'chrome', showDriverLog: true }
Scenario: terminate driver before invoking robot
* driver 'https://google.com'
* input("input[name=q]", 'karate dsl')
* submit().click("input[name=btnI]")
* waitForUrl('https://github.com/intuit/karate')
* quit()
* robot { window: 'Calculator', fork: 'calc', highlight: true, highlightDuration: 500 }
* click('Clear')
* click('One')
* click('Plus')
* click('Two')
* click('Equals')
* match locate('#CalculatorResults').name == 'Display is 3'
* screenshot()
* click('Close Calculator')

Sequence Execution of Appium Test Cases in TestNG leads to test case failure

Below TestNG execution of test cases leads to failure.
Error - org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server. Original error: Error: socket hang up (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 56 milliseconds
#Test(description = "Test I")
public void TestI() {
System.out.println("Test I");
openApp();
checkForCondition();
}
#Test(description = "Test II")
public void TestII() {
System.out.println("Test II");
openApp();
checkForCondition();
}
Could you place all related stuff, not just two methods? I mean the class, where driver is initialized, called etc. Also I would look at your testng.xml file and pom.xml maven(if you're using it) as well.

WebDriverException: target frame detached while interacting with elements within iframe using ChromeDriver Chrome and Selenium

I use Chromedriver 78.0.3904.70,
WebDriverException: target frame detached exception
has occurred, but in previous version of chromedriver all worked fine.
Now in my iFrame I can't find any elements during the autotest, where should be another iFrame, but i can do it by hand.
Also switching to iFrame doing successfully during autotest. I think may be there is a bug in new chromedriver? Any ideas?
org.openqa.selenium.WebDriverException: target frame detached
(Session info: chrome=78.0.3904.97)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'PDF323-440G4', ip: '172.16.14.147', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 78.0.3904.97, chrome: {chromedriverVersion: 78.0.3904.70 (edb9c9f3de024..., userDataDir: C:\Users\Nikolay\AppData\Lo...}, goog:chromeOptions: {debuggerAddress: localhost:64307}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: c6f28448e742438746371ee017a51dda
This error message...
WebDriverException: target frame detached
...implies that for a certain HttpRequest the resultant HttpServerResponseInfo was net::HTTP_NOT_FOUND.
Details
As per the discussion Some error codes are not standard compliant there were some error codes returned by the ChromeDriver which were not compliant to the W3C standard. They were replaced with the corresponding standard error codes:
asynchronous script timeout -> script timeout
element not visible -> element not interactable
no such session -> invalid session id
session not created exception -> session not created
xpath lookup error -> invalid selector
Additionally, there are some Chrome-specific error codes which still exists and most clients will treat them as unknown error. These error codes are:
chrome not reachable
disconnected
forbidden
no such execution context
tab crashed
target frame detached
This issue was addressed through the bug / commit and the current status is ToBeReleased.
Deep Dive
The error target frame detached is the outcome of case kTargetDetached where case kTargetDetached is defined in http_handler.cc and occurs when the HttpServerResponseInfo contains HTTP_NOT_FOUND as follows:
void HttpHandler::HandleCommand(
const net::HttpServerRequestInfo& request,
const std::string& trimmed_path,
const HttpResponseSenderFunc& send_response_func) {
base::DictionaryValue params;
std::string session_id;
CommandMap::const_iterator iter = command_map_->begin();
while (true) {
if (iter == command_map_->end()) {
if (w3cMode(session_id, session_thread_map_)) {
PrepareResponse(
trimmed_path, send_response_func,
Status(kUnknownCommand, "unknown command: " + trimmed_path),
nullptr, session_id, true);
} else {
std::unique_ptr<net::HttpServerResponseInfo> response(
new net::HttpServerResponseInfo(net::HTTP_NOT_FOUND));
response->SetBody("unknown command: " + trimmed_path, "text/plain");
send_response_func.Run(std::move(response));
}
return;
}
if (internal::MatchesCommand(
request.method, trimmed_path, *iter, &session_id, &params)) {
break;
}
++iter;
}
and most possibly the reason in your case is kTargetDetached:
case kTargetDetached:
response.reset(new net::HttpServerResponseInfo(net::HTTP_NOT_FOUND));
break;
I was also facing the same issue on Version 79. Updated to chrome Version 80.0.3987.53 (Official Build) beta (64-bit) on my mac machine and used chromedriver version 80.0.3987.16 while working with selenium. Switching to iframe is working fine now.
Got a hint from the above point that it has been fixed in version 80. Hope it helps!
As a workaround, we can use a try and catch block for the elements in which this error occurs - and the tests will continue further without stopping
try {
button.click();
} catch (WebDriverException e) {
e.printStackTrace();
}
May not be correct or optimal solution but after adding Thread.sleep and nested try catch block issue got resolved.
Note: in WebDriverException I tried the same element again
try
{
Thread.sleep(1000);
yourWebelement.click();
}
catch(WebDriverException e)
{
yourWebelement.click();
}
catch(Exception ee)
{
ee.printStackTrace();
throw ee;
}
Worked for me:
driver.switchTo().parentFrame();
I had the same issue when my Selenium driver version mismatched the version of my Chrome browser because I updated my web browser to its last version without updating also the Selenium driver.
I fixed the issue by updating also my selenium web driver to match the updated chrome.
I found that I get this error when I have too many instances of ChromeDriver running.
I have an application that attempts to shut down instances of ChromeDriver when I am done with current tests, but when I see this error, I usually find that I have 10-20 instances running because I was debugging some issue, and not letting the clean-up code run.
Open Task Manager and kill old instances!