This is a QA project using gradle, serenity bdd for test automation
Every serenity project has 3 parts similar to 3 amigos
- Page Object :- For web this is the page to be automated
- Test steps :- These are steps taken or different actions that can be done on a page
- The Test :- Actual test when the test steps are called.
In this simple project , I will be automating the login to OrangeHRM page
The page object
@DefaultUrl("https://opensource-demo.orangehrmlive.com/")
public class Dashboard extends PageObject {
public void enterUsername() {
$("#txtUsername").sendKeys("Admin");
}
public void enterPassword() {
$("#txtPassword").sendKeys("admin123");
}
public void doLogin() {
$("#btnLogin").click();
}
public String hasLoggedIn() {
String heading = $("div.head h1").getText();
return heading;
}
}
The Page Object steps
public class DashboardSteps {
private Dashboard dashboardPage;
@Step
public void isOnLoginPage() {
dashboardPage.open();
}
@Step
public void userEntersUsername() {
dashboardPage.enterUsername();
}
@Step
public void userEntersPassword() {
dashboardPage.enterPassword();
}
@Step
public void userClicksLogin() {
dashboardPage.doLogin();
}
@Step
public void userShouldBeLoggedIn() {
Assertions.assertTrue(dashboardPage.hasLoggedIn().equals("Dashboard"));
}
}
The Test
@RunWith(SerenityRunner.class)
public class DashboardTest {
@Steps
DashboardSteps dashboardSteps;
@Managed(driver = "chrome")
WebDriver driver;
@Test
public void userLogin() {
dashboardSteps.isOnLoginPage();
dashboardSteps.userEntersUsername();
dashboardSteps.userEntersPassword();
dashboardSteps.userClicksLogin();
dashboardSteps.userShouldBeLoggedIn();
}
}