2016-12-14 19 views
0

restSharp を使用して、次のcURLコマンドをC#に変換しようとしています。これにより、自動化されたBrowserstackテストに合格または不合格をマークできます。Browserstack restSharp cURL PUTリクエスト変換

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 

私は現在、空のJSONレスポンスを返す次のコードを持つC#に非常に新しいです、私は(予想通り)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; 
    } 

答えて

0

あなたはここに彼らのドキュメントで共有するサンプルコードスニペットを試してみました - https://www.browserstack.com/automate/c-sharp

を私は、そこにコードスニペットのビットを引き上げ、サンプルテストランをセットアップすることができましたセッションIDをフェッチし、後でREST APIを使用してセッションのステータスを日付付けします。

  1. サンプルテスト - https://www.browserstack.com/automate/c-sharp#getting-started
  2. セッションID - REST API経由 https://www.browserstack.com/automate/c-sharp#session-id
  3. セッションステータスの更新 - https://www.browserstack.com/automate/c-sharp#rest-api

以下の要旨を参照してください。 https://gist.github.com/ashwingonsalves/56d7724671054bf623081bdcb30d40b8

関連する問題