Code review of a beginner Selenium test
This is the code to be reviewed:
@Test(priority =1)
void testCourses() {
LoginPage lp = new LoginPage(driver);
String username= ReadExcelFile.getCellValue(fileName, "LoginData", 1, 0);
String password= ReadExcelFile.getCellValue(fileName, "LoginData", 1, 1);
System.out.println(username+" "+password);
lp.loginPortal(username,password);
DashBoardPage dp = new DashBoardPage(driver);
dp.dashboardClick();
}
How many issues can you find?
Code review feedback below:
do not use priority attribute since the tests should run in any order; if you need test grouping, use TestNG groups instead
testCourses() is a bad name for a test method as it does not explain how the courses are tested
the username and password can be set outside of the test method as class variables/methods
it is a complex choice to use an excel file for storing test data; json should be used instead
do not print anything in the console unless the test is not complete; do not use the console as a way of checking that the code works well
lp is a bad name for a page object; what does lp mean?
lp should be declared when it is used and not before
loginPortal() is too complex as a method name; just use login()
it is not clear how the site is loaded
it is not clear how the user goes from login page to dashboard page
click should not be used in method names; the method names should be focused on what the user does and not on how the interaction with the site happens
what does dashBoardClick() do?
there are no assertions; what does the test check?
Updated test:
@Test
void coursesAreLoadedInTheDashBoardTest() {
LoginPage loginPage = new LoginPage(driver);
loginPage.open();
DashboardPage dashBoardPage = loginPage.login(getUserName(),
getPassword());
assertTrue(dashBoardPage.getCourseCount() > 0);
}
private String getUserName() {
return ReadExcelFile.getCellValue(fileName, "LoginData", 1, 0);
}
private String getPassword() {
return ReadExcelFile.getCellValue(fileName, "LoginData", 1, 1);
}
Thanks for reading.