[英]Browserstack restSharp cURL PUT request conversion
I am trying to convert the following cURL command to C# using restSharp so that I can mark my automated Browserstack tests passed or failed. 我正在尝试使用restSharp将以下cURL命令转换为C#,以便可以标记自动或未通过的Browserstack测试。
curl -u "user:password" -X PUT -H "Content-Type: application/json" -d "{\"status\":\"<new-status>\", \"reason\":\"<reason text>\"}" https://www.browserstack.com/automate/sessions/<session-id>.json
Please note I am very new to C# I have the following code that currently returns an empty json response, I know I am on the right path as changing the request method to POST returns details (as expected) for my session/test: 请注意,我是C#的新手,我有以下代码,当前返回一个空的json响应,我知道我在正确的路径上,因为将请求方法更改为POST会返回会话/测试的详细信息(按预期):
private string markTestPassedorFail(string sesID)
{
var Client = new RestClient();
var Request = new RestRequest();
string sResponse = "";
Client.BaseUrl = new Uri(CapConf.BROWSERSTACK_SESSIONS_URL);
Client.Authenticator = new HttpBasicAuthenticator(CapConf.BROWSERSTACK_USER_NAME, CapConf.BROWSERSTACK_KEY_PASS);
Request.Resource = sesID + ".json";
Request.Method = Method.PUT;
Request.AddHeader("Content-Type", "application/json");
Request.AddJsonBody("{\"status\":\"failed\", \"reason\":\"failed\"}");
try
{
IRestResponse response = Client.Execute(Request);
sResponse = response.Content;
}
catch (Exception ex)
{
Console.WriteLine("Error Marking Test Passed or Fail : \n" + ex.Message);
}
return sResponse;
}
Have you tried the sample code snippet shared in their documentation here - https://www.browserstack.com/automate/c-sharp 您是否尝试过在其文档中共享的示例代码片段-https: //www.browserstack.com/automate/c-sharp
I just pulled up bits of the code snippet there and was able to setup a sample test run, fetch the session ID and later update the session status via REST API. 我只是在那里拉起了代码片段,并且能够设置示例测试运行,获取会话ID并随后通过REST API更新会话状态。
Refer to the following gist: https://gist.github.com/ashwingonsalves/56d7724671054bf623081bdcb30d40b8 请参阅以下要点: https : //gist.github.com/ashwingonsalves/56d7724671054bf623081bdcb30d40b8
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.