如何在空手道中测试基于 STOMP 协议的 Web 套接字?
How to test STOMP protocol based Web sockets in Karate?
我正在尝试使用空手道编写 Web 套接字测试用例。在我的应用程序中,客户端将订阅各种目的地(“/topic/notifs”、“/topic/alerts”、“/topic/errors”)等
Scenario: text messages
And def socket = karate.webSocket('ws://my websocket url')
When socket.send('hello world!')
And def result = socket.listen(5000)
Then match result == 'hello world!'
When socket.send('another test')
And def result = socket.listen(5000)
Then match result == 'another test'
我试过使用上面的代码片段。但结果为空..
你能帮我如何订阅目的地并为此编写测试用例吗?
您可以像这样创建任意数量的 websocket 实例:
* def socket1 = karate.webSocket('ws://echo.websocket.org')
* def socket2 = karate.webSocket('ws://echo.websocket.org')
* socket1.send('hello world!')
* socket2.send('another test')
* def result1 = socket1.listen(5000)
* match result1 == 'hello world!'
* def result2 = socket2.listen(5000)
* match result2 == 'another test'
因此,现在由您决定如何管理发送的内容以及何时等待 listen()
方法取消阻止。请阅读文档:https://github.com/intuit/karate#websocket
我正在尝试使用空手道编写 Web 套接字测试用例。在我的应用程序中,客户端将订阅各种目的地(“/topic/notifs”、“/topic/alerts”、“/topic/errors”)等
Scenario: text messages
And def socket = karate.webSocket('ws://my websocket url')
When socket.send('hello world!')
And def result = socket.listen(5000)
Then match result == 'hello world!'
When socket.send('another test')
And def result = socket.listen(5000)
Then match result == 'another test'
我试过使用上面的代码片段。但结果为空.. 你能帮我如何订阅目的地并为此编写测试用例吗?
您可以像这样创建任意数量的 websocket 实例:
* def socket1 = karate.webSocket('ws://echo.websocket.org')
* def socket2 = karate.webSocket('ws://echo.websocket.org')
* socket1.send('hello world!')
* socket2.send('another test')
* def result1 = socket1.listen(5000)
* match result1 == 'hello world!'
* def result2 = socket2.listen(5000)
* match result2 == 'another test'
因此,现在由您决定如何管理发送的内容以及何时等待 listen()
方法取消阻止。请阅读文档:https://github.com/intuit/karate#websocket