I have a POM framework. In the BaseTest class I have the following @BeforeMethod
@BeforeMethod(alwaysRun = true)
@Parameters("url")
public void goHome(String URL) {
driver.get(URL);
this.setInventoryPage(
new LoginPage(driver)
.setUsername(this.getSauceUserName())
.setPassword(this.getSaucePassword())
.clickLoginButton());
}
That method includes the login steps so I don't have to add the same line of code in all the tests. Now, the issue is that I have the following 2 test scenarios in the LoginTests class (locked account and wrong credentials). My LoginTests class extends BaseTests class.
@Test(groups = {"Login", "Negative" })
public void lockedCredentials(){
LoginPage loginPage = new LoginPage(driver);
loginPage.setUsername("wrong_user");
loginPage.setPassword("secret_sauce");
loginPage.clickLoginButton();
assertTrue(loginPage.getErrorMessageText()
.contains("Epic sadface: Sorry, this user has been locked out."),
"Credentials are not locked!");
}
@Test(groups = {"Login", "Negative"})
public void invalidCredentials(){
LoginPage loginPage = new LoginPage(driver);
loginPage.setUsername("wrong_user");
loginPage.setPassword("wrong_pass");
loginPage.clickLoginButton();
assertTrue(loginPage.getErrorMessageText()
.contains("Epic sadface: Username and password do not match any user in this service"),
"The credentials entered are valid!");
}
My question is how do I ignore the above @BeforeMethod for the above 2 tests scenarios (just for locked account and wrong credentials)?
Note: I'm using TestNG.