diff --git a/frontend/testing/playwright/enum/Language.ts b/frontend/testing/playwright/enum/Language.ts new file mode 100644 index 00000000000..177fa93809c --- /dev/null +++ b/frontend/testing/playwright/enum/Language.ts @@ -0,0 +1,3 @@ +export enum Language { + NORWEGIAN = 'Norsk', +} diff --git a/frontend/testing/playwright/pages/LoginPage.ts b/frontend/testing/playwright/pages/LoginPage.ts index 53f069e4b66..a570bf58a99 100644 --- a/frontend/testing/playwright/pages/LoginPage.ts +++ b/frontend/testing/playwright/pages/LoginPage.ts @@ -1,16 +1,14 @@ import type { Page } from '@playwright/test'; import { BasePage } from '../helpers/BasePage'; +import { Language } from '../enum/Language'; // Since this page is a Razor page, it's not using the nb/en.json files, which are used in the frontend. const loginPageTexts: Record = { 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', - username_after_logout: 'Username or Email Address', - password_after_logout: 'Password', - error_message_after_logout: 'Username or password is incorrect.', + error_message: 'Ugyldig brukernavn eller passord.', + links: 'Links', }; export class LoginPage extends BasePage { @@ -32,19 +30,16 @@ export class LoginPage extends BasePage { await this.page.getByRole('button', { name: loginPageTexts['login'] }).click(); } - public async writeUsername(username: string, isAfterLogout: boolean = false): Promise { - const textKey = isAfterLogout ? 'username_after_logout' : 'username'; - return await this.page.getByLabel(loginPageTexts[textKey]).fill(username); + public async writeUsername(username: string): Promise { + return await this.page.getByLabel(loginPageTexts['username']).fill(username); } - public async writePassword(password: string, isAfterLogout: boolean = false): Promise { - const textKey = isAfterLogout ? 'password_after_logout' : 'password'; - return await this.page.getByLabel(loginPageTexts[textKey]).fill(password); + public async writePassword(password: string): Promise { + return await this.page.getByLabel(loginPageTexts['password']).fill(password); } - public async clickLoginButton(isAfterLogout: boolean = false): Promise { - const textKey = isAfterLogout ? 'login_after_logout' : 'login'; - return await this.page.getByRole('button', { name: loginPageTexts[textKey] }).click(); + public async clickLoginButton(): Promise { + return await this.page.getByRole('button', { name: loginPageTexts['login'] }).click(); } public async confirmSuccessfulLogin(): Promise { @@ -52,7 +47,22 @@ export class LoginPage extends BasePage { } public async checkThatErrorMessageIsVisible(): Promise { - await this.page.getByText(loginPageTexts['error_message_after_logout']).isVisible(); + await this.page.getByText(loginPageTexts['error_message']).isVisible(); + } + + public async getLanguage(): Promise { + return await this.page + .getByRole('group', { name: loginPageTexts['links'] }) + .getByRole('menu') + .innerText(); + } + + public async clickOnLanguageMenu(): Promise { + await this.page.getByRole('group', { name: loginPageTexts['links'] }).getByRole('menu').click(); + } + + public async clickOnNorwegianLanguageOption(): Promise { + await this.page.getByRole('menuitem', { name: Language.NORWEGIAN }).click(); } public async addSessionToSharableStorage() { diff --git a/frontend/testing/playwright/playwright.config.ts b/frontend/testing/playwright/playwright.config.ts index 35c27753771..50f66775889 100644 --- a/frontend/testing/playwright/playwright.config.ts +++ b/frontend/testing/playwright/playwright.config.ts @@ -110,13 +110,13 @@ export default defineConfig({ // Add ALL other test names here to make sure that the log out test is the last test to be executed dependencies: [ TestNames.SETUP, - TestNames.CREATE_APP_ONLY, + /*TestNames.CREATE_APP_ONLY, TestNames.DATA_MODEL, TestNames.DASHBOARD, TestNames.MAIN_NAVIGATION_BETWEEN_SUB_APPS, TestNames.GIT_SYNC, TestNames.UI_EDITOR, - TestNames.SETTINGS_MODAL, + TestNames.SETTINGS_MODAL,*/ ], testDir: './tests/logout-and-invalid-login-only/', testMatch: '*.spec.ts', @@ -124,7 +124,6 @@ export default defineConfig({ ...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. }, }, ], diff --git a/frontend/testing/playwright/tests/logout-and-invalid-login-only/logout-and-invalid-login-only.spec.ts b/frontend/testing/playwright/tests/logout-and-invalid-login-only/logout-and-invalid-login-only.spec.ts index a2d071d1d74..0256474aabb 100644 --- a/frontend/testing/playwright/tests/logout-and-invalid-login-only/logout-and-invalid-login-only.spec.ts +++ b/frontend/testing/playwright/tests/logout-and-invalid-login-only/logout-and-invalid-login-only.spec.ts @@ -1,6 +1,8 @@ import { test } from '../../extenders/testExtend'; import { LoginPage } from '../../pages/LoginPage'; import { DashboardPage } from '../../pages/DashboardPage'; +import { expect } from '@playwright/test'; +import { Language } from '../../enum/Language'; // This line must be there to ensure that the tests do not run in parallell, and // that the before all call is being executed before we start the tests @@ -26,20 +28,27 @@ 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 => { const loginPage = new LoginPage(page); - console.log('locale', locale); await loginPage.goToAltinnLoginPage(); await loginPage.goToGiteaLoginPage(); - // Gitea login page is in Norwegian locally, but english in dev and prod - const isEnglish: boolean = locale === 'en'; + const lang = await loginPage.getLanguage(); - await loginPage.writeUsername(process.env.PLAYWRIGHT_USER, isEnglish); - await loginPage.writePassword('123', isEnglish); + if (lang !== Language.NORWEGIAN) { + await loginPage.clickOnLanguageMenu(); + await loginPage.clickOnNorwegianLanguageOption(); - await loginPage.clickLoginButton(isEnglish); + const langAfterchange = await loginPage.getLanguage(); + expect(langAfterchange).toBe(Language.NORWEGIAN); + } else { + expect(lang).toBe(Language.NORWEGIAN); + } + + await loginPage.writeUsername(process.env.PLAYWRIGHT_USER); + await loginPage.writePassword('123'); + + await loginPage.clickLoginButton(); await loginPage.checkThatErrorMessageIsVisible(); });