Running tests based on test name in testng.xml

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Running tests based on test name in testng.xml

praveen133t
Is there a way to run tests based on test name in the testng.xml

Example : Let's say I have two <test> tags in my xml as below

<suite name="Suite">
<test name="regression">
<classes>
<class name="com.regression.test1" />
</classes>
</test>
<test name="sanity">
<classes>
<class name="com.sanity.test2" />
</classes>
</test>
</suite>

Now I want to run only test case classes inside "sanity" test name tag. Is that possible?

I know we can define groups but I'd like to know if we can without having the group setup.



--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Running tests based on test name in testng.xml

⇜Krishnan Mahadevan⇝

There is something called beanshell in Testng which can be used as a method selector.

Sometime back I wrote a blog post on this : http://rationaleemotions.wordpress.com/2013/08/21/beanshell-and-testng/

Please check if you can use it to query the XmlTest name from a given method and then used to execute it.

The other option I can think of is kind of like a work around.

1. Define an IInvokedMethodListener.
2. Within the beforeInvocation () method check if the method's XmlTest matches the value that you pass via the JVM argument ( which represents the test name you want to execute ) . If it doesn't match then you would throw a TestSkipException which would prevent the current test from being executed.

The drawback here is that your test reports will look a bit skewed.

On Aug 29, 2014 4:12 AM, "TestNG-Tester" <[hidden email]> wrote:
Is there a way to run tests based on test name in the testng.xml

Example : Let's say I have two <test> tags in my xml as below

<suite name="Suite">
<test name="regression">
<classes>
<class name="com.regression.test1" />
</classes>
</test>
<test name="sanity">
<classes>
<class name="com.sanity.test2" />
</classes>
</test>
</suite>

Now I want to run only test case classes inside "sanity" test name tag. Is that possible?

I know we can define groups but I'd like to know if we can without having the group setup.



--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Running tests based on test name in testng.xml

praveen133t
Thanks for your response Krishnan. Do you know which method I should be invoking in order to get the handle of test name tag in the xml?

http://testng.org/javadoc/org/testng/xml/XmlTest.html



On Friday, August 29, 2014 1:27:53 AM UTC-4, Krishnan wrote:

There is something called beanshell in Testng which can be used as a method selector.

Sometime back I wrote a blog post on this : <a href="http://rationaleemotions.wordpress.com/2013/08/21/beanshell-and-testng/" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Frationaleemotions.wordpress.com%2F2013%2F08%2F21%2Fbeanshell-and-testng%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNGMa8TvTo6l_ACY0RM-rSd1006dMw';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Frationaleemotions.wordpress.com%2F2013%2F08%2F21%2Fbeanshell-and-testng%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNGMa8TvTo6l_ACY0RM-rSd1006dMw';return true;">http://rationaleemotions.wordpress.com/2013/08/21/beanshell-and-testng/

Please check if you can use it to query the XmlTest name from a given method and then used to execute it.

The other option I can think of is kind of like a work around.

1. Define an IInvokedMethodListener.
2. Within the beforeInvocation () method check if the method's XmlTest matches the value that you pass via the JVM argument ( which represents the test name you want to execute ) . If it doesn't match then you would throw a TestSkipException which would prevent the current test from being executed.

The drawback here is that your test reports will look a bit skewed.

On Aug 29, 2014 4:12 AM, "TestNG-Tester" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="OFw47Pr-uiQJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">neevar...@...> wrote:
Is there a way to run tests based on test name in the testng.xml

Example : Let's say I have two <test> tags in my xml as below

<suite name="Suite">
<test name="regression">
<classes>
<class name="com.regression.test1" />
</classes>
</test>
<test name="sanity">
<classes>
<class name="com.sanity.test2" />
</classes>
</test>
</suite>

Now I want to run only test case classes inside "sanity" test name tag. Is that possible?

I know we can define groups but I'd like to know if we can without having the group setup.



--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="OFw47Pr-uiQJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="OFw47Pr-uiQJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">testng...@....
Visit this group at <a href="http://groups.google.com/group/testng-users" target="_blank" onmousedown="this.href='http://groups.google.com/group/testng-users';return true;" onclick="this.href='http://groups.google.com/group/testng-users';return true;">http://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Running tests based on test name in testng.xml

praveen133t
In reply to this post by praveen133t
I was able to achieve my requirement using

 <![CDATA[method.getDeclaringClass().getPackage().getName().contains("xyz")]]>

Thanks a lot Krishnan for your tip.

Now how do I pass this value from Maven surefire?

On Thursday, August 28, 2014 6:42:39 PM UTC-4, TestNG-Tester wrote:
Is there a way to run tests based on test name in the testng.xml

Example : Let's say I have two <test> tags in my xml as below

<suite name="Suite">
<test name="regression">
<classes>
<class name="com.regression.test1" />
</classes>
</test>
<test name="sanity">
<classes>
<class name="com.sanity.test2" />
</classes>
</test>
</suite>

Now I want to run only test case classes inside "sanity" test name tag. Is that possible?

I know we can define groups but I'd like to know if we can without having the group setup.



--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Running tests based on test name in testng.xml

praveen133t
I was able to achieve my maven thing as well... I just did

<argLine>-Darg=xyz</argLine>

On Friday, August 29, 2014 7:56:10 AM UTC-4, TestNG-Tester wrote:
I was able to achieve my requirement using

 <![CDATA[method.getDeclaringClass().getPackage().getName().contains("xyz")]]>

Thanks a lot Krishnan for your tip.

Now how do I pass this value from Maven surefire?

On Thursday, August 28, 2014 6:42:39 PM UTC-4, TestNG-Tester wrote:
Is there a way to run tests based on test name in the testng.xml

Example : Let's say I have two <test> tags in my xml as below

<suite name="Suite">
<test name="regression">
<classes>
<class name="com.regression.test1" />
</classes>
</test>
<test name="sanity">
<classes>
<class name="com.sanity.test2" />
</classes>
</test>
</suite>

Now I want to run only test case classes inside "sanity" test name tag. Is that possible?

I know we can define groups but I'd like to know if we can without having the group setup.



--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Running tests based on test name in testng.xml

⇜Krishnan Mahadevan⇝
In reply to this post by praveen133t

Try http://testng.org/javadoc/org/testng/xml/XmlTest.html#getName() and see if that helps.

On Aug 29, 2014 5:07 PM, "TestNG-Tester" <[hidden email]> wrote:
Thanks for your response Krishnan. Do you know which method I should be invoking in order to get the handle of test name tag in the xml?




On Friday, August 29, 2014 1:27:53 AM UTC-4, Krishnan wrote:

There is something called beanshell in Testng which can be used as a method selector.

Sometime back I wrote a blog post on this : http://rationaleemotions.wordpress.com/2013/08/21/beanshell-and-testng/

Please check if you can use it to query the XmlTest name from a given method and then used to execute it.

The other option I can think of is kind of like a work around.

1. Define an IInvokedMethodListener.
2. Within the beforeInvocation () method check if the method's XmlTest matches the value that you pass via the JVM argument ( which represents the test name you want to execute ) . If it doesn't match then you would throw a TestSkipException which would prevent the current test from being executed.

The drawback here is that your test reports will look a bit skewed.

On Aug 29, 2014 4:12 AM, "TestNG-Tester" <[hidden email]> wrote:
Is there a way to run tests based on test name in the testng.xml

Example : Let's say I have two <test> tags in my xml as below

<suite name="Suite">
<test name="regression">
<classes>
<class name="com.regression.test1" />
</classes>
</test>
<test name="sanity">
<classes>
<class name="com.sanity.test2" />
</classes>
</test>
</suite>

Now I want to run only test case classes inside "sanity" test name tag. Is that possible?

I know we can define groups but I'd like to know if we can without having the group setup.



--
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 [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Running tests based on test name in testng.xml

praveen133t
I'll try that.

Do you happen to know if @BeforeSuite in a base class runs if I use method selector in the testng.xml?

I tried and my @beforesuite is not running.. Don't know why

On Friday, August 29, 2014 11:55:07 AM UTC-4, Krishnan wrote:

Try <a href="http://testng.org/javadoc/org/testng/xml/XmlTest.html#getName()" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Fjavadoc%2Forg%2Ftestng%2Fxml%2FXmlTest.html%23getName()\46sa\75D\46sntz\0751\46usg\75AFQjCNHunbZZ6SL86WRrFuMf7HQDTkm23A';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Fjavadoc%2Forg%2Ftestng%2Fxml%2FXmlTest.html%23getName()\46sa\75D\46sntz\0751\46usg\75AFQjCNHunbZZ6SL86WRrFuMf7HQDTkm23A';return true;">http://testng.org/javadoc/org/testng/xml/XmlTest.html#getName() and see if that helps.

On Aug 29, 2014 5:07 PM, "TestNG-Tester" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="cbT3hleQChQJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">neevar...@...> wrote:
Thanks for your response Krishnan. Do you know which method I should be invoking in order to get the handle of test name tag in the xml?

<a href="http://testng.org/javadoc/org/testng/xml/XmlTest.html" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Fjavadoc%2Forg%2Ftestng%2Fxml%2FXmlTest.html\46sa\75D\46sntz\0751\46usg\75AFQjCNG7eGrkoDF4z8PGLYUQLHFSnFEypA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Ftestng.org%2Fjavadoc%2Forg%2Ftestng%2Fxml%2FXmlTest.html\46sa\75D\46sntz\0751\46usg\75AFQjCNG7eGrkoDF4z8PGLYUQLHFSnFEypA';return true;">http://testng.org/javadoc/org/testng/xml/XmlTest.html



On Friday, August 29, 2014 1:27:53 AM UTC-4, Krishnan wrote:

There is something called beanshell in Testng which can be used as a method selector.

Sometime back I wrote a blog post on this : <a href="http://rationaleemotions.wordpress.com/2013/08/21/beanshell-and-testng/" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Frationaleemotions.wordpress.com%2F2013%2F08%2F21%2Fbeanshell-and-testng%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNGMa8TvTo6l_ACY0RM-rSd1006dMw';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Frationaleemotions.wordpress.com%2F2013%2F08%2F21%2Fbeanshell-and-testng%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNGMa8TvTo6l_ACY0RM-rSd1006dMw';return true;">http://rationaleemotions.wordpress.com/2013/08/21/beanshell-and-testng/

Please check if you can use it to query the XmlTest name from a given method and then used to execute it.

The other option I can think of is kind of like a work around.

1. Define an IInvokedMethodListener.
2. Within the beforeInvocation () method check if the method's XmlTest matches the value that you pass via the JVM argument ( which represents the test name you want to execute ) . If it doesn't match then you would throw a TestSkipException which would prevent the current test from being executed.

The drawback here is that your test reports will look a bit skewed.

On Aug 29, 2014 4:12 AM, "TestNG-Tester" <[hidden email]> wrote:
Is there a way to run tests based on test name in the testng.xml

Example : Let's say I have two <test> tags in my xml as below

<suite name="Suite">
<test name="regression">
<classes>
<class name="com.regression.test1" />
</classes>
</test>
<test name="sanity">
<classes>
<class name="com.sanity.test2" />
</classes>
</test>
</suite>

Now I want to run only test case classes inside "sanity" test name tag. Is that possible?

I know we can define groups but I'd like to know if we can without having the group setup.



--
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 [hidden email].
Visit this group at <a href="http://groups.google.com/group/testng-users" target="_blank" onmousedown="this.href='http://groups.google.com/group/testng-users';return true;" onclick="this.href='http://groups.google.com/group/testng-users';return true;">http://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="cbT3hleQChQJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="cbT3hleQChQJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">testng...@....
Visit this group at <a href="http://groups.google.com/group/testng-users" target="_blank" onmousedown="this.href='http://groups.google.com/group/testng-users';return true;" onclick="this.href='http://groups.google.com/group/testng-users';return true;">http://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.