【问题标题】:How to send my test results from selenium to testrail如何将我的测试结果从 selenium 发送到 testrail
【发布时间】:2018-07-06 11:55:31
【问题描述】:

我无法将我的测试结果从 selenium 发送到 testrail。我似乎无法使用提供的文书工作来弄清楚。我目前正在使用这个:

public class login_errors extends ConditionsWebDriverFactory {

public static String TEST_RUN_ID                = "R1713";
public static String TESTRAIL_USERNAME          = "testemai9@hotmail.com";
public static String TESTRAIL_PASSWORD          = "Password1";
public static String RAILS_ENGINE_URL           = "https://testproj.testrail.com/";
public static final int TEST_CASE_PASSED_STATUS = 1;
public static final int TEST_CASE_FAILED_STATUS = 5;


@Test
public void login_errors() throws IOException, APIException {
    Header header = new Header();
    header.guest_select_login();
    Pages.Login login = new Pages.Login();
    login.login_with_empty_fields();
    login.login_with_invalid_email();
    login.email_or_password_incorrect();
    login.login_open_and_close();
    login_errors.addResultForTestCase(TEST_RUN_ID,TEST_CASE_PASSED_STATUS," ");

}
public static void addResultForTestCase(String testCaseId, int status,
                                        String error) throws IOException, APIException {

    String testRunId = TEST_RUN_ID;

    APIClient client = new APIClient(RAILS_ENGINE_URL);
    client.setUser(TESTRAIL_USERNAME);
    client.setPassword(TESTRAIL_PASSWORD);
    Map data = new HashMap();
    data.put("status_id", status);
    data.put("comment", "Test Executed - Status updated automatically from Selenium test automation.");
    client.sendPost("add_result_for_case/"+testRunId+"/"+testCaseId+"",data );

}

}

但我不断收到以下异常:

com.gurock.testrail.APIException:TestRail API 返回 HTTP 401("身份验证失败:用户/密码无效或丢失或 会话 cookie。”)

任何人都可以帮助我了解这应该在 java 中完成的确切方式吗?我不确定我做得对。

【问题讨论】:

  • 我查看了文档,您的代码看起来没有问题。错误可能实际上是它的样子,您确定可以使用 URL 中的给定凭据登录吗? (我无法访问网址,testproj.testrail.com,是私人服务器还是什么?)
  • 哦,不抱歉,我刚刚更改了我的网址以将其放在网站上,我不希望我的登录可用。我会不会错过任何我想知道的东西。还是他的网址格式不正确。我不确定
  • URL 格式对我来说也不错。你可以尝试另一种格式,“http:///testrail/”吗?是的,您不必共享您的凭据,但您可以手动登录,对吗?
  • 是的,我可以从那里手动登录

标签: java selenium testrail


【解决方案1】:

我正在使用我自己定制的测试轨道 API,但它都是基于相同的东西。

但是看官方的gurrock, documentation

首先您需要在 URL 端点的末尾添加“testrail/”,

APIClient client = new APIClient("http://<server>/testrail/");
client.setUser("..");
client.setPassword("..");

应该是这样的:

public static String RAILS_ENGINE_URL ="https://testproj.testrail.com/testrail/";

我发现的第二件事是,您正在为测试用例 ID 发送变量中的测试运行 ID,这不一样。

另外一点是测试用例 ID 前面不应该是纯数字,而不是像“R123”而是“123”

你的方法应该接受一个参数,testRunId

public static void addResultForTestCase(String testRunId, String testCaseId, int status,String error) throws IOException, APIException {
    String testRunId = TEST_RUN_ID;

    APIClient client = new APIClient(RAILS_ENGINE_URL);
    client.setUser(TESTRAIL_USERNAME);
    client.setPassword(TESTRAIL_PASSWORD);
    Map data = new HashMap();
    data.put("status_id", status);
    data.put("comment", "Test Executed - Status updated automatically from Selenium test automation.");
    client.sendPost("add_result_for_case/"+testRunId+"/"+testCaseId+"",data );
}

另一件事是你必须已经创建了测试运行,所以你可以拥有你自己的测试运行 ID,如下图所示:

而且测试用例 ID 与 testrun id 不同。

【讨论】:

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