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

[Backport release_3_7] Tests e2e playwright : Lint tests and POM #5298

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion tests/end2end/playwright/attribute-table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ test.describe('Attribute table', () => {
await expect(project.attributeTableHtml(layerName).locator('tbody tr')).toHaveCount(7);
// mediaFile as stored in data-src attributes
const mediaFile = await project.attributeTableHtml(layerName).locator('img.data-attr-thumbnail').first().getAttribute('data-src');
expect(mediaFile).not.toBeNull
// ensure src contain "dynamic" mediaFile
await expect(project.attributeTableHtml(layerName).locator('img.data-attr-thumbnail').first()).toHaveAttribute('src', new RegExp(mediaFile));
await expect(project.attributeTableHtml(layerName).locator('img.data-attr-thumbnail').first()).toHaveAttribute('src', new RegExp(mediaFile ?? ''));
// ensure src contain getMedia and projet URL
await expect(project.attributeTableHtml(layerName).locator('img.data-attr-thumbnail').first()).toHaveAttribute('src', /getMedia\?repository=testsrepository&project=attribute_table&/);
})
Expand Down
23 changes: 17 additions & 6 deletions tests/end2end/playwright/globals.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
// @ts-check
const { expect } = require('@playwright/test');
import { Page } from '@playwright/test';

/**
* Playwright Page
* @typedef {import('@playwright/test').Page} Page
*/

/**
* Integer
* @typedef {number} int
*/

/**
* Expect no errors in the map page
* @param {Page} page The page object
* @param {boolean} checkLayerTreeView Checking that tree view contains layers
*/
async function NoErrors(page, checkLayerTreeView = true) {
// No error
await expect(page.locator('p.error-msg')).toHaveCount(0);
Expand All @@ -13,10 +27,9 @@ async function NoErrors(page, checkLayerTreeView = true) {
}

/**
* CatchErrors function
* Some checks when the map is on error
* Expect errors in the map page
* @param {Page} page The page object
* @param {int} layersInTreeView The number of layers to find in the treeview.
* @param {int} layersInTreeView The number of layers to find in the tree view.
*/
async function CatchErrors(page, layersInTreeView = 0) {
// Error
Expand All @@ -29,7 +42,6 @@ async function CatchErrors(page, layersInTreeView = 0) {
}

/**
* gotoMap function
* Helper to load a map and do some basic checks
* @param {string} url The URL of the map to load
* @param {Page} page The page object
Expand Down Expand Up @@ -67,7 +79,6 @@ export async function gotoMap(url, page, mapMustLoad = true, layersInTreeView =
}

/**
* reloadMap function
* Helper to reload a map and do some basic checks
* @param {Page} page The page object
* @param {boolean} check If some basic checks must be done.
Expand Down
12 changes: 11 additions & 1 deletion tests/end2end/playwright/pages/admin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// @ts-check

import {expect, Locator, Page} from '@playwright/test';
import { expect } from '@playwright/test';
import { BasePage } from './base';

/**
* Playwright Page
* @typedef {import('@playwright/test').Page} Page
*/

/**
* Playwright Page
* @typedef {import('@playwright/test').Locator} Locator
*/

export class AdminPage extends BasePage {
/**
* Main administrator menu
Expand Down
12 changes: 11 additions & 1 deletion tests/end2end/playwright/pages/base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
// @ts-check

import {expect, Locator, Page} from '@playwright/test';
import { expect } from '@playwright/test';

/**
* Playwright Page
* @typedef {import('@playwright/test').Page} Page
*/

/**
* Playwright Page
* @typedef {import('@playwright/test').Locator} Locator
*/

export class BasePage {
/** @type {Page} */
Expand Down
12 changes: 11 additions & 1 deletion tests/end2end/playwright/pages/project.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// @ts-check
import {expect, Locator, Page} from '@playwright/test';
import { expect } from '@playwright/test';
import { gotoMap } from '../globals';
import { BasePage } from './base';

/**
* Playwright Page
* @typedef {import('@playwright/test').Page} Page
*/

/**
* Playwright Page
* @typedef {import('@playwright/test').Locator} Locator
*/

export class ProjectPage extends BasePage {
// Metadata
/**
Expand Down
9 changes: 7 additions & 2 deletions tests/end2end/playwright/requests-metadata.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// @ts-check
import { test, expect } from '@playwright/test';

/**
* Playwright Page
* @typedef {import('@playwright/test').APIResponse} APIResponse
*/

const url = 'index.php/view/app/metadata';

/**
* Check for a JSON response about the metadata
* @param {Response} response The response object
* @param {APIResponse} response The response object
*
* @return {JSON} The JSON response
* @return {Promise<any>} The JSON response
*/
export async function checkJson(response) {
expect(response.ok()).toBeTruthy();
Expand Down
Loading