-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
To add support for websocket #395
Comments
closing due to inactivity |
@4M01 and others - reopening this, and we've made some progress adding websocket helpers to the code. can you provide some examples of test scenarios / requirements |
@ptrthomas I will try to provide some example for this by Sunday. Hope that is fine |
commit message was not descriptive enough, so a few notes:
EDIT: for those looking for the current example (syntax will change slightly): https://github.com/intuit/karate/blob/cukexit/karate-demo/src/test/java/demo/websocket/websocket.feature |
I think the new "native" support for an "await" has turned out really well. Feature: payment service
Background:
* def QueueConsumer = Java.type('mock.contract.QueueConsumer')
* def queue = new QueueConsumer(queueName)
* def handler = function(msg){ karate.signal(msg) }
* eval queue.listen(handler)
* url paymentServiceUrl + '/payments'
Scenario: create, get, update, list and delete payments
Given request { amount: 5.67, description: 'test one' }
When method post
Then status 200
And match response == { id: '#number', amount: 5.67, description: 'test one' }
And def id = response.id
* json shipment = karate.listen(5000)
* print '### received:', shipment
* match shipment == { paymentId: '#(id)', status: 'shipped' } and something I just found out is that which leads us to the code behind the public void listen(java.util.function.Consumer<String> handler) {
setMessageListener(message -> {
TextMessage tm = (TextMessage) message;
try {
handler.accept(tm.getText());
} catch (Exception e) {
throw new RuntimeException(e);
}
});
} and yes, instead of the improved API is designed so the which gives us this beauty that can send as well as receive from a websocket connection while ignoring messages we are not interested in: * def handler = function(msg){ if (msg.startsWith('hello')) karate.signal(msg) }
* def socket = karate.webSocket(demoBaseUrl + '/websocket', handler)
* eval socket.send('Billie')
* def result = karate.listen(5000)
* match result == 'hello Billie !' |
added echo example, support binary messages introduced type conversion for bytes
so if a signal arrives before we start listening it will still be handled
0.9.0 released |
Karate supports HTTP protocol, it would be great if it can support Websocket.
The text was updated successfully, but these errors were encountered: