Skip to content

Commit

Permalink
Merge pull request #5236 from rldhont/backport-5223-to-release_3_8
Browse files Browse the repository at this point in the history
[Backport release_3_8] Tests e2e Playwright: Defined global getEchoRequestParams
  • Loading branch information
rldhont authored Jan 17, 2025
2 parents 68e1a26 + 5de25fe commit 959c227
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
18 changes: 18 additions & 0 deletions tests/end2end/playwright/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,21 @@ export async function reloadMap(page, check = true) {
await CatchErrors(page);
}
}

/**
* Re-send the request with additional "__echo__" param to retrieve the OGC Request search params
* @param {Page} page The page object
* @param {string} url The URL to re-send
*
* @return {Promise<URLSearchParams>}
*/
export async function getEchoRequestParams(page, url) {
// Re-send the request with additionnal echo param to retrieve the OGC Request
let echoResponse = await page.request.get(url + '&__echo__');
const originalUrl = decodeURIComponent(await echoResponse.text());
// When the request has not been logged by echo proxy
await expect(URL.canParse(originalUrl), originalUrl+' is not an URL!').toBeTruthy();
await expect(originalUrl).not.toContain('unfound')

return new URLSearchParams((new URL(originalUrl).search));
}
11 changes: 3 additions & 8 deletions tests/end2end/playwright/timemanage.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 { gotoMap, getEchoRequestParams } from './globals';

test.describe('Time Manager', () => {

Expand Down Expand Up @@ -49,12 +49,8 @@ test.describe('Time Manager', () => {
await expect(urlMapRequest).toMatch(/FILTERTOKEN/);
await expect(urlMapRequest).toContain('FILTERTOKEN='+jsonFiltertokenResponse.token);

// Re-send the request with additionnal echo param to retrieve the WMS Request
let echoGetMap = await page.request.get(urlMapRequest + '&__echo__');
const originalUrl = decodeURIComponent(await echoGetMap.text());
// When the request has not been logged by echo proxy
await expect(URL.canParse(originalUrl), originalUrl+' is not an URL!').toBeTruthy();
await expect(originalUrl).not.toContain('unfound')
// Re-send the request with additional echo param to retrieve the WMS Request search params
const urlObj = await getEchoRequestParams(page, urlMapRequest)

// expected request params
const expectedParamValue = [
Expand All @@ -65,7 +61,6 @@ test.describe('Time Manager', () => {
{ 'param': 'filter', 'expectedvalue': 'time_manager_layer: ( ( "test_date" >= \'' + timeObj.start + '\' ) AND ( "test_date" <= \'' + timeObj.end + '\' ) ) ' },
];
// Check if WMS Request params are as expected
const urlObj = new URLSearchParams((new URL(originalUrl).search));
for (let obj of expectedParamValue) {
await expect(urlObj.has(obj.param), obj.param+' not in ['+Array.from(urlObj.keys()).join(', ')+']').toBeTruthy();
await expect(urlObj.get(obj.param), obj.param+'='+obj.expectedvalue+' not in ['+urlObj.toString().split('&').join(', ')+']').toBe(obj.expectedvalue);
Expand Down

0 comments on commit 959c227

Please sign in to comment.