Skip to content

Commit 850c63e

Browse files
committed
added fix for the failed tests
1 parent 4af01d5 commit 850c63e

3 files changed

Lines changed: 40 additions & 23 deletions

File tree

fixtures/LoginData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const loginData = {
1212
location: "Inpatient Ward"
1313
},
1414
errorMessages: {
15-
invalidCredentials: "Invalid username or password. Invalid username/password. Please try again. try again.",
15+
invalidCredentials: "Invalid username/password. Please try again",
1616
locationRequired: "You must choose a location!"
1717
},
1818
sessionLocations: [

pages/LoginPage.ts

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,60 @@ export class LoginPage {
1818
this.usernameInput = page.locator('input#username');
1919
this.passwordInput = page.locator('input#password');
2020
this.sessionLocationSelect = page.locator('ul#sessionLocation.select');
21-
this.loginButton = page.locator('button#loginButton');
21+
this.loginButton = page.locator('input#loginButton.btn.confirm');
2222
this.errorMessage = page.locator('.alert.alert-danger');
2323
this.errorMessageSessionLocationSelect = page.locator('#sessionLocationError');
2424
}
2525

26+
2627
async navigate() {
2728
await this.page.goto(this.baseUrl);
29+
await this.page.waitForLoadState('domcontentloaded');
2830
await expect(this.page).toHaveTitle(this.expectedTitle);
2931
}
32+
3033
async login(username: string, password: string, location: string) {
31-
await this.usernameInput.fill(username);
32-
await this.passwordInput.fill(password);
33-
await this.sessionLocationSelect.selectOption(location);
34-
await this.loginButton.click();
34+
await this.usernameInput.fill(username);
35+
await this.passwordInput.fill(password);
36+
//await this.page.locator(`ul#sessionLocation.select >> text=${location}`).click();
37+
if (location) {
38+
await this.page.locator(`ul#sessionLocation.select >> text=${location}`).click();
3539
}
40+
await this.loginButton.click();
41+
}
3642

3743
async invalidLogin(username: string, password: string, location: string) {
38-
await this.usernameInput.fill(username);
39-
await this.passwordInput.fill(password);
40-
await this.sessionLocationSelect.selectOption(location);
41-
await this.loginButton.click();
44+
await this.usernameInput.fill(username);
45+
await this.passwordInput.fill(password);
46+
//await this.page.locator(`ul#sessionLocation.select >> text=${location}`).click();
47+
if (location) {
48+
await this.page.locator(`ul#sessionLocation.select >> text=${location}`).click();
4249
}
50+
await this.loginButton.click();
51+
}
52+
53+
async loginWithoutLocation(username: string, password: string) {
54+
await this.usernameInput.fill(username);
55+
await this.passwordInput.fill(password);
56+
await this.loginButton.click();
57+
}
4358

4459
async assertErrorMessage(expectedMessage: string) {
45-
await expect(this.errorMessage).toHaveText(expectedMessage);
60+
await expect(this.errorMessage).toContainText(expectedMessage);
4661
}
4762

4863
async assertSessionLocationError(expectedMessage: string) {
49-
await expect(this.errorMessageSessionLocationSelect).toHaveText(expectedMessage);
64+
await expect(this.errorMessageSessionLocationSelect).toContainText(expectedMessage);
5065
}
66+
5167
async verifySessionLocations(expectedLocations: string[]) {
52-
const options = this.sessionLocationSelect.locator('option');
53-
const optionCount = await options.count();
54-
let actualLocations: string[] = [];
55-
for (let i = 0; i < optionCount; i++) {
56-
actualLocations.push(await options.nth(i).innerText());
57-
}
58-
expect(actualLocations).toEqual(expectedLocations);
59-
}
60-
}
68+
const options = this.sessionLocationSelect.locator('li');
69+
const optionCount = await options.count();
70+
let actualLocations: string[] = [];
71+
for (let i = 0; i < optionCount; i++) {
72+
actualLocations.push((await options.nth(i).innerText()).trim());
73+
}
74+
expect(actualLocations.sort()).toEqual(expectedLocations.sort());
75+
}
76+
77+
}

tests/LoginTest.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ test.describe('Login Tests', () => {
3131
await loginPage.assertErrorMessage(errorMessages.invalidCredentials);
3232
});
3333
test('Login without selecting session location', async () => {
34-
await loginPage.login(validUser.username, validUser.password, "");
35-
await loginPage.errorMessage.isVisible();
34+
await loginPage.loginWithoutLocation(validUser.username, validUser.password);
35+
await loginPage.errorMessageSessionLocationSelect.isVisible();
3636
await loginPage.assertSessionLocationError(errorMessages.locationRequired);
3737
});
3838

0 commit comments

Comments
 (0)