how to config TestNG XML to run the intersection of two groups?

472 views
Skip to first unread message

baijing...@gmail.com

unread,
Aug 13, 2014, 11:22:54 AM8/13/14
to testng...@googlegroups.com
for example:
I want to run methods which belongs to groupA and belongs to groupC as the same time.

@Test(groups={ "groupA", "groupB", "groupC" })
public void method1() {
}

@Test(groups={ "groupA", "groupB" })
public void method2() {
}

@Test(groups={ "groupA", "groupC" })
public void method3() {
}


Giannis Papadakis

unread,
Aug 13, 2014, 1:17:26 PM8/13/14
to testng...@googlegroups.com
Hi you can use beanshell expression inside test tag like:

<method-selectors>
    <method-selector>
      <script language="beanshell"><![CDATA[
        (groups.containsKey(GroupÀ) && groups.containsKey(GroupC))]]>
        </script>
     </method-selector>
    </method-selectors>


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

baijing...@gmail.com

unread,
Aug 14, 2014, 12:38:20 AM8/14/14
to testng...@googlegroups.com
Thank you !!

在 2014年8月14日星期四UTC+8上午1时17分26秒,John Papadakis写道:

baijing...@gmail.com

unread,
Aug 14, 2014, 1:51:33 AM8/14/14
to testng...@googlegroups.com
can't let beanshell work for me, did I write something wrong?



在 2014年8月14日星期四UTC+8上午1时17分26秒,John Papadakis写道:

Giannis Papadakis

unread,
Aug 14, 2014, 2:07:48 AM8/14/14
to testng...@googlegroups.com
Hi 
<method-selector> can be specified on <suite> or <test> tags...Do you include <test> tags with you test classes in your xml? 

Regards

baijing...@gmail.com

unread,
Aug 14, 2014, 2:55:55 AM8/14/14
to testng...@googlegroups.com




在 2014年8月14日星期四UTC+8下午2时07分48秒,John Papadakis写道:

baijing...@gmail.com

unread,
Aug 14, 2014, 3:04:49 AM8/14/14
to testng...@googlegroups.com
I used "GroupA" and "GroupC" before, but it should be "groupA" and "groupC";
I fixed this, but still same result: run 0

在 2014年8月14日星期四UTC+8下午2时07分48秒,John Papadakis写道:

Giannis Papadakis

unread,
Aug 14, 2014, 3:06:38 AM8/14/14
to testng...@googlegroups.com
Your group name is in Lower case and in the bean shell expression you have the first char in Upper case (GroupA instead of groupA)!!!!


baijing...@gmail.com

unread,
Aug 14, 2014, 4:01:54 AM8/14/14
to testng...@googlegroups.com
I fixed this, but still same result: run 0



在 2014年8月14日星期四UTC+8下午3时06分38秒,John Papadakis写道:

Giannis Papadakis

unread,
Aug 14, 2014, 4:16:32 AM8/14/14
to testng...@googlegroups.com
i have other result for example:
package DemoTest;

import org.testng.annotations.Test;

public class TestBeanShell {

    @Test(groups={"groupA","groupC"})
    public void test1(){
        System.out.println("test1 executed!!!");
    }


    @Test(groups={"groupA"})
    public void test2(){
        System.out.println("test2 executed!!!");
    }


    @Test(groups={"groupB"})
    public void test3(){
        System.out.println("test3 executed!!!");
    }
}

and xml:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="BeanShell" verbose="2">

 
<test
 name="BeanShell">
  <method-selectors>
    <method-selector>
      <script language="beanshell"><![CDATA[
        (groups.containsKey("groupA") && groups.containsKey("groupC"))]]>
        </script>
     </method-selector>
    </method-selectors>
  <classes>
   <class
    name="DemoTest.TestBeanShell">
   </class>
  </classes>
  </test>
</suite>


The result is:

[TestNG] Running:
  D:\privateGitHub\project\BeanShell.xml

test1 executed!!!
PASSED: test1

===============================================
    BeanShell
    Tests run: 1, Failures: 0, Skips: 0
===============================================


===============================================
BeanShell
Total tests run: 1, Failures: 0, Skips: 0
===============================================

[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@5214cda3: 43 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@3f874627: 34 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@11be0773: 10 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@22e7ef68: 5 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@21606a56: 7 ms

baijing...@gmail.com

unread,
Aug 14, 2014, 5:19:37 AM8/14/14
to testng...@googlegroups.com
ok, thank you very much!!
don't know why I can't let it work.

在 2014年8月14日星期四UTC+8下午4时16分32秒,John Papadakis写道:
Reply all
Reply to author
Forward
0 new messages