Problem with annotations @BeforeTest @AfterTest in automated testing

0

I am learning to use Selenium with Eclipse for the automation of tests. When I try to run annotations, I get the error:

  

the annotation "X" is disallowed for this location.

As I am starting with the theme, I am leaving something important in the pipeline.

package TestNG;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;

@BeforeTest
public void login() {
    System.out.println("BT");
}

@AfterTest
public void logout{
    System.out.println("AT");
}

public class TestNGClass {
    @Test 
    public void testContact(){
        System.out.println("Test1");
    }
}

Could someone help me with the error? Thank you.

    
asked by L. Arena 26.10.2017 в 10:02
source

1 answer

0

The @Before and @After methods must be inside a class as well.

After this the annotations must work correctly before the methods:

public class ProjectWebAnnotations {
@BeforeTest
public void startTest(final ITestContext testContext) {}

@BeforeMethod
public void openDriver() {}

@AfterMethod
public void closeDriver() {}
}
    
answered by 26.10.2017 в 10:23