java - 如何将我的测试结果从 selenium 发送到 testrail
问题描述
我无法将我的测试结果从 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中完成的确切方式吗?我不确定我做得对。
解决方案
我正在使用我自己定制的测试轨 API,但它都是基于相同的东西。
但是看官方的gurrock, 文档
首先,您需要在 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 不同。
推荐阅读
- sql - ORA-01722: 无效的数字行以逗号传输 VARCHAR2 TO_NUMBER 开头
- conv-neural-network - tensorflow conv2d 参数个数
- google-apps-script - Google Forms Apps 脚本 - 随机缺少选项
- r - dbPool 对象即将到期
- c - C中的不同演员表
- angular - 如何在角度设置属性值
- javascript - 试图理解新的 Promise 和 Async/await
- python - 安装与 python 3.7.4 兼容的旧虚拟环境?
- php - 在 opencart v3.0.3.2 中设置 payTM 插件时出错
- python - 使用 Flask 和 HTML 的开/关按钮动作控制