Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将我的测试结果从selenium发送到testrail_Java_Selenium_Testrail - Fatal编程技术网

Java 如何将我的测试结果从selenium发送到testrail

Java 如何将我的测试结果从selenium发送到testrail,java,selenium,testrail,Java,Selenium,Testrail,我无法将测试结果从selenium发送到。我似乎无法用提供的文件来解决这个问题。我目前正在使用: public class login_errors extends ConditionsWebDriverFactory { public static String TEST_RUN_ID = "R1713"; public static String TESTRAIL_USERNAME = "testemai9@hotmail.com"; pub

我无法将测试结果从selenium发送到。我似乎无法用提供的文件来解决这个问题。我目前正在使用:

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实现这一点的确切方法吗?我不确定我做得是否正确。

我正在为testrail使用我自己定制的API,但它都基于相同的东西

但看看官方的摇滚乐,

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

APIClient client = new APIClient("http://<server>/testrail/");
client.setUser("..");
client.setPassword("..");
我发现的第二件事是,您在testcase 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,如下图所示:


而且,测试用例ID与测试运行ID不同。

我查看了文档,您的代码似乎没有问题。错误可能就是它的实际样子,您确定可以使用URL中给定的凭据登录吗?(我无法访问该URL,它是私人服务器还是什么的?)哦,不,对不起,我刚刚更改了我的URL,以便将其放在网站上,我不希望我的登录可用。我会错过任何我想知道的东西吗。或者他的url格式不正确。我不确定URL格式对我来说也不坏。你能试试另一种格式吗?”http:///testrail/"? 是的,你不必共享你的凭据,但你可以手动登录,对吗?可能是重复的我可以从那里手动登录
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 );
}