Skip to content

Instantly share code, notes, and snippets.

@krmahadevan
Created October 27, 2016 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krmahadevan/6349e75fbf27ff9b43aa674df801895b to your computer and use it in GitHub Desktop.
Save krmahadevan/6349e75fbf27ff9b43aa674df801895b to your computer and use it in GitHub Desktop.
How to execute selective methods from a group using Beanshell in TestNG
package org.rationale.emotions;
import org.testng.annotations.Test;
public class GroupTest {
@Test(groups = "dragon-lord")
public void foo() {
System.err.println("foo() says hello");
}
@Test(groups = "dragon-lord")
public void bar() {
System.err.println("bar() says hello");
}
@Test(groups = "dragon-lord")
public void foobar() {
System.err.println("foobar() says hello");
}
}
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="My Suite" verbose="1" parallel="false" thread-count="1">
<test name="groups-demo">
<method-selectors>
<method-selector>
<script language="beanshell">
<![CDATA[
whatGroup = System.getProperty("whatgroup","dragon-lord");
whatMethod = System.getProperty("methodToRun", "foo");
if (whatGroup.isEmpty() || whatMethod.isEmpty()) {
return true;
}
return groups.containsKey(whatGroup) && method.getName().equals(whatMethod);
]]>
</script>
</method-selector>
</method-selectors>
<classes>
<class name="org.rationale.emotions.GroupTest"/>
</classes>
</test>
</suite>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment