I have a task do create e2e for a web app, but I don't know what is the correct way doing it.
For example: In app there is a possibility to add new employee, so the scenario is as described:
- Login to application(it can be implemented in TestNG @BeforeClass annotation)
- Switch to correct role that have posibility to add employee
- Forward to form & Filling form and submit
- Switch to employee tab, assert that employee exists @AfterClass teardown
In testing project I have to use Selenium with TestNG.
My question is what is the correct way to do this? There are three possible options:
Option 1:
public class CreateEmployeeTest {
@BeforeClass
public void loginToApplication() {
driver.get("url");
new LoginPage(driver).login("username", "password");
}
@Test
public void addNewEmployee() {
new DashboardPage(driver)
.clickAddEmployeeButton();
new AddEmployeeForm(driver)
.fillFirstName("Name")
.fillLastName("LastName")
.fillEmail("email")
.submitForm();
new WebDriverWait(driver, 10)
.until(ExpectedConditions.urlContains("/employees"));
assertThat(new EmployeeDetails(driver).getEmployeeName(), equalTo(String.format("%s %s", "Name", "LastName")));
}
@Test(dependsOnMethods = "addNewEmployee")
public void verifyThatEmployeeIsOnList() throws InterruptedException {
new DashboardPage
.switchToEmployesTab()
.search(String.format("%s %s", "Name", "LastName"));
Assert.assertTrue(DashboardPage.checkThatUserIsOnList(String.format("%s %s", "Name", "LastName")));
}
}
Is it correct to create tests like this? I mean to create few @Test in one scenario with 'dependsOnMethod' option.
Option 2:
public class CreateEmployeeTest {
@BeforeClass
public void loginToApplication() {
driver.get("url");
new LoginPage(driver).login("username", "password");
}
@Test
public void addNewEmployee() {
new DashboardPage(driver)
.clickAddEmployeeButton();
new AddEmployeeForm(driver)
.fillFirstName("Name")
.fillLastName("LastName")
.fillEmail("email")
.submitForm();
new WebDriverWait(driver, 10)
.until(ExpectedConditions.urlContains("/employees"));
assertThat(new EmployeeDetails(driver).getEmployeeName(), equalTo(String.format("%s %s", "Name", "LastName")));
new DashboardPage
.switchToEmployesTab()
.search(String.format("%s %s", "Name", "LastName"));
Assert.assertTrue(DashboardPage.checkThatUserIsOnList(String.format("%s %s", "Name", "LastName")));
}
}
Option 2 Create one @Test and write a full scenario in it. If option two is correct - what is the best way with dealing with very long tests?
Option 3: Maybe two of examples are incorrect - your idea?