Explore Courses Blog Tutorials Interview Questions
+1 vote
in DevOps and Agile by (19.7k points)

I am new to testNG, I have the below code:


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 want the group name in before method, I tried using ITestAnnotation but when I run the test I am getting the below error

Method getGroup requires 1 parameters but 0 were supplied in the @Configuration annotation.

Can you please help the parameter which I should pass from the XML?

1 Answer

0 votes
by (62.9k points)

Use the reflected method to get the group of the test as below :


public void befMet(Method m){

        Test t = m.getAnnotation(Test.class);

        System.out.println(t.groups()[0]);//or however you want to use it.


Browse Categories