Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.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自动化Jenkins页面_Java_Selenium_Xpath_Jenkins_Jenkins Api - Fatal编程技术网

Java 使用selenium自动化Jenkins页面

Java 使用selenium自动化Jenkins页面,java,selenium,xpath,jenkins,jenkins-api,Java,Selenium,Xpath,Jenkins,Jenkins Api,我想构建一个自动化系统来发现我的测试脚本中的缺陷,对于这些缺陷,我需要获得给定作业的通过百分比,比如n个构建。通过xpath查找数据不起作用。是否有任何API可以获取相同的信息,或者有任何特定的方法来处理xpath 附:框架使用了-Java和Selenium,因为您提供的信息有点模糊,请在下面找到两个工作片段 获取整个文档 URI uri = new URI("http://host:port/job/JOB_NAME/api/xml"); HttpURLConnection con = (Ht

我想构建一个自动化系统来发现我的测试脚本中的缺陷,对于这些缺陷,我需要获得给定作业的通过百分比,比如n个构建。通过
xpath
查找数据不起作用。是否有任何API可以获取相同的信息,或者有任何特定的方法来处理
xpath


附:框架使用了-
Java和Selenium

,因为您提供的信息有点模糊,请在下面找到两个工作片段

获取整个文档

URI uri = new URI("http://host:port/job/JOB_NAME/api/xml");
HttpURLConnection con = (HttpURLConnection) uri.toURL().openConnection();

DocumentBuilder builder = DocumentBuilderFactory.newInstance()
    .newDocumentBuilder();
Document document = builder.parse(con.getInputStream());

XPath xPath = XPathFactory.newInstance().newXPath();
NodeList nodeList = (NodeList) xPath.compile("//lastSuccessfulBuild/url")
    .evaluate(document, XPathConstants.NODESET);
for (int i = 0; i < nodeList.getLength(); i++) {
    System.out.println("last successful: " + nodeList.item(i).getTextContent());
}
con.disconnect();

仅将这些代码片段视为PoC,以证明Jenkins XML API上的XPath总体上是有效的

当您谈到
xpath
时,我假设您已经看过
Jenkins restapi
?到目前为止你试过什么?xpath的问题是什么?driver.findelelement(By.xpath(xpathExpression))不适用于Jenkins HTML报告页的任何xpath。我使用了以下-->URL=newURL(“jobName+”/“+build+”/api/xml”);这不是故意的。我需要一些东西来帮助我找到@KshipraDwivedi指定的生成的通过百分比。我不确定您在寻找什么。如果您正在寻找最新生成的测试结果。XML API的URL是
http://host:port/job/JOB_NAME//lastCompletedBuild/testReport/api/xml
。修改URL和相应的片段中的xpath。
URI uri = new URI("http://host:port/job/JOB_NAME/api/xml"
    + "?xpath=//lastSuccessfulBuild/url");

HttpURLConnection con = (HttpURLConnection) uri.toURL().openConnection();

DocumentBuilder builder = DocumentBuilderFactory.newInstance()
    .newDocumentBuilder();
Document document = builder.parse(con.getInputStream());

XPath xPath = XPathFactory.newInstance().newXPath();
NodeList nodeList = (NodeList) xPath.compile("/url")
    .evaluate(document, XPathConstants.NODESET);
for (int i = 0; i < nodeList.getLength(); i++) {
    System.out.println("last successful: " + nodeList.item(i).getTextContent());
}
con.disconnect();
last successful: http://host:port/job/JOB_NAME/1234/