13
Sep

Beanshell to process specific tests via testng.xml

Running specific tests via TestNG.xml
===========================================

Suppose you have specified different test as part of testng.xml setup as follow:

<suite>

<test name=1>
<groups>
</groups>
<classes>
</classes>
</test>

<test name=2>
<groups>
</groups>
<classes>
</classes>
</test>

<test name=3>
<groups>
</groups>
<classes>
</classes>
</test>

<test name=4>
<groups>
</groups>
<classes>
</classes>
</test>

</suite>

If you need to degine testng.xml to dynamically run specific test, we can use following code snippet

<method-selectors>
<method-selector>
<script language=”beanshell”>
<![CDATA[
testName = testngMethod.getXmlTest().getName();
print (“testname = ” + testName);
return testName.equals(System.getProperty(“whichTestToRun”));
]]>
</script>
</method-selector>
</method-selectors>