Skip to content

Commit 97464e0

Browse files
authored
Merge pull request #5223 from rldhont/tests-e2e-playwright-getEchoRequestParams
Tests e2e Playwright: Defined global getEchoRequestParams
2 parents 0c9a6fa + 4a8e14d commit 97464e0

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

tests/end2end/playwright/form-filter.spec.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
22
import { test, expect } from '@playwright/test';
3-
import { gotoMap } from './globals';
3+
import { gotoMap, getEchoRequestParams } from './globals';
44

55
test.describe('Form filter', () => {
66
test.beforeEach(async ({ page }) => {
@@ -30,10 +30,8 @@ test.describe('Form filter', () => {
3030
await expect(page.locator(countFeature)).toHaveText('1');
3131

3232
let getMapRequest = await getMapPromise;
33-
// Re-send the request with additionnal echo param to retrieve the WMS Request
34-
let echoGetMap = await page.request.get(getMapRequest.url() + '&__echo__');
35-
let originalUrl = decodeURIComponent(await echoGetMap.text());
36-
let urlObj = new URLSearchParams((new URL(originalUrl).search));
33+
// Re-send the request with additional echo param to retrieve the WMS Request search params
34+
let urlObj = await getEchoRequestParams(page, getMapRequest.url())
3735

3836
expect(urlObj.get('filter')).toBe('form_filter_layer:"id" IN ( 2 ) ');
3937

@@ -52,10 +50,8 @@ test.describe('Form filter', () => {
5250

5351
getMapRequest = await getMapPromise;
5452

55-
// Re-send the request with additionnal echo param to retrieve the WMS Request
56-
echoGetMap = await page.request.get(getMapRequest.url() + '&__echo__');
57-
originalUrl = decodeURIComponent(await echoGetMap.text());
58-
urlObj = new URLSearchParams((new URL(originalUrl).search));
53+
// Re-send the request with additional echo param to retrieve the WMS Request search params
54+
urlObj = await getEchoRequestParams(page, getMapRequest.url())
5955

6056
expect(urlObj.get('filter')).toBeNull();
6157

@@ -101,6 +97,5 @@ test.describe('Form filter', () => {
10197
await page.locator('#liz-filter-field-textautocomplete').fill('mon');
10298
await expect(page.locator('#ui-id-2 .ui-menu-item')).toHaveCount(1);
10399
await expect(page.locator('#ui-id-2 .ui-menu-item div')).toHaveText('monuments');
104-
});
100+
});
105101
});
106-

tests/end2end/playwright/globals.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,21 @@ export async function reloadMap(page, check = true) {
9696
await CatchErrors(page);
9797
}
9898
}
99+
100+
/**
101+
* Re-send the request with additional "__echo__" param to retrieve the OGC Request search params
102+
* @param {Page} page The page object
103+
* @param {string} url The URL to re-send
104+
*
105+
* @return {Promise<URLSearchParams>}
106+
*/
107+
export async function getEchoRequestParams(page, url) {
108+
// Re-send the request with additionnal echo param to retrieve the OGC Request
109+
let echoResponse = await page.request.get(url + '&__echo__');
110+
const originalUrl = decodeURIComponent(await echoResponse.text());
111+
// When the request has not been logged by echo proxy
112+
await expect(URL.canParse(originalUrl), originalUrl+' is not an URL!').toBeTruthy();
113+
await expect(originalUrl).not.toContain('unfound')
114+
115+
return new URLSearchParams((new URL(originalUrl).search));
116+
}

tests/end2end/playwright/timemanage.spec.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-check
22
import { test, expect } from '@playwright/test';
3-
import { gotoMap } from './globals';
3+
import { gotoMap, getEchoRequestParams } from './globals';
44

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

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

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

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

0 commit comments

Comments
 (0)