【问题标题】:Posting SpecFlow results to TestRail将 SpecFlow 结果发布到 TestRail
【发布时间】:2017-06-05 10:30:01
【问题描述】:

免责声明:我是一个在工作中学习的相对编码新手。

我已经设置了一个使用 Cucumber 和 C# Selenium 的 Specflow 项目,并下载了 TestRail API。我按照现有示例在场景结束时将测试结果发布到静态 Test Rail ID。

{ Gurock.TestRail.APIClient 客户端 = new Gurock.TestRail.APIClient("https://testrail.placeholder.com/testrail"); client.User = "user@email.com"; //把你的用户的电子邮件放在这里 client.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 将上述代码链接到场景,例如

if (ScenarioContext.Current.ScenarioInfo.Tags.Contains("case_id"))

但是这样做的问题是我必须为每个场景复制上面的代码,每次都使用唯一的 IF 语句和标记。我想要的是一种将帖子参数化的方法,这样我只需要一个代码块就可以将每个场景的结果发送到正确的静态 TestRail ID。

【问题讨论】:

    标签: c# json specflow testrail


    【解决方案1】:

    我会为 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();
    

    现在您有了一个包含测试用例 ID 的列表,您可以将其传递给 TestRails API。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多