Skip to content

Commit

Permalink
Tests e2e Playwright: defined getAuthStorageStatePath globasl method
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Feb 6, 2025
1 parent 5297343 commit 79cc2c3
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 36 deletions.
22 changes: 4 additions & 18 deletions tests/end2end/playwright/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
import { test as setup } from '@playwright/test';
// @ts-ignore
import path from 'path';
import { getAuthStorageStatePath } from './globals';
import { Page } from '@playwright/test';

/**
* The file directory path
* @var string
* @see https://nodejs.org/docs/latest-v15.x/api/esm.html#esm_no_filename_or_dirname
* @see https://stackoverflow.com/questions/64963450/dirname-is-not-defined
* @see https://stackoverflow.com/questions/8817423/why-is-dirname-not-defined-in-node-repl
* @example
* import { fileURLToPath } from 'url';
* import { dirname } from 'path';
* const __filename = fileURLToPath(import.meta.url);
* const __dirname = dirname(__filename);
*/
const __dirname = path.resolve(path.dirname(''));

/**
* Performs the authentication steps
* @param {Page} page The page object
Expand All @@ -40,13 +26,13 @@ export async function auth_using_login(page: Page, login: string, password: stri
}

setup('authenticate as user_in_group_a', async ({ page }) => {
await auth_using_login(page, 'user_in_group_a', 'admin', path.join(__dirname, './.auth/user_in_group_a.json'));
await auth_using_login(page, 'user_in_group_a', 'admin', getAuthStorageStatePath('user_in_group_a'));
});

setup('authenticate as admin', async ({ page }) => {
await auth_using_login(page, 'admin', 'admin', path.join(__dirname, './.auth/admin.json'));
await auth_using_login(page, 'admin', 'admin', getAuthStorageStatePath('admin'));
});

setup('authenticate as publisher', async ({ page }) => {
await auth_using_login(page, 'publisher', 'admin', path.join(__dirname, './.auth/publisher.json'));
await auth_using_login(page, 'publisher', 'admin', getAuthStorageStatePath('publisher'));
});
3 changes: 2 additions & 1 deletion tests/end2end/playwright/bad-repository.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// @ts-check
import { test, expect } from '@playwright/test';
import { getAuthStorageStatePath } from './globals';
import {AdminPage} from "./pages/admin";

test.describe('Bad repository in conf', () => {

test.use({ storageState: 'playwright/.auth/admin.json' });
test.use({ storageState: getAuthStorageStatePath('admin') });

test.beforeEach(async ({ page }) => {
// Go to repos page
Expand Down
4 changes: 2 additions & 2 deletions tests/end2end/playwright/custom-javascript-api.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @ts-check
import { test, expect } from '@playwright/test';
import { gotoMap } from './globals';
import { getAuthStorageStatePath, gotoMap } from './globals';

test.describe('Maps management', () => {

test.use({ storageState: 'playwright/.auth/admin.json' });
test.use({ storageState: getAuthStorageStatePath('admin') });

test('OpenLayers', {
tag: '@flaky',
Expand Down
6 changes: 3 additions & 3 deletions tests/end2end/playwright/filter-layer-by-user.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
import { test, expect } from '@playwright/test';
import { gotoMap } from './globals';
import { getAuthStorageStatePath, gotoMap } from './globals';

test.describe('Filter layer data by user - not connected', () => {

Expand Down Expand Up @@ -176,7 +176,7 @@ test.describe('Filter layer data by user - not connected', () => {
});

test.describe('Filter layer data by user - user in group a', () => {
test.use({ storageState: 'playwright/.auth/user_in_group_a.json' });
test.use({ storageState: getAuthStorageStatePath('user_in_group_a') });

test.beforeEach(async ({ page }) => {
const url = '/index.php/view/map/?repository=testsrepository&project=filter_layer_by_user';
Expand Down Expand Up @@ -372,7 +372,7 @@ test.describe('Filter layer data by user - user in group a', () => {
});

test.describe('Filter layer data by user - admin', () => {
test.use({ storageState: 'playwright/.auth/admin.json' });
test.use({ storageState: getAuthStorageStatePath('admin') });

test.beforeEach(async ({ page }) => {
const url = '/index.php/view/map/?repository=testsrepository&project=filter_layer_by_user';
Expand Down
25 changes: 25 additions & 0 deletions tests/end2end/playwright/globals.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @ts-check
import { expect } from '@playwright/test';
import { URLSearchParams } from 'url';
import { fileURLToPath } from 'url';
import * as path from 'path';

/**
* Playwright Page
Expand All @@ -12,6 +14,29 @@ import { URLSearchParams } from 'url';
* @typedef {number} int
*/

/**
* Get the auth storage state path
* @param {string} name The file name without extension
* @returns {string} The path to auth storage state path
*/
export function getAuthStorageStatePath(name) {
const __filename = fileURLToPath(import.meta.url);
/**
* The file directory path
* @var string
* @see https://nodejs.org/docs/latest-v15.x/api/esm.html#esm_no_filename_or_dirname
* @see https://stackoverflow.com/questions/64963450/dirname-is-not-defined
* @see https://stackoverflow.com/questions/8817423/why-is-dirname-not-defined-in-node-repl
* @example
* import { fileURLToPath } from 'url';
* import { dirname } from 'path';
* const __filename = fileURLToPath(import.meta.url);
* const __dirname = dirname(__filename);
*/
const __dirname = path.dirname(__filename);
return path.join(__dirname, './.auth/' + name + '.json')
}

/**
* Expect no errors in the map page
* @param {Page} page The page object
Expand Down
3 changes: 2 additions & 1 deletion tests/end2end/playwright/landing_page_config.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check
import { test, expect } from '@playwright/test';
import { getAuthStorageStatePath } from './globals';
import {HomePage} from "./pages/homepage";
import {AdminPage} from "./pages/admin";

Expand All @@ -9,7 +10,7 @@ test.describe('Landing page content', {

test('Fill form & check content', async ({ browser }) => {

const adminContext = await browser.newContext({ storageState: 'playwright/.auth/admin.json' });
const adminContext = await browser.newContext({ storageState: getAuthStorageStatePath('admin') });
const page = await adminContext.newPage();
const adminPage = new AdminPage(page);
// unanthenticated context
Expand Down
4 changes: 2 additions & 2 deletions tests/end2end/playwright/map-projects-switcher.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @ts-check
import { test, expect } from '@playwright/test';
import { gotoMap } from './globals';
import { getAuthStorageStatePath, gotoMap } from './globals';

test.describe('Map projects switcher', () => {

const locale = 'en-US';

test.use({ storageState: 'playwright/.auth/admin.json' });
test.use({ storageState: getAuthStorageStatePath('admin') });

test.beforeEach(async ({ page }) => {
// Go to Lizmap configuration
Expand Down
3 changes: 2 additions & 1 deletion tests/end2end/playwright/maps-management.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// @ts-check
import { test, expect } from '@playwright/test';
import { getAuthStorageStatePath } from './globals';
import {AdminPage} from "./pages/admin";

test.describe('Maps management', () => {

test.use({ storageState: 'playwright/.auth/admin.json' });
test.use({ storageState: getAuthStorageStatePath('admin') });

test.beforeEach(async ({ page }) => {
// Go to admin.php
Expand Down
6 changes: 3 additions & 3 deletions tests/end2end/playwright/print.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
import { test, expect } from '@playwright/test';
import { gotoMap, expectParametersToContain } from './globals';
import { gotoMap, expectParametersToContain, getAuthStorageStatePath } from './globals';

test.describe('Print', () => {

Expand Down Expand Up @@ -354,7 +354,7 @@ test.describe('Print in popup', () => {
});

test.describe('Print - user in group a', () => {
test.use({ storageState: 'playwright/.auth/user_in_group_a.json' });
test.use({ storageState: getAuthStorageStatePath('user_in_group_a') });

test.beforeEach(async ({ page }) => {
const url = '/index.php/view/map/?repository=testsrepository&project=print';
Expand Down Expand Up @@ -393,7 +393,7 @@ test.describe('Print - user in group a', () => {
});

test.describe('Print - admin', () => {
test.use({ storageState: 'playwright/.auth/admin.json' });
test.use({ storageState: getAuthStorageStatePath('admin') });

test.beforeEach(async ({ page }) => {
const url = '/index.php/view/map/?repository=testsrepository&project=print';
Expand Down
3 changes: 2 additions & 1 deletion tests/end2end/playwright/project_load_warning.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// @ts-check
import { test, expect } from '@playwright/test';
import { getAuthStorageStatePath } from './globals';
import { ProjectPage } from './pages/project';

test.describe('Project warnings in CFG as admin',
{
tag: ['@readonly'],
}, () => {

test.use({ storageState: 'playwright/.auth/admin.json' });
test.use({ storageState: getAuthStorageStatePath('admin') });

test('Visit map with a warning', async ({ page }) => {
const project = new ProjectPage(page, 'project_cfg_warnings');
Expand Down
7 changes: 4 additions & 3 deletions tests/end2end/playwright/requests-metadata.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check
import { test, expect } from '@playwright/test';
import { getAuthStorageStatePath } from './globals';

/**
* Playwright Page
Expand Down Expand Up @@ -71,7 +72,7 @@ test.describe('Connected from context, as a normal user',
},
() => {

test.use({ storageState: 'playwright/.auth/user_in_group_a.json' });
test.use({ storageState: getAuthStorageStatePath('user_in_group_a') });

test('Request metadata', async ({ request }) => {
const response = await request.get(url, {});
Expand All @@ -87,7 +88,7 @@ test.describe('Connected from context, as a publisher',
},
() => {

test.use({ storageState: 'playwright/.auth/publisher.json' });
test.use({ storageState: getAuthStorageStatePath('publisher') });

test('Checking JSON metadata content as a publisher', async ({ request }) => {
const response = await request.get(url, {});
Expand Down Expand Up @@ -156,7 +157,7 @@ test.describe('Request JSON metadata as admin, connected from context',
},
() => {

test.use({ storageState: 'playwright/.auth/admin.json' });
test.use({ storageState: getAuthStorageStatePath('admin') });

test('Checking JSON metadata content as admin', async ({ request }) => {
const response = await request.get(url, {});
Expand Down
3 changes: 2 additions & 1 deletion tests/end2end/playwright/server-information.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// @ts-check
import { test, expect } from '@playwright/test';
import { getAuthStorageStatePath } from './globals';
import {AdminPage} from "./pages/admin";

test.describe('Server information', () => {

test.use({ storageState: 'playwright/.auth/admin.json' });
test.use({ storageState: getAuthStorageStatePath('admin') });

test.beforeEach(async ({ page }) => {
// Go to admin.php
Expand Down

0 comments on commit 79cc2c3

Please sign in to comment.