Urgent: TestNG: Is there a way to ignore a test completely based on a Condition (if a parameter does not exist in the test)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Urgent: TestNG: Is there a way to ignore a test completely based on a Condition (if a parameter does not exist in the test)

Ramakrishna Prasad
Hi All,

Below is my TestNG suite xml file.

<suite name="Hive_961" thread-count="1">
      <parameter name="connectionFile" value="Connections/ConnHive_961"/>
      <parameter name="settingXmlPath" value="Resources/EnvironmentFiles/EnvHIVE_961.xml"/>
      <parameter name="verifyXml" value="Resources/VerifyFiles/1011/VerifyHIVE_961.xml"/>
      <parameter name="onlyVerify" value="false"/>
      <parameter name= "applicationPath" value="Applications/1011/Hive_961.iar"/>
      <parameter name= "database" value="Hive_961"/>
   
<test name="m_AggregatorTx">
                <parameter name="logFile" value="hadoopmslogs/${Domain_Name}/${NODENAME}/Hive_961/m_AggregatorTx.log"/>
                <classes>
                        <class name="executems.main.RunMS"></class>
                </classes>
        </test>

<test name="m_alldt">
                <parameter name="logFile" value="hadoopmslogs/${Domain_Name}/${NODENAME}/Hive_961/m_alldt.log"/>
                <parameter name="enableUT" value="true"/>
                <classes>
                        <class name="executems.main.RunMS"></class>
                </classes>
        </test>
<test name="m_alldt_cpx">
                <parameter name="logFile" value="hadoopmslogs/${Domain_Name}/${NODENAME}/Hive_961/m_alldt_cpx.log"/>
                <classes>
                        <class name="executems.main.RunMS"></class>
                </classes>
        </test>
<test name="m_alldt_custom_query_prop">
                <parameter name="logFile" value="hadoopmslogs/${Domain_Name}/${NODENAME}/Hive_961/m_alldt_custom_query_prop.log"/>
                <parameter name="enableUT" value="true"/>
                <classes>
                        <class name="executems.main.RunMS"></class>
                </classes>
        </test>
</suite>

In runtime, I want to ignore the tests which do not have enableUT parameter in it.
For example, in the above suite file m_AggregatorTx and m_alldt_cpx do not have enableUT parameter in them.

Note: 
1. I do not want to add enabled=true/false to my suite xml. ( Because I have 30 different suite files which have 100 test cases each)
2. Currently during runtime, I am able to Skip these tests using throw new SkipException. But once a run finishes, the results comes as this:

===============================================
Hive_961
Total tests run: 4, Failures: 0, Skips: 2
===============================================
3. I do not want the two cases to show up in the Skips section in the result. I want those cases to be ignored during run-time.
I want the result something like this:

===============================================
Hive_961
Total tests run: 2, Failures: 0, Skips: 0
===============================================

if(enableBugB.equals("true"))
{
System.out.println("enableBugB is set to true in this Test Case");
boolean result = Services.runMapping(applicationName, mappingName, database, runID);
if(runID != null && !runID.isEmpty())
{
VerifyMapping.compareResults(verifyXml, runID, logPath,result);
}
else
{
VerifyMapping.compareResults(verifyXml, mappingName, logPath,result);
}
}
else
{
//System.out.println("enableBugB is not present for this Test. Hence skipping this Test Case..");
throw new SkipException("enableBugB is not enabled. Skipping this Test Case..");
}


Appreciate any help. Thanks.

--
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 https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Urgent: TestNG: Is there a way to ignore a test completely based on a Condition (if a parameter does not exist in the test)

Krishnan Mahadevan

Maybe you could try leveraging a method interceptor to do what you are looking for.

This gist shows you how to work with a method interceptor and wire it in as a listener.

https://gist.github.com/krmahadevan/5028960

I think it's worth giving it a try.


On Sat, Apr 1, 2017, 18:27 Ramakrishna Prasad <[hidden email]> wrote:
Hi All,

Below is my TestNG suite xml file.

<suite name="Hive_961" thread-count="1">
      <parameter name="connectionFile" value="Connections/ConnHive_961"/>
      <parameter name="settingXmlPath" value="Resources/EnvironmentFiles/EnvHIVE_961.xml"/>
      <parameter name="verifyXml" value="Resources/VerifyFiles/1011/VerifyHIVE_961.xml"/>
      <parameter name="onlyVerify" value="false"/>
      <parameter name= "applicationPath" value="Applications/1011/Hive_961.iar"/>
      <parameter name= "database" value="Hive_961"/>
   
<test name="m_AggregatorTx">
                <parameter name="logFile" value="hadoopmslogs/${Domain_Name}/${NODENAME}/Hive_961/m_AggregatorTx.log"/>
                <classes>
                        <class name="executems.main.RunMS"></class>
                </classes>
        </test>

<test name="m_alldt">
                <parameter name="logFile" value="hadoopmslogs/${Domain_Name}/${NODENAME}/Hive_961/m_alldt.log"/>
                <parameter name="enableUT" value="true"/>
                <classes>
                        <class name="executems.main.RunMS"></class>
                </classes>
        </test>
<test name="m_alldt_cpx">
                <parameter name="logFile" value="hadoopmslogs/${Domain_Name}/${NODENAME}/Hive_961/m_alldt_cpx.log"/>
                <classes>
                        <class name="executems.main.RunMS"></class>
                </classes>
        </test>
<test name="m_alldt_custom_query_prop">
                <parameter name="logFile" value="hadoopmslogs/${Domain_Name}/${NODENAME}/Hive_961/m_alldt_custom_query_prop.log"/>
                <parameter name="enableUT" value="true"/>
                <classes>
                        <class name="executems.main.RunMS"></class>
                </classes>
        </test>
</suite>

In runtime, I want to ignore the tests which do not have enableUT parameter in it.
For example, in the above suite file m_AggregatorTx and m_alldt_cpx do not have enableUT parameter in them.

Note: 
1. I do not want to add enabled=true/false to my suite xml. ( Because I have 30 different suite files which have 100 test cases each)
2. Currently during runtime, I am able to Skip these tests using throw new SkipException. But once a run finishes, the results comes as this:

===============================================
Hive_961
Total tests run: 4, Failures: 0, Skips: 2
===============================================
3. I do not want the two cases to show up in the Skips section in the result. I want those cases to be ignored during run-time.
I want the result something like this:

===============================================
Hive_961
Total tests run: 2, Failures: 0, Skips: 0
===============================================

if(enableBugB.equals("true"))
{
System.out.println("enableBugB is set to true in this Test Case");
boolean result = Services.runMapping(applicationName, mappingName, database, runID);
if(runID != null && !runID.isEmpty())
{
VerifyMapping.compareResults(verifyXml, runID, logPath,result);
}
else
{
VerifyMapping.compareResults(verifyXml, mappingName, logPath,result);
}
}
else
{
//System.out.println("enableBugB is not present for this Test. Hence skipping this Test Case..");
throw new SkipException("enableBugB is not enabled. Skipping this Test Case..");
}


Appreciate any help. Thanks.

--
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 https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
--

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

Re: Urgent: TestNG: Is there a way to ignore a test completely based on a Condition (if a parameter does not exist in the test)

Ramakrishna Prasad
Thanks Krishnan. Not quite sure how this will help.
What I want to achieve is to Ignore some of the tests based on a condition. Can you give me an example code please?. I am new to TestNG. Thanks

On Saturday, April 1, 2017 at 8:04:18 PM UTC+5:30, Krishnan wrote:

Maybe you could try leveraging a method interceptor to do what you are looking for.

This gist shows you how to work with a method interceptor and wire it in as a listener.

<a href="https://gist.github.com/krmahadevan/5028960" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fkrmahadevan%2F5028960\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFA7J3RHlsJUSut_q4exYpOEoXcjw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fkrmahadevan%2F5028960\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFA7J3RHlsJUSut_q4exYpOEoXcjw&#39;;return true;">https://gist.github.com/krmahadevan/5028960

I think it's worth giving it a try.


On Sat, Apr 1, 2017, 18:27 Ramakrishna Prasad <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="GeQcpSAKBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">prasadku...@...> wrote:
Hi All,

Below is my TestNG suite xml file.

<suite name="Hive_961" thread-count="1">
      <parameter name="connectionFile" value="Connections/ConnHive_961"/>
      <parameter name="settingXmlPath" value="Resources/EnvironmentFiles/EnvHIVE_961.xml"/>
      <parameter name="verifyXml" value="Resources/VerifyFiles/1011/VerifyHIVE_961.xml"/>
      <parameter name="onlyVerify" value="false"/>
      <parameter name= "applicationPath" value="Applications/1011/Hive_961.iar"/>
      <parameter name= "database" value="Hive_961"/>
   
<test name="m_AggregatorTx">
                <parameter name="logFile" value="hadoopmslogs/${Domain_Name}/${NODENAME}/Hive_961/m_AggregatorTx.log"/>
                <classes>
                        <class name="executems.main.RunMS"></class>
                </classes>
        </test>

<test name="m_alldt">
                <parameter name="logFile" value="hadoopmslogs/${Domain_Name}/${NODENAME}/Hive_961/m_alldt.log"/>
                <parameter name="enableUT" value="true"/>
                <classes>
                        <class name="executems.main.RunMS"></class>
                </classes>
        </test>
<test name="m_alldt_cpx">
                <parameter name="logFile" value="hadoopmslogs/${Domain_Name}/${NODENAME}/Hive_961/m_alldt_cpx.log"/>
                <classes>
                        <class name="executems.main.RunMS"></class>
                </classes>
        </test>
<test name="m_alldt_custom_query_prop">
                <parameter name="logFile" value="hadoopmslogs/${Domain_Name}/${NODENAME}/Hive_961/m_alldt_custom_query_prop.log"/>
                <parameter name="enableUT" value="true"/>
                <classes>
                        <class name="executems.main.RunMS"></class>
                </classes>
        </test>
</suite>

In runtime, I want to ignore the tests which do not have enableUT parameter in it.
For example, in the above suite file m_AggregatorTx and m_alldt_cpx do not have enableUT parameter in them.

Note: 
1. I do not want to add enabled=true/false to my suite xml. ( Because I have 30 different suite files which have 100 test cases each)
2. Currently during runtime, I am able to Skip these tests using throw new SkipException. But once a run finishes, the results comes as this:

===============================================
Hive_961
Total tests run: 4, Failures: 0, Skips: 2
===============================================
3. I do not want the two cases to show up in the Skips section in the result. I want those cases to be ignored during run-time.
I want the result something like this:

===============================================
Hive_961
Total tests run: 2, Failures: 0, Skips: 0
===============================================

if(enableBugB.equals("true"))
{
System.out.println("enableBugB is set to true in this Test Case");
boolean result = Services.runMapping(applicationName, mappingName, database, runID);
if(runID != null && !runID.isEmpty())
{
VerifyMapping.compareResults(verifyXml, runID, logPath,result);
}
else
{
VerifyMapping.compareResults(verifyXml, mappingName, logPath,result);
}
}
else
{
//System.out.println("enableBugB is not present for this Test. Hence skipping this Test Case..");
throw new SkipException("enableBugB is not enabled. Skipping this Test Case..");
}


Appreciate any help. Thanks.

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

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/

My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Urgent: TestNG: Is there a way to ignore a test completely based on a Condition (if a parameter does not exist in the test)

Ramakrishna Prasad
In reply to this post by Krishnan Mahadevan
Thanks Krishnan. Got similar solution for the same query in stackoverflow and now I am able to do what I was looking for.

Thanks a lot for your time.

On Saturday, April 1, 2017 at 8:04:18 PM UTC+5:30, Krishnan wrote:

Maybe you could try leveraging a method interceptor to do what you are looking for.

This gist shows you how to work with a method interceptor and wire it in as a listener.

<a href="https://gist.github.com/krmahadevan/5028960" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fkrmahadevan%2F5028960\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFA7J3RHlsJUSut_q4exYpOEoXcjw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Fkrmahadevan%2F5028960\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFA7J3RHlsJUSut_q4exYpOEoXcjw&#39;;return true;">https://gist.github.com/krmahadevan/5028960

I think it's worth giving it a try.


On Sat, Apr 1, 2017, 18:27 Ramakrishna Prasad <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="GeQcpSAKBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">prasadku...@...> wrote:
Hi All,

Below is my TestNG suite xml file.

<suite name="Hive_961" thread-count="1">
      <parameter name="connectionFile" value="Connections/ConnHive_961"/>
      <parameter name="settingXmlPath" value="Resources/EnvironmentFiles/EnvHIVE_961.xml"/>
      <parameter name="verifyXml" value="Resources/VerifyFiles/1011/VerifyHIVE_961.xml"/>
      <parameter name="onlyVerify" value="false"/>
      <parameter name= "applicationPath" value="Applications/1011/Hive_961.iar"/>
      <parameter name= "database" value="Hive_961"/>
   
<test name="m_AggregatorTx">
                <parameter name="logFile" value="hadoopmslogs/${Domain_Name}/${NODENAME}/Hive_961/m_AggregatorTx.log"/>
                <classes>
                        <class name="executems.main.RunMS"></class>
                </classes>
        </test>

<test name="m_alldt">
                <parameter name="logFile" value="hadoopmslogs/${Domain_Name}/${NODENAME}/Hive_961/m_alldt.log"/>
                <parameter name="enableUT" value="true"/>
                <classes>
                        <class name="executems.main.RunMS"></class>
                </classes>
        </test>
<test name="m_alldt_cpx">
                <parameter name="logFile" value="hadoopmslogs/${Domain_Name}/${NODENAME}/Hive_961/m_alldt_cpx.log"/>
                <classes>
                        <class name="executems.main.RunMS"></class>
                </classes>
        </test>
<test name="m_alldt_custom_query_prop">
                <parameter name="logFile" value="hadoopmslogs/${Domain_Name}/${NODENAME}/Hive_961/m_alldt_custom_query_prop.log"/>
                <parameter name="enableUT" value="true"/>
                <classes>
                        <class name="executems.main.RunMS"></class>
                </classes>
        </test>
</suite>

In runtime, I want to ignore the tests which do not have enableUT parameter in it.
For example, in the above suite file m_AggregatorTx and m_alldt_cpx do not have enableUT parameter in them.

Note: 
1. I do not want to add enabled=true/false to my suite xml. ( Because I have 30 different suite files which have 100 test cases each)
2. Currently during runtime, I am able to Skip these tests using throw new SkipException. But once a run finishes, the results comes as this:

===============================================
Hive_961
Total tests run: 4, Failures: 0, Skips: 2
===============================================
3. I do not want the two cases to show up in the Skips section in the result. I want those cases to be ignored during run-time.
I want the result something like this:

===============================================
Hive_961
Total tests run: 2, Failures: 0, Skips: 0
===============================================

if(enableBugB.equals("true"))
{
System.out.println("enableBugB is set to true in this Test Case");
boolean result = Services.runMapping(applicationName, mappingName, database, runID);
if(runID != null && !runID.isEmpty())
{
VerifyMapping.compareResults(verifyXml, runID, logPath,result);
}
else
{
VerifyMapping.compareResults(verifyXml, mappingName, logPath,result);
}
}
else
{
//System.out.println("enableBugB is not present for this Test. Hence skipping this Test Case..");
throw new SkipException("enableBugB is not enabled. Skipping this Test Case..");
}


Appreciate any help. Thanks.

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

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/

My Technical Scribbings @ <a href="http://rationaleemotions.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Loading...