use of com.lazerycode.ebselen.handlers.XMLHandler in project Ebselen by Ardesco.
the class XMLHandlerTest method performXPathQueryWithNormalXML.
@Test
public void performXPathQueryWithNormalXML() throws Exception {
URI normalXMLFile = this.getClass().getResource("/xml/normal.xml").toURI();
XMLHandler normal = new XMLHandler(new File(normalXMLFile));
assertThat(normal.performXPathQueryReturnInteger("count(//fruit)"), is(equalTo(2)));
}
use of com.lazerycode.ebselen.handlers.XMLHandler in project Ebselen by Ardesco.
the class XMLHandlerTest method addAttributeToElement.
@Test
public void addAttributeToElement() throws Exception {
XMLHandler textBased = new XMLHandler("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><bar/></root>");
textBased.addAttribute("element", "foo", "/root/bar");
assertThat(textBased.returnXML(), is(equalTo("<?xml version=\"1.0\" encoding=\"UTF-8\"?><root><bar element=\"foo\"/></root>")));
}
use of com.lazerycode.ebselen.handlers.XMLHandler in project Ebselen by Ardesco.
the class TestReports method createHTMLReport.
/**
* Create an HTML format report of the test run
*
* @throws Exception
*/
private void createHTMLReport() throws Exception {
String overallResult = "Pass";
XMLHandler testResults = new XMLHandler(new File(this.htmlTestTemplate));
// Populate the "test name" field
testResults.addTextToElement(this.testSuiteName, "//p[@id='name']/span");
// Populate the "Author(s)" field
testResults.addTextToElement(this.testSuiteAuthor, "//p[@id='author']/span");
// Populate "stories covered" field
String stories = "";
for (String story : this.associatedStories) {
stories = stories.concat(story).concat(", ");
}
stories = stories.trim().substring(0, stories.length() - 2);
testResults.addTextToElement(stories, "//p[@id='story']/span");
// Populate "total suite time" field
testResults.addTextToElement(formattedTime(this.suiteRunTime), "//p[@id='time']/span");
// Build the test results table
Iterator test = this.testData.entrySet().iterator();
int rowNumber = 0;
while (test.hasNext()) {
Map.Entry pairs = (Map.Entry) test.next();
testResults.addChildElement("tr", "//table[@id='testResults']/tbody");
rowNumber++;
TestData individualTestResults = (TestData) pairs.getValue();
testResults.addChildElement("td", "//table[@id='testResults']/tbody/tr[" + rowNumber + "]");
testResults.addTextToElement(individualTestResults.getTestName(), "//table[@id='testResults']/tbody/tr[" + rowNumber + "]/td[1]");
testResults.addChildElement("td", "//table[@id='testResults']/tbody/tr[" + rowNumber + "]");
testResults.addTextToElement(Integer.valueOf(individualTestResults.getFailures()).toString(), "//table[@id='testResults']/tbody/tr[" + rowNumber + "]/td[2]");
String result = "";
if (individualTestResults.getFailures() == 0) {
result = "Pass";
} else {
result = "Fail";
overallResult = "Fail";
}
testResults.addAttribute("class", result.toLowerCase(), "//table[@id='testResults']/tbody/tr[" + rowNumber + "]");
testResults.addChildElement("td", "//table[@id='testResults']/tbody/tr[" + rowNumber + "]");
testResults.addTextToElement(result, "//table[@id='testResults']/tbody/tr[" + rowNumber + "]/td[3]");
testResults.addChildElement("td", "//table[@id='testResults']/tbody/tr[" + rowNumber + "]");
testResults.addTextToElement(formattedTime(individualTestResults.getTimeTaken()), "//table[@id='testResults']/tbody/tr[" + rowNumber + "]/td[4]");
}
// Populate the "overall result" field
testResults.addTextToElement(overallResult, "//h2[@id='overallResult']/span");
testResults.addAttribute("class", overallResult.toLowerCase(), "//h2[@id='overallResult']/span");
// Print HTML results page location
logger.info("Test report available at {}", testResults.writeXMLFile(this.outputDirectory + this.testSuiteName.concat(".html")));
FileHandler cssStyle = new FileHandler(new File(this.htmlCSSFile));
cssStyle.copyFileTo(this.outputDirectory + cssStyle.getFileName());
}
Aggregations