Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to user handler in websocket tests in 1.4.1 #2572

Open
jrx-sjg opened this issue Jun 11, 2024 · 3 comments
Open

Unable to user handler in websocket tests in 1.4.1 #2572

jrx-sjg opened this issue Jun 11, 2024 · 3 comments

Comments

@jrx-sjg
Copy link

jrx-sjg commented Jun 11, 2024

Hi all.

I'm unable to use a handler when using karate.websocket(), as intented in the documentation.

The test is:

@ws-test
Feature: public test
    
@websocket
Scenario: only listening to websocket messages
    * def handler = function(msg) { karate.log('received:', msg); return msg.startsWith('hello'); }
    * def socket = karate.webSocket('wss://ws.postman-echo.com/raw', handler)
    * socket.send('hello world')
    * listen 5000
    * print listenResult

And the error I'm getting is:

[ERROR] Failures: 
[ERROR]   ExamplesTest.testParallel:15 js failed:
>>>>
01: karate.webSocket('wss://ws.postman-echo.com/raw', handler)
<<<<
org.graalvm.polyglot.PolyglotException: Cannot invoke "org.graalvm.polyglot.SourceSection.getCharacters()" because the return value of "org.graalvm.polyglot.Value.getSourceLocation()" is null
- com.intuit.karate.graal.JsFunction$Executable.<init>(JsFunction.java:95)
- com.intuit.karate.graal.JsFunction$Executable.<init>(JsFunction.java:89)
- com.intuit.karate.graal.JsFunction$Instantiable.<init>(JsFunction.java:132)
- com.intuit.karate.graal.JsLambda.<init>(JsLambda.java:37)
- com.intuit.karate.core.ScenarioBridge.webSocket(ScenarioBridge.java:1110)
- com.intuit.karate.core.ScenarioBridge.webSocket(ScenarioBridge.java:1101)
- <js>.:program(Unnamed:1)

classpath:examples/websocket/websocket.feature:7 ==> expected: <0> but was: <1>

This is something that only happens in karate 1.4.1, using 1.4.0 works normally and it calls the handler function and retrieve the messages as intended.

I've tried to use karate.toJava to call the handler, but didn't help.

I've tested everything in a new minimal maven karate template as explained in https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue, and you can replicate everything in the code in the attached .zip using the command: mvn compile test

karate-template.zip

@ptrthomas
Copy link
Member

@jrx-sjg thanks for the report, and it may take a while to get to this. I also wanted to be transparent about the fact that the websocket feature has not been very successful because of its design. recently we re-thought how to test async systems in general and are releasing a set of capabilities which will be closed-source. if you are interested I can let you know when websocket support lands, you can see a preview here: https://github.com/karatelabs/karate-addons/blob/main/karate-websocket/README.md

@jrx-sjg
Copy link
Author

jrx-sjg commented Jun 13, 2024

@ptrthomas thanks so much for the transparency.

My questions are? Will be the open-source basic websocket implementation fixed? What license will be necessary to get access to karate-websocket addon?

Having websocket support was something that made us decide to use karate in our company. However, the fact that it doesn't work in the latest version is something that blocks us a lot.

@ptrthomas
Copy link
Member

ptrthomas commented Jun 13, 2024

@jrx-sjg

Will be the open-source basic websocket implementation fixed

yes, breakage of any existing functionality should be fixed. we also welcome PRs from the community

the license needed is described at the link above (runtime + IDE)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants