Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing temporary solution for solving logout tests in Playwright #12261

Merged
5 commits merged into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions frontend/testing/playwright/pages/LoginPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ const loginPageTexts: Record<string, string> = {
login: 'logg inn',
username: 'Brukernavn eller epost',
password: 'Passord',
// After loging out, the language on the page changes from Norwegian to English
login_after_logout: 'Sign in',
This conversation was marked as resolved.
Show resolved Hide resolved
username_after_logout: 'Username or Email Address',
password_after_logout: 'Password',
error_message_after_logout: 'Username or password is incorrect.',
};

export class LoginPage extends BasePage {
Expand All @@ -27,24 +32,27 @@ export class LoginPage extends BasePage {
await this.page.getByRole('button', { name: loginPageTexts['login'] }).click();
}

public async writeUsername(username: string): Promise<void> {
return await this.page.getByLabel(loginPageTexts['username']).fill(username);
public async writeUsername(username: string, isAfterLogout: boolean = false): Promise<void> {
const textKey = isAfterLogout ? 'username_after_logout' : 'username';
return await this.page.getByLabel(loginPageTexts[textKey]).fill(username);
}

public async writePassword(password: string): Promise<void> {
return await this.page.getByLabel(loginPageTexts['password']).fill(password);
public async writePassword(password: string, isAfterLogout: boolean = false): Promise<void> {
const textKey = isAfterLogout ? 'password_after_logout' : 'password';
return await this.page.getByLabel(loginPageTexts[textKey]).fill(password);
}

public async clickLoginButton(): Promise<void> {
return await this.page.getByRole('button', { name: loginPageTexts['login'] }).click();
public async clickLoginButton(isAfterLogout: boolean = false): Promise<void> {
const textKey = isAfterLogout ? 'login_after_logout' : 'login';
return await this.page.getByRole('button', { name: loginPageTexts[textKey] }).click();
}

public async confirmSuccessfulLogin(): Promise<void> {
await this.page.waitForURL(this.getRoute('dashboard'));
}

public async checkThatErrorMessageIsVisible(): Promise<void> {
await this.page.getByText(/ugyldig brukernavn eller passord./i).isVisible();
await this.page.getByText(loginPageTexts['error_message_after_logout']).isVisible();
}

public async addSessionToSharableStorage() {
Expand Down
1 change: 1 addition & 0 deletions frontend/testing/playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export default defineConfig<ExtendedTestOptions>({
...devices['Desktop Chrome'],
storageState: '.playwright/auth/user.json',
headless: true,
locale: process.env.CI ? 'en' : 'no', // Our solution runs Gitea page in Norwegian locally and English in dev and prod.
},
},
],
Expand Down
28 changes: 15 additions & 13 deletions frontend/testing/playwright/tests/dashboard/dashboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,8 @@ const getExtraAppName = (appName: string): string => `extra-app-${appName}`;

// Before the tests starts, we need to create the dashboard app
test.beforeAll(async ({ testAppName, request, storageState }) => {
// Create 2 apps
const firstApp = await createApp(testAppName, request, storageState as StorageState);
const secondApp = await createApp(
getExtraAppName(testAppName),
request,
storageState as StorageState,
);

expect(firstApp.ok()).toBeTruthy();
expect(secondApp.ok()).toBeTruthy();
const response = await createApp(testAppName, request, storageState as StorageState);
expect(response.ok()).toBeTruthy();
});

test.afterAll(async ({ request, testAppName }) => {
Expand Down Expand Up @@ -84,14 +76,24 @@ test('It is possible to change context and view only Testdepartementet apps', as
await dashboardPage.checkThatTTDApplicationsHeaderIsVisible();
});

test('It is possible to search an app by name', async ({ page, testAppName }) => {
test('It is possible to search an app by name', async ({
page,
testAppName,
request,
storageState,
}) => {
const dashboardPage = await setupAndVerifyDashboardPage(page, testAppName);
const testAppName2 = `${testAppName}2`;
const testAppName2 = getExtraAppName(testAppName);

// Need to wait a bit to make sure that Gitea does not crash
dashboardPage.waitForXAmountOfMilliseconds(3000);
const response = await createApp(testAppName2, request, storageState as StorageState);
expect(response.ok()).toBeTruthy();

await dashboardPage.checkThatAppIsVisible(testAppName);
await dashboardPage.checkThatAppIsVisible(testAppName2);

await dashboardPage.typeInSearchField('2');
await dashboardPage.typeInSearchField('extra');
await dashboardPage.checkThatAppIsHidden(testAppName);
await dashboardPage.checkThatAppIsVisible(testAppName2);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@ test('That it is possible to login with valid user credentials, and then log out

test('That it is not possible to login with invalid credentials', async ({
page,
locale,
}): Promise<void> => {
const loginPage = new LoginPage(page);
console.log('locale', locale);

await loginPage.goToAltinnLoginPage();
await loginPage.goToGiteaLoginPage();

await loginPage.writeUsername(process.env.PLAYWRIGHT_USER);
await loginPage.writePassword('123');
// Gitea login page is in Norwegian locally, but english in dev and prod
const isEnglish: boolean = locale === 'en';

await loginPage.clickLoginButton();
await loginPage.writeUsername(process.env.PLAYWRIGHT_USER, isEnglish);
await loginPage.writePassword('123', isEnglish);

await loginPage.clickLoginButton(isEnglish);
await loginPage.checkThatErrorMessageIsVisible();
});
Loading