0

I use POM pattern in Selenium tests.
To run tests OpCreate and OpEdit, a user should be logged in.
I have positive test for Login, but how to run Login every time OpCreate and OpEdit tests are run? Probably, there are other solutions?

public class SignInPage {
    //some @FindBy here

    public void makeLogin(String email, String password) {
        emailLogin.sendKeys(email);
        passwordLogin.sendKeys(password);
        loginButton.click();
}

public class LoginTest extends UiTestBase {

    @Test()
    private void UicorrectLogin() {
        //init user and pass

       loginPage.makeLogin(user, pass);
       //check for login
       Assert.assertEquals(true, menuPage.getMenu().isDisplayed());
    }

    @AfterMethod
    private void tearDown() {
    }
}


public class OpTest extends UiTestBase {

    @Test()
    private void OpCreate() {
        //some Op test
        }

    @Test()
    private void OpEdit() {
        //some Op test
        }
    }
0

Add a @BeforeTest and make login in that method in the LoginTest and OpTest class.

public class LoginTest extends UiTestBase {

SignInPage signInPage = new SignInpage();

@BeforeTest
public void loginBeforeTest(){
    signInPage.makeLogin(user, pass);
}
@Test()
private void UicorrectLogin() {
    //init user and pass

   loginPage.makeLogin(user, pass);
   //check for login
   Assert.assertEquals(true, menuPage.getMenu().isDisplayed());
}

@AfterMethod
private void tearDown() {
}
}


public class OpTest extends UiTestBase {

SignInPage signInPage = new SignInpage();

@BeforeTest
public void loginBeforeTest(){
    signInPage.makeLogin(user, pass);
}
@Test()
private void OpCreate() {
    //some Op test
    }

@Test()
private void OpEdit() {
    //some Op test
    }
} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.