import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.testng.IAlterSuiteListener;
import org.testng.Reporter;
import org.testng.annotations.Test;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;
public class ExampleTest {
@Test
public void test() {
System.err.println("test() ==> " + Reporter.getCurrentTestResult().getTestContext().getName());
}
public static class ExampleSuiteAlterer implements IAlterSuiteListener {
@Override
public void alter(List<XmlSuite> suites) {
String tests = System.getProperty("tests", "t1"); //only <t1> should be executed
if (!tests.trim().isEmpty()) {
List<String> testNamesToInclude = Arrays.asList(tests.split(","));
List<XmlTest> filtered = suites.get(0).getTests().stream()
.filter(xmlTest -> testNamesToInclude.contains(xmlTest.getName()))
.collect(Collectors.toList());
suites.get(0).getTests().clear();
suites.get(0).getTests().addAll(filtered);
}
}
}
}
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Implementing Parametrization">
<listeners>
<listener class-name="com.rationaleemotions.ExampleTest$ExampleSuiteAlterer"/>
</listeners>
<test name="t1">
<classes>
<class name="com.rationaleemotions.ExampleTest"/>
</classes>
</test>
<test name="t2">
<classes>
<class name="com.rationaleemotions.ExampleTest"/>
</classes>
</test>
</suite>
test() ==> t1
===============================================
Implementing Parametrization
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================
Process finished with exit code 0
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CACvSpted9YBNRg3cNkybmwjSqyfLfvXUCMpCZeX_RWnTNaZC5w%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CANikZLnNAVOcskr9-8tyEU44VfFbqL0SSOu2S9PH0xr2mYHVpg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/f0010ec6-b3ae-41f4-88f4-2f901bcdf09b%40gmail.com.
Anil,
Please clean up your project and upload something into github that can be used to reproduce the problem. You seem to have just uploaded your current project into google drive.
The project you shared right now doesn’t have any suite xml file, nor a listener and I am not sure what test to be executing.
The sample project needs to have only the following:
PS:
Please help put it on github instead of google drive
Thanks & Regards
Krishnan Mahadevan
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.com/
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CACvSptdkxkeMfww5sXBx_86QdKcmrE9%3DcfU_T%2BHySF6%2B3arpZA%40mail.gmail.com.