Is it possible to write testng name testng from the called method?

I am running Selenium tests using Java (TestNG and IntelliJ) and am currently working on my reporting framework. My test setup looks something like this:

@Test
public void testLogin(){
  myKeyword.login();
}

myKeyword is the keyword class I created using the login method. The login keyword will look like this:

public void login(){
  myPage.typeInTextBox("Username");
  myPage.typeInTextBox("Password");
  myPage.buttonClick("Login");
}

My check is built into the "buttonClick" and "typeInTextBox" methods. They will look something like this:

try{
  driver.findelement(By.id("myButton")).click();
}
catch (Exception e){
  Assert.fail("Could not click on the button.");
}

What I want to know is it possible for the "buttonClick" method to know the name of the test calling it?

"Assert.fail..." , , , , ( "testLogin".

+4
1

- -, , . TestNG here.

public class Test { 
    @BeforeMethod
    public void handleTestMethodName(java.lang.reflect.Method method) {
        GlobalVariables.currentTestName = method.getName(); 
    }
...
}
+3

Source: https://habr.com/ru/post/1689360/


All Articles