How to get Running test case name on report

Hi,

For example i am running multiple tests (@Test) . How to generate test name in reports
dc.setCapability(“testName”, testName);

I running through TestNG.

Thanks in advance…

Hi,
I would recommend to use the Class name and the method name as the ‘testName’.
For example:
LoginTests.successLogin

One challenge around it is that the capability is set at the setUp method and it can serve multiple tests. I would recommend to separate your tests so you will have one test per class. So the test name can be only the class name:
SuccessLoginTest

So in that case your code can be:
dc.setCapability(“testName”, this.getClass().getName());

Thanks Guy for quick response and help.

I have multiple testcases in multiple class - for this scenario how can we do and get test name to report.

As your suggestion i cant separate or keep single test to single class (Which goes many classes)

Could you please help on this.

Best Regards,
Sudhakar MK

Hi @sudhakar

If you wish to retrieve the name of each method that is annotated with @Test, and put the name in the testName variable to be added to the DesiredCapabilities, do the following:

Create a method and annotate with @BeforeMethod, pass it the type import java.lang.reflect.Method.

  @BeforeMethod
    public void setUp(Method m) {

       dc.setCapability("testName", m.getName());
    }

Thanks nivi for Reply and help.

I tried the above m.getName() …but its not working.

Capabilities are not working …

For TestNG look at the following:

Great Guy …Thanks its working like charm…

My mistake import was wrong.

we need to import java.lang.reflect.Method

Regards,
Sudhakar MK

What is the method for junit?

google.com

already read this post and appium keeps returning Untitled.

@pmaristani

It should work…

Have a look at the snippet below:

import org.junit.*;
import org.junit.rules.TestName;

public class TestClass {

@Rule public TestName testName = new TestName();

@Before
public void setup(){
    System.out.println(testName.getMethodName());
    // set capability ("testName", testName.getMethodName())
}

@Test
public void NameOfTestMethod(){

    System.out.println("Test");
}


@After
public void tearDown(){
    System.out.println("After");
}

}

he method getMethodName() is undefined for the type String

=(

Hi @pmaristani

In the import section, right above the class, add the following import statements:

import org.junit.*;
import org.junit.rules.TestName;
1 Like

worked thank you!!!