Websocket returns null values - karate

When i am trying execute the below code
Scenario: demo
* def socket = karate.webSocket("wss://socketsbay.com/wss/v2/1/demo/")
* socket.send('Test Karate')
And listen 5000
Then match listenResult == 'Test Karate'
i am getting below error
22:02:32.320 [nioEventLoopGroup-2-1] DEBUG c.i.k.http.WebSocketClientHandler - websocket client connected
22:02:32.330 [main] DEBUG com.intuit.karate - entered listen state with timeout: 5000
22:02:37.335 [main] ERROR com.intuit.karate - listen timed out: java.util.concurrent.TimeoutException
22:02:37.336 [main] DEBUG com.intuit.karate - exit listen state with result: null
22:02:37.348 [main] ERROR com.intuit.karate - classpath:websocket/test.feature:28
Then match listenResult == 'Test Karate'
match failed: EQUALS
$ | data types don't match (NULL:STRING)
null
'Test Karate'
Meanwhile in socketsbay.com ui i can able to notice message has been delivered and i can able to see below screenshot
enter image description here
Requesting to help here

It works fine. Because you have to send a message from the server.
* def socket = karate.webSocket('wss://socketsbay.com/wss/v2/1/demo/')
* listen 10000
* match listenResult == 'test'
After starting the test, I went to the UI, clicked "Connect" and then typed test and clicked "Send". It worked fine:
22:34:34.521 [nioEventLoopGroup-2-1] DEBUG c.i.k.http.WebSocketClientHandler - websocket client connected
22:34:34.552 [main] DEBUG com.intuit.karate - entered listen state with timeout: 10000
22:34:41.549 [main] DEBUG com.intuit.karate - exit listen state with result: test
22:34:41.771 [nioEventLoopGroup-2-1] DEBUG c.i.k.http.WebSocketClientHandler - websocket closing
22:34:41.786 [nioEventLoopGroup-2-1] DEBUG c.i.k.http.WebSocketClientHandler - websocket client disconnected

Related

Karate scripts with API request to Splunk server works fine on MAC but fails on windows & pipeline[Alpine linux] [duplicate]

I am working on automating a API which is hosted in China server and when I send a request it throws me timeout exception ( org.apache.http.conn.HttpHostConnectException).
My feature file:
Background:
* url 'http://myurl'
* configure connectTimeout = 500000
Scenario: Get Client details
Given path '/clients'
And header Authorization = 'sdssSSLwWDSD'
When method get
Then match response.client_id == 'TestId'
Error details:
11:22:30.347 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://myurl.com][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10]
11:22:30.365 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {s}->https://myurl.com][total kept alive: 0; route allocated: 1 of 5; total allocated: 1 of 10]
11:22:30.365 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Opening connection {s}->https://myurl.com
11:22:30.384 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to myurl.com/54.223.191.33:443
11:22:30.384 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Connecting socket to myurl.com/54.223.191.33:443 with timeout 500000
11:22:51.407 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connect to myurl.com/54.223.191.33:443 timed out. Connection will be retried using another IP address
11:22:51.407 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to myurl.com/52.80.167.86:443
11:22:51.408 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Connecting socket to myurl.com/52.80.167.86:443 with timeout 500000
11:23:12.438 [main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-0: Shutdown connection
11:23:12.439 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection discarded
11:23:12.440 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {s}->https://myurl.com:443][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10]
11:23:12.440 [main] ERROR com.intuit.karate - org.apache.http.conn.HttpHostConnectException: Connect to myurl.com [myurl.com/54.223.191.33, myurl.com/52.80.167.86] failed: Connection timed out: connect, http call failed after 42094 milliseconds for URL: https://myurl.com/tnc/v1/tnc/all
11:23:12.441 [main] ERROR com.intuit.karate - http request failed:
org.apache.http.conn.HttpHostConnectException: Connect to myurl.com:443 [myurl.com/54.223.191.33, myurl.com/52.80.167.86] failed: Connection timed out: connect
11:23:12.601 [Finalizer] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection manager is shutting down
11:23:12.601 [Finalizer] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection manager shut down
HTML report: (paste into browser to view) | Karate version: 0.9.4
What I have tried yet:
I tried to configure timeout to max as below:
* configure connectTimeout = 500000
It didn't work.
However, the same request when tried from Postman, works fine and I get response within 2000 ms.
Not sure where I am wrong.
Most likely you have a corporate HTTP proxy.
Refer: https://github.com/intuit/karate#configure
* configure proxy = 'http://my.proxy.host:8080'

"Target host not specified" when using json data for Dynamic Scenario Outline

I have upgraded to version 1.0.0 and I am encountering an error that was working fine when using 0.9.6.
Below is a provided Karate sample code which I modified a bit to show how I get the error.
Background:
* url 'https://jsonplaceholder.typicode.com'
* def id = read("id-list.json")
Scenario Outline: [id: <id>] get all users and then get the first user by id
Given path 'users', <id>
When method get
Then status 200
* print id
Examples:
| id |
id-list.json
[{"id":1},{"id":2}]
Error:
Testing started at 11:12 ...
command: --plugin org.jetbrains.plugins.cucumber.java.run.CucumberJvmSMFormatter --monochrome --name ^\[id\: .*\] get all users and then get the first user by id$ --glue com.intuit.karate C:/Users/danna/IdeaProjects/YXC/src/test/java/examples/users/users.feature
11:12:19.580 [main] DEBUG com.intuit.karate.Suite - [config] classpath:karate-config.js
11:12:19.585 [main] INFO com.intuit.karate.Suite - backed up existing 'target\karate-reports' dir to: target\karate-reports_1616551939583
11:12:19.606 [main] INFO c.intuit.karate.core.FeatureRuntime - found scenario at line: 18 - ^\[id\: .*\] get all users and then get the first user by id$
11:12:20.265 [main] INFO com.intuit.karate - karate.env system property was: null
11:12:20.333 [main] INFO c.intuit.karate.core.FeatureRuntime - found scenario at line: 18 - ^\[id\: .*\] get all users and then get the first user by id$
11:12:20.338 [main] INFO com.intuit.karate - karate.env system property was: null
11:12:20.595 [main] ERROR com.intuit.karate - karate.org.apache.http.ProtocolException: Target host is not specified, http call failed after 250 milliseconds for url: /users/1
11:12:20.596 [main] ERROR com.intuit.karate - src/test/java/examples/users/users.feature:12
When method get
http call failed after 250 milliseconds for url: /users/1
src/test/java/examples/users/users.feature:12
http call failed after 250 milliseconds for url: /users/1
src/test/java/examples/users/users.feature:12
11:12:20.596 [main] INFO c.intuit.karate.core.FeatureRuntime - found scenario at line: 18 - ^\[id\: .*\] get all users and then get the first user by id$
11:12:20.600 [main] INFO com.intuit.karate - karate.env system property was: null
11:12:20.601 [main] ERROR com.intuit.karate - karate.org.apache.http.ProtocolException: Target host is not specified, http call failed after 0 milliseconds for url: /users/2
11:12:20.601 [main] ERROR com.intuit.karate - src/test/java/examples/users/users.feature:12
When method get
http call failed after 0 milliseconds for url: /users/2
src/test/java/examples/users/users.feature:12
http call failed after 0 milliseconds for url: /users/2
src/test/java/examples/users/users.feature:12
I think the error was related to this issue but I'm not quite sure .
Any help would be appreciated.
Thanks for reporting this. This sounds like it is related to the same bug, so we have noted it: https://github.com/intuit/karate/issues/1517#issuecomment-805439326
For now you can work around by moving the url line into the first line of the Scenario.

Error using http post request with void output in Karate Framework

I try to run a post request that does not have an output body. The output is void. I get the 200 answer but then it fails. I have already spoken to my colleagues at the company and they have indicated that it is not possible to execute these types of requests in karate. Is it a bug on the part of karate's developers? Here's the error:
[ForkJoinPool-1-worker-1] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection [id: 3][route: {s}->REMOVED:443] can be kept alive indefinitely
[ForkJoinPool-1-worker-1] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-3: set socket timeout to 0
[ForkJoinPool-1-worker-1] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 3][route: {s}->REMOVED:443][total available: 1; route allocated: 1 of 5; total allocated: 1 of 10]
[ForkJoinPool-1-worker-1] ERROR com.intuit.karate - java.lang.RuntimeException: java.io.EOFException, http call failed after 1601 milliseconds for URL:REMOVED
[ForkJoinPool-1-worker-1] ERROR com.intuit.karate - http request failed:
java.lang.RuntimeException: java.io.EOFException
There's a new version just released: https://github.com/intuit/karate/releases/tag/v1.0.0 - so try that first.
Do update here if that works. That said - the log you provided does not help at all. The best thing you can do is follow this process, so that the developers get a decent chance to understand what you mean by "does not have an output body" and "void": https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Karate DSL: Getting connection timeout error

I am working on automating a API which is hosted in China server and when I send a request it throws me timeout exception ( org.apache.http.conn.HttpHostConnectException).
My feature file:
Background:
* url 'http://myurl'
* configure connectTimeout = 500000
Scenario: Get Client details
Given path '/clients'
And header Authorization = 'sdssSSLwWDSD'
When method get
Then match response.client_id == 'TestId'
Error details:
11:22:30.347 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://myurl.com][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10]
11:22:30.365 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {s}->https://myurl.com][total kept alive: 0; route allocated: 1 of 5; total allocated: 1 of 10]
11:22:30.365 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Opening connection {s}->https://myurl.com
11:22:30.384 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to myurl.com/54.223.191.33:443
11:22:30.384 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Connecting socket to myurl.com/54.223.191.33:443 with timeout 500000
11:22:51.407 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connect to myurl.com/54.223.191.33:443 timed out. Connection will be retried using another IP address
11:22:51.407 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to myurl.com/52.80.167.86:443
11:22:51.408 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Connecting socket to myurl.com/52.80.167.86:443 with timeout 500000
11:23:12.438 [main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-0: Shutdown connection
11:23:12.439 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection discarded
11:23:12.440 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {s}->https://myurl.com:443][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10]
11:23:12.440 [main] ERROR com.intuit.karate - org.apache.http.conn.HttpHostConnectException: Connect to myurl.com [myurl.com/54.223.191.33, myurl.com/52.80.167.86] failed: Connection timed out: connect, http call failed after 42094 milliseconds for URL: https://myurl.com/tnc/v1/tnc/all
11:23:12.441 [main] ERROR com.intuit.karate - http request failed:
org.apache.http.conn.HttpHostConnectException: Connect to myurl.com:443 [myurl.com/54.223.191.33, myurl.com/52.80.167.86] failed: Connection timed out: connect
11:23:12.601 [Finalizer] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection manager is shutting down
11:23:12.601 [Finalizer] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection manager shut down
HTML report: (paste into browser to view) | Karate version: 0.9.4
What I have tried yet:
I tried to configure timeout to max as below:
* configure connectTimeout = 500000
It didn't work.
However, the same request when tried from Postman, works fine and I get response within 2000 ms.
Not sure where I am wrong.
Most likely you have a corporate HTTP proxy.
Refer: https://github.com/intuit/karate#configure
* configure proxy = 'http://my.proxy.host:8080'

How can I trace the failure ot TSaslTransport (hive related)

I've been debugging a JDBC Connection error in hive, similar to what was asked here:
Hive JDBC getConnection does not return.
By turning on log4j properly, i finally got down to seeing this , before the getConnection() hangs. What is thrift waiting for ? If this is related to using the wrong thrift APIs, how can I determine versioning differences between client/server?
I have tried copying all libraries from my hive server onto my client app to test if it is some kind of minor thrift class versioning error, but that didnt solve the problem, my JDBC connection still hangs.
0 [main] DEBUG org.apache.thrift.transport.TSaslTransport - opening transport org.apache.thrift.transport.TSaslClientTransport#219ba640
0 [main] DEBUG org.apache.thrift.transport.TSaslTransport - opening transport org.apache.thrift.transport.TSaslClientTransport#219ba640
3 [main] DEBUG org.apache.thrift.transport.TSaslClientTransport - Sending mechanism name PLAIN and initial response of length 14
3 [main] DEBUG org.apache.thrift.transport.TSaslClientTransport - Sending mechanism name PLAIN and initial response of length 14
5 [main] DEBUG org.apache.thrift.transport.TSaslTransport - CLIENT: Writing message with status START and payload length 5
5 [main] DEBUG org.apache.thrift.transport.TSaslTransport - CLIENT: Writing message with status START and payload length 5
5 [main] DEBUG org.apache.thrift.transport.TSaslTransport - CLIENT: Writing message with status COMPLETE and payload length 14
5 [main] DEBUG org.apache.thrift.transport.TSaslTransport - CLIENT: Writing message with status COMPLETE and payload length 14
5 [main] DEBUG org.apache.thrift.transport.TSaslTransport - CLIENT: Start message handled
5 [main] DEBUG org.apache.thrift.transport.TSaslTransport - CLIENT: Start message handled
5 [main] DEBUG org.apache.thrift.transport.TSaslTransport - CLIENT: Main negotiation loop complete
5 [main] DEBUG org.apache.thrift.transport.TSaslTransport - CLIENT: Main negotiation loop complete
6 [main] DEBUG org.apache.thrift.transport.TSaslTransport - CLIENT: SASL Client receiving last message
6 [main] DEBUG org.apache.thrift.transport.TSaslTransport - CLIENT: SASL Client receiving last message