Skip to content

Instantly share code, notes, and snippets.

@krmahadevan
Last active July 2, 2016 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save krmahadevan/4befa0686bf3f1a05374edcb32dfc4ee to your computer and use it in GitHub Desktop.
Save krmahadevan/4befa0686bf3f1a05374edcb32dfc4ee to your computer and use it in GitHub Desktop.
A Sample Suite Listener which can retrieve the names of all methods that are part of a group.
public static class GroupPrinter implements ISuiteListener {
@Override
public void onStart(ISuite suite) {
String groupName = System.getProperty("groupName", "all");
List<ITestNGMethod> allMethods = suite.getAllMethods();
List<ITestNGMethod> filteredMethods = new ArrayList<>();
for (ITestNGMethod method : allMethods) {
if (Arrays.asList(method.getGroups()).contains(groupName)) {
filteredMethods.add(method);
}
if (Arrays.asList(method.getBeforeGroups()).contains(groupName)) {
filteredMethods.add(method);
}
if (Arrays.asList(method.getAfterGroups()).contains(groupName)) {
filteredMethods.add(method);
}
}
System.err.println("**** Filtered Groups " + filteredMethods);
}
@Override
public void onFinish(ISuite suite) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment