如何為基於websocket的應用程序實現功能自動化?


0

我的被測應用程序是基於WebSocket的應用程序。

我必須使功能場景自動化,但不知道如何執行操作或不使用什麼工具。

我從身邊搜尋過Google,發現郵遞員目前不支持websocket。

我也遇到了一些代碼示例,但是它不起作用,因為這些示例僅顯示瞭如何向websocket發送文本或從websocket接收文本。

我的應用程序需要不同類型的參數和值,而我遇到的示例僅用於發送文本和接收來自websocket的文本。

因此,如果您知道該怎麼做,請幫助我。

1

I was able to send the basic input as per my requirement using Karate tool.

Below is the code I modified as per my requirement from the example provided in the documentation, I have used Karate archtype to create this maven project and updated the karate-config.js as per the latest documentation:

  1. Feature File Code

@ignore Feature: wspoctest

Scenario: send first webscoket request Given def demoBaseUrl = 'wss://myURL' And def socket = karate.webSocket(demoBaseUrl, null) And def txt = '{"attr1":"value1","attr2":"value2"}'
When socket.send(txt) And def result = socket.listen(5000) Then print(result)

  1. Java Code
package wspoc;

import org.junit.BeforeClass;
import org.junit.runner.RunWith;

import com.intuit.karate.KarateOptions;
import com.intuit.karate.junit4.Karate;

@RunWith(Karate.class)

@KarateOptions(features = "classpath:wspoc/wspoc.feature")
public class WSPOCRunner
{

  @BeforeClass
  public static void beforeClass()
  { // skip 'callSingle' in karate-config.js 
      System.setProperty("karate.env", "mock");
  }
}

Now since my basic scenario is working fine, I am planning to modify and update this into the solution which I want.