【解決方法】Restapi specflow: specflow BDD シナリオでの 2 番目の API 呼び出しでの最初の API 呼び出しデータの使用

プログラミングQA


I have first API call which gets me ID and once I have got the ID from this api , only then I need to make the second api get call (/api/<Id>/) . It must happen in the series and not parallelly. How can I do this in RestSharp Specflow in Visual Studio 2022

私が試したこと:

最初の API 呼び出しから ID を正常に取得

解決策 1

Specflow で RestSharp を使用している場合は、最初の API 呼び出しを行い、ID を変数に格納できます。 次に、2 番目の API 呼び出しでその変数を使用できます。 これを行う方法の例を次に示します。

// First API call to get the ID
var client = new RestClient("https://www.example.com/api/");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);

// Store the ID in a variable
var id = response.Data.id;

// Second API call using the ID
var client = new RestClient("https://www.example.com/api/" + id);
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);

これにより、2 つの API 呼び出しが正しい順序で行われ、2 番目の API 呼び出しは最初の API 呼び出しから取得した ID を使用します。

コメント

タイトルとURLをコピーしました