How to get testgroup name in TestNG
I am new to testNG, I have below code:
@BeforeMethod
public void getGroup(ITestAnnotation annotation){
System.out.println("Group Name is --" + annotation.getGroups()) ;
}
@Test(groups = { "MobilSite" })
public void test1(){
System.out.println("I am Running Mobile Site Test");
}
I need the group name in front of the method, I tried using ITestAnnotation
, but when I run the test, I get the following error
Method getGroup requires 1 parameters but 0 were supplied in the @Configuration annotation.
Can you please help the parameter that I have to pass from XML?
+3
source to share
3 answers
If you want to find out the name of all groups to which a method belongs @Test
:
@BeforeMethod
public void beforeMethod(Method method){
Test testClass = method.getAnnotation(Test.class);
for (int i = 0; i < testClass.groups().length; i++) {
System.out.println(testClass.groups()[i]);
}
}
+1
source to share