Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/main/java/hudson/plugins/robot/RobotParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public static final class RobotParserCallable implements
private final String logFileName;
private final String reportFileName;

private int schemaVersion;
private String startLocalName = "starttime";
private String elapsedLocalName = "elapsedtime";
private String endLocalName = "endtime";

public RobotParserCallable(String outputFileLocations, String logFileName, String reportFileName) {
this.outputFileLocations = outputFileLocations;
this.logFileName = logFileName;
Expand Down Expand Up @@ -116,6 +121,16 @@ private RobotResult parseResult(RobotResult result, XMLStreamReader reader, File
//we already have all data from suites and tests so we can stop parsing
break;
else if("robot".equals(tagName)){
String value = reader.getAttributeValue(null, "schemaversion");
value = value == null ? "0" : value;
schemaVersion = Integer.parseInt(value);
// RF schemaVersion does not follow major version number.
// schemaVersion 5 == RF7.0
if (schemaVersion >= 5) {
Comment thread
asimell marked this conversation as resolved.
startLocalName = "start";
elapsedLocalName = "elapsed";
// endLocalName is no longer used
}
result.setTimeStamp(reader.getAttributeValue(null, "generated"));
} else if("suite".equals(tagName)){
result.addSuite(processSuite(reader, result, baseDirectory));
Expand All @@ -131,6 +146,7 @@ private RobotSuiteResult processSuite(XMLStreamReader reader, RobotTestObject pa
return getSplitXMLSuite(parent, baseDirectory, splitXMLPath);
}
RobotSuiteResult suite = new RobotSuiteResult();
suite.setSchemaVersion(schemaVersion);
suite.setLogFile(this.logFileName);
suite.setReportFile(this.reportFileName);
suite.setParent(parent);
Expand All @@ -157,9 +173,9 @@ private RobotSuiteResult processSuite(XMLStreamReader reader, RobotTestObject pa
suite.failTeardown();
}
} else if("status".equals(tagName)){
suite.setElapsedTime(reader.getAttributeValue(null, "elapsedtime"));
suite.setStartTime(reader.getAttributeValue(null, "starttime"));
suite.setEndTime(reader.getAttributeValue(null, "endtime"));
suite.setElapsedTime(reader.getAttributeValue(null, elapsedLocalName));
suite.setStartTime(reader.getAttributeValue(null, startLocalName));
suite.setEndTime(reader.getAttributeValue(null, endLocalName));
}
} else if (reader.isEndElement() && "suite".equals(reader.getLocalName())) {
return suite;
Expand Down Expand Up @@ -324,8 +340,12 @@ private RobotCaseResult processTest(XMLStreamReader reader, RobotSuiteResult res
//parse test details from nested status
caseResult.setPassed("PASS".equals(reader.getAttributeValue(null, "status")));
caseResult.setSkipped("SKIP".equals(reader.getAttributeValue(null, "status")));
caseResult.setStarttime(reader.getAttributeValue(null, "starttime"));
caseResult.setEndtime(reader.getAttributeValue(null, "endtime"));

caseResult.setStarttime(reader.getAttributeValue(null, startLocalName));
caseResult.setEndtime(reader.getAttributeValue(null, endLocalName));
if (schemaVersion >= 5) {
caseResult.setElapsedTime(reader.getAttributeValue(null, elapsedLocalName));
}
setCriticalityIfAvailable(reader, caseResult);
while(reader.hasNext()){
reader.next();
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/hudson/plugins/robot/model/RobotCaseResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class RobotCaseResult extends RobotTestObject{
private String description;
private String starttime;
private String endtime;
private double elapsedtime;
private List<String> tags;
private String stackTrace;

Expand All @@ -61,9 +62,10 @@ public class RobotCaseResult extends RobotTestObject{
* @return Elapsed time from start to end
* @throws ParseException thrown exception
*/
public static long timeDifference(String time1, String time2) throws ParseException{
public static long timeDifference(String time1, String time2) throws ParseException {
long difference = 0;
DateFormat format = new SimpleDateFormat("yyyyMMdd HH:mm:ss.SS");
String dateFormat = "yyyyMMdd HH:mm:ss.SS";
DateFormat format = new SimpleDateFormat(dateFormat);

Date startDate = format.parse(time1);
Date endDate = format.parse(time2);
Expand All @@ -83,7 +85,7 @@ public String getName() {
public void setName(String name) {
this.name = name;
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -112,7 +114,8 @@ public void setParent(RobotSuiteResult parent){
public long getDuration() {
if (duration != 0)
return duration;

if (elapsedtime != 0)
return Double.valueOf(elapsedtime * 1000).longValue(); // convert seconds to milliseconds
try{
return timeDifference(this.starttime, this.endtime);
} catch (ParseException e){
Expand All @@ -137,14 +140,22 @@ public void setEndtime(String endtime) {
this.endtime = endtime;
}

public double getElapsedtime() {
return elapsedtime;
}

public void setElapsedTime(String elapsed) {
this.elapsedtime = Double.parseDouble(elapsed);
}

public String getErrorMsg() {
return errorMsg;
}

public void setErrorMsg(String errorMsg) {
this.errorMsg = errorMsg;
}

public String getStackTrace() {
return stackTrace;
}
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/hudson/plugins/robot/model/RobotSuiteResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class RobotSuiteResult extends RobotTestObject {
private transient int criticalPassed;
private transient int criticalFailed;

private int schemaVersion;


/**
* Adds a nested suite to this suite. If a suite exists with the same name
Expand Down Expand Up @@ -122,7 +124,7 @@ public void setDescription(String description){
public Collection<RobotCaseResult> getCaseResults() {
if(caseResults != null) {
List<RobotCaseResult> res = new ArrayList(caseResults.values());
Collections.sort(res, new RobotCaseComparator());
res.sort(new RobotCaseComparator());
return res;
}
return Collections.emptyList();
Expand Down Expand Up @@ -180,6 +182,10 @@ public int getCriticalTotal() {
return criticalPassed + criticalFailed;
}

public void setSchemaVersion(int version) {
this.schemaVersion = version;
}

/**
* Adds a test case result to this suite. If a case exists with the same
* name it will be overwritten with this one.
Expand All @@ -202,7 +208,7 @@ public void addCaseResult(RobotCaseResult caseResult) {
public void setElapsedTime(String elapsedTime) {
this.elapsedTime = elapsedTime;
}

public void setStartTime(String startTime){
this.startTime = startTime;
}
Expand All @@ -213,6 +219,10 @@ public void setEndTime(String endTime){

@Override
public long getDuration() {
if (schemaVersion >= 5) {
double d = Double.parseDouble(this.elapsedTime) * 1000;
return Double.valueOf(d).longValue();
}
if (StringUtils.isNotEmpty(this.elapsedTime)) {
return Long.parseLong(this.elapsedTime);
} else if (StringUtils.isEmpty(this.startTime) || StringUtils.isEmpty(this.endTime)) {
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/hudson/plugins/robot/RobotParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,11 @@ public void testEmptyArgTags() {
final String mask = "empty_args-output.xml";
parse(dir, mask);
}

@Test
public void testRF7InlineVar() {
final String dir = "robot7";
final String mask = "inline_var_output.xml";
parse(dir, mask);
}
}
33 changes: 23 additions & 10 deletions src/test/java/hudson/plugins/robot/model/RobotResultTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,16 @@

import hudson.plugins.robot.RobotParser;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import hudson.plugins.robot.RobotParserTest;
import org.apache.commons.lang.StringUtils;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.*;


public class RobotResultTest {

Expand Down Expand Up @@ -75,7 +70,7 @@ public void testShouldParseCases(){
RobotCaseResult caseResult = suite.getCase("Hello");
assertNotNull(caseResult);
}

@Test
public void testShouldParseCaseDescription(){
RobotSuiteResult suite = result.getSuite("Othercases & Testcases");
Expand Down Expand Up @@ -111,7 +106,7 @@ public void testShouldParseFailMessages(){
String errorMsg = caseResult.getErrorMsg();
assertEquals("Test failed miserably!", errorMsg.trim());
}

@Test
public void testShouldParseNewCriticalCases() throws Exception{

Expand Down Expand Up @@ -346,6 +341,24 @@ public void testSuiteNameAttributeMightBeMissingInRobot4() throws Exception {
// passing null as `thisObject` should not matter, as the name resolving fails first
// due to getName() returning `null`
caseResult.getRelativePackageName(null);
}

@Test
public void testCaseResultsShouldBeCorrectlySet() throws Exception {
File directory = new File(RobotParserTest.class.getResource("robot7").toURI());
RobotParser.RobotParserCallable remoteOperation = new RobotParser.RobotParserCallable("inline_var_output.xml", null, null);
result = remoteOperation.invoke(directory, null);
result.tally(null);

RobotSuiteResult suite = result.getSuite("Rf7");
RobotCaseResult caseResult = suite.getCase("Test Inline Var");

// suite results
assertEquals(35.0, suite.getDuration(), 0.01);

// case results
assertEquals("2023-11-13T15:33:07.168330", caseResult.getStarttime());
assertEquals(0.001748, caseResult.getElapsedtime(), 0.01);
assertNull(caseResult.getEndtime());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<robot generator="Robot 7.0a1 (Python 3.8.5 on darwin)" generated="2023-11-13T15:33:07.131714" rpa="false" schemaversion="5">
<suite id="s1" name="Rf7" source="/Users/aleksisimell/projects/tmp/rf7.robot">
<test id="s1-t1" name="Test Inline Var" line="2">
<variable name="${local}">
<var>mikki hiiri</var>
<status status="PASS" start="2023-11-13T15:33:07.168900" elapsed="0.000162"/>
</variable>
<kw name="Should Be Equal" owner="BuiltIn">
<arg>${local}</arg>
<arg>mikki hiiri</arg>
<doc>Fails if the given objects are unequal.</doc>
<status status="PASS" start="2023-11-13T15:33:07.169409" elapsed="0.000416"/>
</kw>
<status status="PASS" start="2023-11-13T15:33:07.168330" elapsed="0.001748"/>
</test>
<status status="PASS" start="2023-11-13T15:33:07.134805" elapsed="0.035963"/>
</suite>
<statistics>
<total>
<stat pass="1" fail="0" skip="0">All Tests</stat>
</total>
<tag>
</tag>
<suite>
<stat pass="1" fail="0" skip="0" id="s1" name="Rf7">Rf7</stat>
</suite>
</statistics>
<errors>
</errors>
</robot>