How to run test case which are in group and having priority one.

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

How to run test case which are in group and having priority one.

Shishir Dwivedi
Hi ,

I want to run those test case which are in particular group say A and having priority 1.Group A also include test case having priority 2,3 etc... and i don't want to run priority 2 and 3 test cases.


Please 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
|

Re: How to run test case which are in group and having priority one.

Krishnan Mahadevan
You should be able to use the bean-shell capability of TestNG to do this.

You can refer to the below links for more information
Test Class
package organized.chaos.testng;

import org.testng.annotations.Test;

public class ManyGroupsAndManyPriorities {
@Test (groups = {"ios"}, priority = 1)
public void iPhoneSix() {
System.err.println("Hey I am the iPhone 6");
}

@Test (groups = {"ios"}, priority = 2)
public void iPhoneFive() {
System.err.println("Hey I am the iPhone 5");
}

@Test (groups = {"ios"}, priority = 2)
public void iPhoneFiveS() {
System.err.println("Hey I am the iPhone 5S");
}

@Test (groups = {"ios"}, priority = 3)
public void iPhoneFour() {
System.err.println("Hey I am the iPhone 4");
}

@Test (groups = {"windows"}, priority = 1)
public void windows640XL() {
System.err.println("Hey I am the Microsoft 640 XL");
}
}

Suite XML 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="MobileSuite" parallel="false" verbose="2">
<test name="MobileTest">
<method-selectors>
<method-selector>
<script language="beanshell">
<![CDATA[
whichGroup = System.getProperty("groupName","");
if (whichGroup.trim().isEmpty()) {
return true;
}
boolean groupFlag = groups.containsKey(whichGroup);
priority = System.getProperty("priority","");
if (priority.trim().isEmpty() ){
return groupFlag && true;
}
value = Integer.parseInt(priority);
return ( (testngMethod.getPriority() == value) && groupFlag );
]]></script>
</method-selector>
</method-selectors>
<classes>
<class name="organized.chaos.testng.ManyGroupsAndManyPriorities"/>
</classes>
</test>
</suite>

Output 

mvn clean test -DsuiteXmlFile=mobiles.xml -DgroupName=ios -Dpriority=2

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
...
... TestNG 6.9.9 by Cédric Beust ([hidden email])
...

Hey I am the iPhone 5
Hey I am the iPhone 5S
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.37 sec - in TestSuite

Results :

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

Explanation :
  • If you don't provide a group Name, by default all groups get executed.
  • If group Name is provided but no priority was specified, all methods that belong to a group are executed.
  • Only if groups and priorities are provided is when they would get used.

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/

On Wed, Dec 30, 2015 at 4:26 PM, Shishir Dwivedi <[hidden email]> wrote:
Hi ,

I want to run those test case which are in particular group say A and having priority 1.Group A also include test case having priority 2,3 etc... and i don't want to run priority 2 and 3 test cases.


Please 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.

--
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
|

Re: How to run test case which are in group and having priority one.

Panikera
Hi Krishnan,

This above post is very help full, Thanks to you.

here I am trying to execute only priority test cases from CLI using below command:

mvn clean test -DsuiteXmlFile=GroupPriority.xml -Dpriority=2

but here executing all the test cases. Am I doing something wrong.


-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
...
... TestNG 6.8.9beta by Cédric Beust ([hidden email])
...

Hey this is iphone SIX
Hey this is iphone FIVE
Hey this is iphone 5S
Hey this is Windows 64
Hey this is iphone FOUR
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.65 sec

Results :

Tests run: 5, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.505 s
[INFO] Finished at: 2016-01-05T10:30:34+05:30
[INFO] Final Memory: 16M/180M
[INFO] ------------------------------------------------------------------------


Thanks in advance

- Panikera



On Fri, Jan 1, 2016 at 6:49 PM, Krishnan Mahadevan <[hidden email]> wrote:
You should be able to use the bean-shell capability of TestNG to do this.

You can refer to the below links for more information
Test Class
package organized.chaos.testng;

import org.testng.annotations.Test;

public class ManyGroupsAndManyPriorities {
@Test (groups = {"ios"}, priority = 1)
public void iPhoneSix() {
System.err.println("Hey I am the iPhone 6");
}

@Test (groups = {"ios"}, priority = 2)
public void iPhoneFive() {
System.err.println("Hey I am the iPhone 5");
}

@Test (groups = {"ios"}, priority = 2)
public void iPhoneFiveS() {
System.err.println("Hey I am the iPhone 5S");
}

@Test (groups = {"ios"}, priority = 3)
public void iPhoneFour() {
System.err.println("Hey I am the iPhone 4");
}

@Test (groups = {"windows"}, priority = 1)
public void windows640XL() {
System.err.println("Hey I am the Microsoft 640 XL");
}
}

Suite XML 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="MobileSuite" parallel="false" verbose="2">
<test name="MobileTest">
<method-selectors>
<method-selector>
<script language="beanshell">
<![CDATA[
whichGroup = System.getProperty("groupName","");
if (whichGroup.trim().isEmpty()) {
return true;
}
boolean groupFlag = groups.containsKey(whichGroup);
priority = System.getProperty("priority","");
if (priority.trim().isEmpty() ){
return groupFlag && true;
}
value = Integer.parseInt(priority);
return ( (testngMethod.getPriority() == value) && groupFlag );
]]></script>
</method-selector>
</method-selectors>
<classes>
<class name="organized.chaos.testng.ManyGroupsAndManyPriorities"/>
</classes>
</test>
</suite>

Output 

mvn clean test -DsuiteXmlFile=mobiles.xml -DgroupName=ios -Dpriority=2

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
...
... TestNG 6.9.9 by Cédric Beust ([hidden email])
...

Hey I am the iPhone 5
Hey I am the iPhone 5S
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.37 sec - in TestSuite

Results :

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

Explanation :
  • If you don't provide a group Name, by default all groups get executed.
  • If group Name is provided but no priority was specified, all methods that belong to a group are executed.
  • Only if groups and priorities are provided is when they would get used.

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/

On Wed, Dec 30, 2015 at 4:26 PM, Shishir Dwivedi <[hidden email]> wrote:
Hi ,

I want to run those test case which are in particular group say A and having priority 1.Group A also include test case having priority 2,3 etc... and i don't want to run priority 2 and 3 test cases.


Please 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.

--
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.

--
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
|

Re: How to run test case which are in group and having priority one.

Krishnan Mahadevan
Panikera,

The Beanshell that I shared was specifically aimed at coupling both the group name and the priority. If you want to run only based on priority then you should write up/tweak the beanshell method selector. It wasn't meant to be a generic ready to be consumed method selector. It was an example that was trying to solve a specific use case of the OP.

In your case, you didnt provide a group name, so the beanshell method selector by default ended up having every test to be executed and the control never went to the section that works with the priority.


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/

On Tue, Jan 5, 2016 at 10:35 AM, Panikera Raj <[hidden email]> wrote:
Hi Krishnan,

This above post is very help full, Thanks to you.

here I am trying to execute only priority test cases from CLI using below command:

mvn clean test -DsuiteXmlFile=GroupPriority.xml -Dpriority=2

but here executing all the test cases. Am I doing something wrong.


-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
...
... TestNG 6.8.9beta by Cédric Beust ([hidden email])
...

Hey this is iphone SIX
Hey this is iphone FIVE
Hey this is iphone 5S
Hey this is Windows 64
Hey this is iphone FOUR
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.65 sec

Results :

Tests run: 5, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.505 s
[INFO] Finished at: 2016-01-05T10:30:34+05:30
[INFO] Final Memory: 16M/180M
[INFO] ------------------------------------------------------------------------


Thanks in advance

- Panikera



On Fri, Jan 1, 2016 at 6:49 PM, Krishnan Mahadevan <[hidden email]> wrote:
You should be able to use the bean-shell capability of TestNG to do this.

You can refer to the below links for more information
Test Class
package organized.chaos.testng;

import org.testng.annotations.Test;

public class ManyGroupsAndManyPriorities {
@Test (groups = {"ios"}, priority = 1)
public void iPhoneSix() {
System.err.println("Hey I am the iPhone 6");
}

@Test (groups = {"ios"}, priority = 2)
public void iPhoneFive() {
System.err.println("Hey I am the iPhone 5");
}

@Test (groups = {"ios"}, priority = 2)
public void iPhoneFiveS() {
System.err.println("Hey I am the iPhone 5S");
}

@Test (groups = {"ios"}, priority = 3)
public void iPhoneFour() {
System.err.println("Hey I am the iPhone 4");
}

@Test (groups = {"windows"}, priority = 1)
public void windows640XL() {
System.err.println("Hey I am the Microsoft 640 XL");
}
}

Suite XML 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="MobileSuite" parallel="false" verbose="2">
<test name="MobileTest">
<method-selectors>
<method-selector>
<script language="beanshell">
<![CDATA[
whichGroup = System.getProperty("groupName","");
if (whichGroup.trim().isEmpty()) {
return true;
}
boolean groupFlag = groups.containsKey(whichGroup);
priority = System.getProperty("priority","");
if (priority.trim().isEmpty() ){
return groupFlag && true;
}
value = Integer.parseInt(priority);
return ( (testngMethod.getPriority() == value) && groupFlag );
]]></script>
</method-selector>
</method-selectors>
<classes>
<class name="organized.chaos.testng.ManyGroupsAndManyPriorities"/>
</classes>
</test>
</suite>

Output 

mvn clean test -DsuiteXmlFile=mobiles.xml -DgroupName=ios -Dpriority=2

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
...
... TestNG 6.9.9 by Cédric Beust ([hidden email])
...

Hey I am the iPhone 5
Hey I am the iPhone 5S
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.37 sec - in TestSuite

Results :

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0

Explanation :
  • If you don't provide a group Name, by default all groups get executed.
  • If group Name is provided but no priority was specified, all methods that belong to a group are executed.
  • Only if groups and priorities are provided is when they would get used.

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/

On Wed, Dec 30, 2015 at 4:26 PM, Shishir Dwivedi <[hidden email]> wrote:
Hi ,

I want to run those test case which are in particular group say A and having priority 1.Group A also include test case having priority 2,3 etc... and i don't want to run priority 2 and 3 test cases.


Please 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.

--
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.

--
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.

--
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.