免責聲明:我是一位在工作中學習的相對編碼新手。發佈SpecFlow結果到TestRail
我已經設置了一個使用Cucumber和C#Selenium的Specflow項目並下載了TestRail API。我遵循現有示例將測試結果發佈到方案末尾的靜態測試導軌ID。
{ Gurock.TestRail.APIClient client = new Gurock.TestRail.APIClient(「https://testrail.placeholder.com/testrail」); client.User =「[email protected]」; //將用戶的電子郵件放在這裏 client.Password =「password」; //把你的用戶的密碼,這裏
Dictionary<string, object> testResult = new Dictionary<string, object>();
if (null != ScenarioContext.Current.TestError)
{
testResult["status_id"] = "5"; //failed;
testResult["comment"] = ScenarioContext.Current.TestError.ToString();
}
else
{
testResult["status_id"] = "1"; //passed
}
client.SendPost("add_result_for_case/:run_id/:case_id"); //Here I am using a hardcoded test id.}
我可以在上面的代碼鏈接到方案通過使用基於場景標籤,例如如果一個
if (ScenarioContext.Current.ScenarioInfo.Tags.Contains("case_id"))
但問題是,我將不得不復制上面的代碼爲每個方案,每次都有一個獨特的IF語句和標記。我想要的是一種使發帖準確無誤的方式,這樣我只需要一段代碼就可以將每個場景的結果發送到正確的靜態TestRail ID。