Java 使用selenium自动化Jenkins页面
我想构建一个自动化系统来发现我的测试脚本中的缺陷,对于这些缺陷,我需要获得给定作业的通过百分比,比如n个构建。通过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
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/