免责声明:我是一个在工作中学习的编程新手。
我已经为使用Cucumber和C# Selenium设置了一个Specflow项目,并下载了TestRail应用编程接口。我遵循了一个现有的示例,在场景结束时将测试结果发布到静态测试Rail ID。
{ Gurock.TestRail.APIClient client =新密码(“https://testrail.placeholder.com/testrail”);client.User = "user@email.com";//将您用户的邮箱client.Password =“Gurock.TestRail.APIClient”放在这里;//将您用户的密码放在这里
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.}我可以通过使用基于Scenario标签的If将上面的代码链接到一个场景,例如
if (ScenarioContext.Current.ScenarioInfo.Tags.Contains("case_id"))但这样做的问题是,我必须为每个场景复制上面的代码,每次都要使用唯一的IF语句和标记。我想要的是一种参数化发布的方法,这样我只需要一个代码块,就可以将每个场景的结果发送到正确的静态TestRail ID。
发布于 2017-06-14 20:17:24
我会在CaseID标签前加上前缀,这样您就可以将它们与普通标签区分开来。
以TC_为例,这样您的标记的名称就像TC_1,TC_42,...
要获得测试用例id,您必须在ScenarioContext.Current.ScenarioInfo.Tags中找到一个以TC_开头的条目
这段代码可能如下所示:
var tags = ScenarioContext.Current.ScenarioInfo.Tags;
var testCaseIds = tags
.Where(i => i.StartsWith("TC_")) //get all entries that start with TC_
.Select(i => i.Substring(3)); //get only the part after TC_
.ToList();现在您有了一个包含测试用例ids的列表,您可以将该列表传递给TestRails应用编程接口。
https://stackoverflow.com/questions/44366970
复制相似问题