Skip to content

Commit 461cc2c

Browse files
committed
misc refactor
1 parent fc63da3 commit 461cc2c

File tree

3 files changed

+26
-41
lines changed

3 files changed

+26
-41
lines changed

src/main/java/io/github/tahanima/page/login/LoginPage.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ public LoginPage navigateToUrl() {
1919
return this;
2020
}
2121

22-
@Step("Fill <username> in 'Username' textbox")
23-
public LoginPage fillUsernameInTextBox(String username) {
22+
@Step("Type <username> into 'Username' textbox")
23+
public LoginPage typeUsernameIntoTextBox(String username) {
2424
page.fill("id=user-name", username);
2525

2626
return this;
2727
}
2828

29-
@Step("Fill <password> in 'Password' textbox")
30-
public LoginPage fillPasswordInTextBox(String password) {
29+
@Step("Type <password> into 'Password' textbox")
30+
public LoginPage typePasswordIntoTextBox(String password) {
3131
page.fill("id=password", password);
3232

3333
return this;

src/test/java/io/github/tahanima/e2e/login/LoginE2ETest.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
class LoginE2ETest extends BaseE2ETest {
2020

21+
private final static String PATH = "login/login.csv";
2122
private LoginPage loginPage;
2223

2324
@BeforeEach
@@ -45,12 +46,12 @@ public void closeBrowserContextSession() {
4546
@Owner("Tahanima Chowdhury")
4647
@Description(
4748
"Test that verifies user gets redirected to 'Products' page after submitting correct login credentials")
48-
@DataSource(testCaseId = "TC-1", filePath = "login/login.csv", clazz = LoginTestData.class)
49+
@DataSource(testCaseId = "TC-1", filePath = PATH, clazz = LoginTestData.class)
4950
void testCorrectLoginCredentials(LoginTestData loginDto) {
5051
loginPage
5152
.navigateToUrl()
52-
.fillUsernameInTextBox(loginDto.getUserName())
53-
.fillPasswordInTextBox(loginDto.getPassword())
53+
.typeUsernameIntoTextBox(loginDto.getUserName())
54+
.typePasswordIntoTextBox(loginDto.getPassword())
5455
.clickOnLoginButton();
5556

5657
ProductsPage productsPage = createInstance(ProductsPage.class);
@@ -64,12 +65,12 @@ void testCorrectLoginCredentials(LoginTestData loginDto) {
6465
@Owner("Tahanima Chowdhury")
6566
@Description(
6667
"Test that verifies user gets error message after submitting incorrect login credentials")
67-
@DataSource(testCaseId = "TC-2", filePath = "login/login.csv", clazz = LoginTestData.class)
68+
@DataSource(testCaseId = "TC-2", filePath = PATH, clazz = LoginTestData.class)
6869
void testIncorrectLoginCredentials(LoginTestData loginDto) {
6970
loginPage
7071
.navigateToUrl()
71-
.fillUsernameInTextBox(loginDto.getUserName())
72-
.fillPasswordInTextBox(loginDto.getPassword())
72+
.typeUsernameIntoTextBox(loginDto.getUserName())
73+
.typePasswordIntoTextBox(loginDto.getPassword())
7374
.clickOnLoginButton();
7475

7576
assertThat(loginPage.getErrorMessage()).hasText(loginDto.getErrorMessage());
@@ -81,11 +82,11 @@ void testIncorrectLoginCredentials(LoginTestData loginDto) {
8182
@Owner("Tahanima Chowdhury")
8283
@Description(
8384
"Test that verifies user gets error message after submitting login credentials where the username is blank")
84-
@DataSource(testCaseId = "TC-3", filePath = "login/login.csv", clazz = LoginTestData.class)
85+
@DataSource(testCaseId = "TC-3", filePath = PATH, clazz = LoginTestData.class)
8586
void testBlankUserName(LoginTestData loginDto) {
8687
loginPage
8788
.navigateToUrl()
88-
.fillPasswordInTextBox(loginDto.getPassword())
89+
.typePasswordIntoTextBox(loginDto.getPassword())
8990
.clickOnLoginButton();
9091

9192
assertThat(loginPage.getErrorMessage()).hasText(loginDto.getErrorMessage());
@@ -97,11 +98,11 @@ void testBlankUserName(LoginTestData loginDto) {
9798
@Owner("Tahanima Chowdhury")
9899
@Description(
99100
"Test that verifies user gets error message after submitting login credentials where the password is blank")
100-
@DataSource(testCaseId = "TC-4", filePath = "login/login.csv", clazz = LoginTestData.class)
101+
@DataSource(testCaseId = "TC-4", filePath = PATH, clazz = LoginTestData.class)
101102
void testBlankPassword(LoginTestData loginDto) {
102103
loginPage
103104
.navigateToUrl()
104-
.fillUsernameInTextBox(loginDto.getUserName())
105+
.typeUsernameIntoTextBox(loginDto.getUserName())
105106
.clickOnLoginButton();
106107

107108
assertThat(loginPage.getErrorMessage()).hasText(loginDto.getErrorMessage());
@@ -113,12 +114,12 @@ void testBlankPassword(LoginTestData loginDto) {
113114
@Owner("Tahanima Chowdhury")
114115
@Description(
115116
"Test that verifies user gets error message after submitting login credentials for locked out user")
116-
@DataSource(testCaseId = "TC-5", filePath = "login/login.csv", clazz = LoginTestData.class)
117+
@DataSource(testCaseId = "TC-5", filePath = PATH, clazz = LoginTestData.class)
117118
void testLockedOutUser(LoginTestData loginDto) {
118119
loginPage
119120
.navigateToUrl()
120-
.fillUsernameInTextBox(loginDto.getUserName())
121-
.fillPasswordInTextBox(loginDto.getPassword())
121+
.typeUsernameIntoTextBox(loginDto.getUserName())
122+
.typePasswordIntoTextBox(loginDto.getPassword())
122123
.clickOnLoginButton();
123124

124125
assertThat(loginPage.getErrorMessage()).hasText(loginDto.getErrorMessage());

src/test/java/io/github/tahanima/util/CsvToPOJOMapper.java

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,7 @@ public final class CsvToPOJOMapper {
1919

2020
private CsvToPOJOMapper() {}
2121

22-
private static Object[][] convertToArray(ArrayList<ArrayList<? extends BaseTestData>> data) {
23-
int noOfRows = data.size();
24-
Object[][] dataArray = new Object[noOfRows][1];
25-
26-
for (int i = 0; i < noOfRows; i++) {
27-
dataArray[i][0] = data.get(i).get(0);
28-
}
29-
30-
return dataArray;
31-
}
32-
33-
public static Object[][] map(
22+
public static Object[] map(
3423
Class<? extends BaseTestData> clazz, String csvFilePath, String testCaseId) {
3524
CsvParserSettings parserSettings = new CsvParserSettings();
3625

@@ -41,24 +30,19 @@ public static Object[][] map(
4130

4231
try (Reader inputReader =
4332
new InputStreamReader(new FileInputStream(csvFilePath), StandardCharsets.UTF_8)) {
44-
ArrayList<ArrayList<? extends BaseTestData>> testData = new ArrayList<>();
33+
ArrayList<BaseTestData> testData = new ArrayList<>();
4534

46-
for (BaseTestData data : routines.iterate(clazz, inputReader)) {
47-
if (data.getTestCaseId().equals(testCaseId)) {
48-
testData.add(
49-
new ArrayList<>() {
50-
{
51-
add(data);
52-
}
35+
routines.iterate(clazz, inputReader)
36+
.forEach(
37+
e -> {
38+
if (e.getTestCaseId().equals(testCaseId)) testData.add(e);
5339
});
54-
}
55-
}
5640

57-
return convertToArray(testData);
41+
return testData.toArray();
5842
} catch (IOException e) {
5943
e.printStackTrace();
6044
}
6145

62-
return new Object[0][0];
46+
throw new NullPointerException("Couldn't provide test data");
6347
}
6448
}

0 commit comments

Comments
 (0)