如何将我的测试结果从硒发送到Testrail

时间:2018-07-06 11:55:32

标签: java selenium testrail

我无法将测试结果从硒发送到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中完成此操作的确切方法吗?我不确定我做的是否正确。

1 个答案:

答案 0 :(得分:1)

我正在使用自己定制的API用于testrail,但它们都是基于同一件事。

但是,在官方官场, 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 );
}

另一件事是,您必须创建了testrun,因此您可以拥有自己的testrun ID,例如以下所示:

enter image description here

并且测试案例ID与测试运行ID不同。