I use testlink-plugin which uses your project as a dependency module. If we have a profile with several suites to be executed we will see that the testNG file will have several suites in it. In this case the results which will be returned will be only from the first suite element. In this case we will lose information about the rest of the suites in the testNG file. That`s why it is a good idea to change this behavior to a new one. For example:
return a list of suite elements. This way all suite elements will have correct information ( timestamp / duration and so on ).
return a single suite element which but parse the suite file from testng-results tag instead from suite level. This way all tests will be part from the suite element and their information will be correct but you will lose suite information like ( timestamp / duration and so on).
Currently, I have implemented the second way locally because as a test user I am interested in the test results. The changes which are applied are just a few.
You can see the implementation below:
public class TestNGXmlHandler extends DefaultHandler implements Serializable {
private static final String TESTNG_RESULT_TAG = "testng-results";
private static final String SUITE = "suite";
private static final String TEST_METHOD = "test-method";
private static final String CLAZZ = "class";
private static final String TEST = "test";
private static final String STATUS = "status";
private static final String SIGNATURE = "signature";
private static final String IS_CONFIG = "is-config";
private static final String NAME = "name";
private static final String STARTED_AT = "started-at";
private static final String FINISHED_AT = "finished-at";
private static final String DURATION_MS = "duration-ms";
private static final String DATA_PROVIDER = "data-provider";
private static final long serialVersionUID = -7393574325643071292L;
private Suite suite;
private Test test;
private Class clazz;
private TestMethod testMethod;
/**
* Default constructor.
*/
public TestNGXmlHandler() {
super();
}
/*
* (non-Javadoc)
*
* @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String,
* java.lang.String, java.lang.String, org.xml.sax.Attributes)
*/
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if (TESTNG_RESULT_TAG.equals(qName)){
suite = new Suite();
} else if (SUITE.equals(qName)) {
suite.setDurationMs(attributes.getValue(DURATION_MS));
suite.setFinishedAt(attributes.getValue(FINISHED_AT));
suite.setStartedAt(attributes.getValue(STARTED_AT));
suite.setName(attributes.getValue(NAME));
} else if (TEST.equals(qName)) {
test = new Test();
test.setDurationMs(attributes.getValue(DURATION_MS));
test.setFinishedAt(attributes.getValue(FINISHED_AT));
test.setStartedAt(attributes.getValue(STARTED_AT));
test.setName(attributes.getValue(NAME));
} else if (CLAZZ.equals(qName)) {
clazz = new Class();
clazz.setName(attributes.getValue(NAME));
} else if (TEST_METHOD.equals(qName)) {
testMethod = new TestMethod();
testMethod.setDurationMs(attributes.getValue(DURATION_MS));
testMethod.setFinishedAt(attributes.getValue(FINISHED_AT));
testMethod.setStartedAt(attributes.getValue(STARTED_AT));
testMethod.setName(attributes.getValue(NAME));
testMethod.setIsConfig(attributes.getValue(IS_CONFIG));
testMethod.setSignature(attributes.getValue(SIGNATURE));
testMethod.setStatus(attributes.getValue(STATUS));
testMethod.setDataProvider(attributes.getValue(DATA_PROVIDER));
}
}
/*
* (non-Javadoc)
*
* @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String,
* java.lang.String, java.lang.String)
*/
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
if (TEST.equals(qName)) {
suite.addTest(test);
} else if (CLAZZ.equals(qName)) {
test.addClass(clazz);
} else if (TEST_METHOD.equals(qName)) {
clazz.addTestMethod(testMethod);
}
}
/**
* Retrieves the parsed Suite.
* @return the parsed Suite.
*/
public Suite getSuite() {
return this.suite;
}
Hello,
I use testlink-plugin which uses your project as a dependency module. If we have a profile with several suites to be executed we will see that the testNG file will have several suites in it. In this case the results which will be returned will be only from the first suite element. In this case we will lose information about the rest of the suites in the testNG file. That`s why it is a good idea to change this behavior to a new one. For example:
Currently, I have implemented the second way locally because as a test user I am interested in the test results. The changes which are applied are just a few.
You can see the implementation below:
public class TestNGXmlHandler extends DefaultHandler implements Serializable {
}