Run all tests if no value passed for -testnames parameter

129 views
Skip to first unread message

Srikanth Rao Melagiri

unread,
Aug 16, 2018, 2:52:54 AM8/16/18
to testng-users
Hi,

I am trying to trigger targeted execution of regression tests from my Maven-Selenium-TestNG automation framework. 

I've created a property for 'testnames' and set the value to pick from systemProperty during maven invocation with -D option. 
The execution happens properly if i mention the test name, but i also want to perform the execution for all tests in testng.xml if no value is passed for -testnames parameter. 

Is there is way to do it? Or, is it not possible unless i send all the testnames in arguments during invocation.


TestNG.xml

<test name="T1" preserve-order="true">

<classes>

<class name="com.mypackage.tests.Test1Class">

<methods>

<include name="TC_004"/>

<include name="TC_005"/>

</methods>

</class>

</classes>

</test>

<test name="T2" preserve-order="true">

<classes>

<class name="com.mypackage.tests.Test2Class">

<methods>

<include name="TC_001"/>

<include name="TC_002"/>

</methods>

</class>

</classes>

</test>


Maven POM.xml


<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-surefire-plugin</artifactId>

<version>2.20</version>

        <configuration>    

          <!-- System Property Variables to consume from Maven invocation -->

  <systemPropertyVariables>

<browser>${browser}</browser>

                <browserVersion>${browserVersion}</browserVersion>

  </systemPropertyVariables>

  <!-- TestNG xml Configuration -->

  <suiteXmlFiles>

<suiteXmlFile>${suiteFile}</suiteXmlFile>

  </suiteXmlFiles>

  <!-- Project level Properties configuration -->

  <properties>

  <property> <!-- Block Default TestNG Listeners -->

   <name>usedefaultlisteners</name>

   <value>false</value>

</property>

<property>

   <name>testnames</name>

           <value>${testCases}</value>

</property>

  </properties>

  <!-- Maven Run Configurations -->

  <skipTests>false</skipTests>

  <testFailureIgnore>true</testFailureIgnore>

</configuration>

</plugin>


Maven Profile will have the suiteXml value and the execution is invoked using: mvn test -P featureTests -DtestCases=T1,T2


What i am looking for is, if i invoke the execution using: mvn test -P featureTests the execution to happen with all tests in the testNG xml 


But here it is failing with below: The test(s) <[]> cannot be found.



Srikanth Rao

unread,
Aug 23, 2018, 6:21:27 AM8/23/18
to testng-users
HI All, 

I am trying to explore if there are other ways to achieve it but no luck. Appreciate your response on this. 

Regards,
Srikanth Rao

Krishnan Mahadevan

unread,
Aug 23, 2018, 11:47:38 PM8/23/18
to testng...@googlegroups.com

Srikanth,

 

The current implementation is such that once you provide testnames then a match is always done only against what was provided. That explains why you see that error, when you don’t provide any testnames to be executed.

 

But you still can get this done if you make use of a beanshell executor as your selector in your suite file.

 

The beanshell executor basically exposes the ITestNGMethod (the test method in the TestNG world) object to your selector. So you should be able to query its “test name” via its ITestContext object, cross check that with the testnames provided via the JVM argument and proceed further. So you could basically disable this filtering if the JVM argument was null (or) empty, which is what you mean by if no test names were provided, then run everything

 

For more information on working with beanshell, please refer to the following:

 

  1. Official TestNG documentation: http://testng.org/doc/documentation-main.html#beanshell
  2. My blog post: https://rationaleemotions.wordpress.com/2013/08/21/beanshell-and-testng/  

 

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.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Srikanth Rao

unread,
Oct 3, 2018, 4:34:41 AM10/3/18
to testng-users
Hi Krishna,

Apologies for the delay in response.

I tried using the Beanshell executor and yes, it fulfilled my requirement.

I am using something like this:

          <test name="Feature Tests">

<method-selectors>

             <method-selector>

 <script language="beanshell">

              <![CDATA[

        String test=System.getProperty("testCase");

testngMethod.getMethodName().contains(test);

]]>

  </script>

     </method-selector>

</method-selectors>

<packages>

<package name="com.xxx.yyyy.abc"/>

</packages >

</test>


Thanks,

Srikanth M

Reply all
Reply to author
Forward
0 new messages