In the web application i am trying to automate there is a Login page and a Secure page.
When user enters valid credentials in Login page s/he is navigated to Secure page with a success message. If the credentials are invalid s/he would stay in the same page with an error message.
I have created two page objects to represent them LoginPage and Secure Page.
Login Page
public class LoginPage extends BasePage
{
public void loginWith(String username,String password)
{
enter(usernameLocator, username);
enter(passwordLocator,password);
clickOn(loginButton);
}
}
Secure Page
public class SecurePage extends BasePage
{
public void logout()
{
if(isDisplayed(logoutButton))
{
clickOn(logoutButton);
}
else
{
System.out.println("Log out button is not displayed");
}
return this;
}
}
Test Class
public class LoginTests extends BaseTest
{
@Test(dataProvider="TestData", dataProviderClass=TestDataProvider.class)
public void validUserLoginTest(String username, String password)
{
LoginPage login = new LoginPage(driver);
login.loginWith(username, password);
}
}
Now, I want make modifications to my loginWith()
method so that I could return respective page object based on the credentials entered. (i.e, if valid credentials -> Secure Page, invalid credentials -> Login Page).
Can you please suggest how could I do achieve that?
One solution I thought is to create two methods in my login page like loginWithValidCrendentials(), loginWithInvalidCrendentials()
.
But, I don't want to create two methods which basically does the same action(but would produce different results because of their method parameters).