Skip to content

Commit 8d2d301

Browse files
author
GuustMetz
committed
separate the click from the waitForFunction check
1 parent 4f26cf1 commit 8d2d301

3 files changed

Lines changed: 27 additions & 23 deletions

File tree

test/public/defaults.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -275,25 +275,16 @@ exports.waitForNavigation = waitForNavigation;
275275
* @returns {Promise} Whether the element was clickable or not.
276276
*/
277277
module.exports.pressElement = async (page, selector, jsClick = false) => {
278-
await page.waitForFunction(
279-
(sel, isJsClick) => {
280-
const element = document.querySelector(sel);
281-
282-
if (!element) {
283-
return false;
284-
}
278+
await page.waitForFunction( (sel) => !!document.querySelector(sel), {}, selector);
285279

286-
if (isJsClick) {
280+
if (jsClick) {
281+
await page.evaluate((sel) => {
282+
const element = document.querySelector(sel);
283+
if (element) {
287284
element.click();
288285
}
289-
290-
return true;
291-
},
292-
{},
293-
selector, jsClick
294-
);
295-
296-
if (!jsClick) {
286+
}, selector);
287+
} else {
297288
await page.click(selector);
298289
}
299290
};

test/public/runs/runsPerLhcPeriod.overview.test.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ module.exports = () => {
7575
after(async () => {
7676
[page, browser] = await defaultAfter(page, browser);
7777
});
78+
const EXPORT_RUNS_TRIGGER_SELECTOR = '#export-data-trigger';
79+
80+
const waitForExportButton = async () =>
81+
await page.waitForFunction((selector) => {
82+
const button = document.querySelector(selector);
83+
return button && !button.disabled;
84+
}, {}, EXPORT_RUNS_TRIGGER_SELECTOR);
7885

7986
it('loads the page successfully', async () => {
8087
const response = await goToPage(page, 'runs-per-lhc-period', { queryParameters: { lhcPeriodId: 1 } });
@@ -204,7 +211,6 @@ module.exports = () => {
204211
await waitForTableLength(page, 4);
205212
});
206213

207-
const EXPORT_RUNS_TRIGGER_SELECTOR = '#export-data-trigger';
208214

209215
it('should successfully export all runs per lhc Period', async () => {
210216
await page.evaluate(() => {
@@ -213,7 +219,7 @@ module.exports = () => {
213219
});
214220

215221
const targetFileName = 'data.json';
216-
222+
await waitForExportButton();
217223
// First export
218224
await pressElement(page, EXPORT_RUNS_TRIGGER_SELECTOR, true);
219225
await page.waitForSelector('select.form-control', { timeout: 200 });
@@ -286,9 +292,9 @@ module.exports = () => {
286292
await navigateToRunsPerLhcPeriod(page, 1, 4);
287293

288294
const targetFileName = 'data.csv';
289-
295+
await waitForExportButton();
290296
// Export
291-
await pressElement(page, '#export-data-trigger');
297+
await pressElement(page, EXPORT_RUNS_TRIGGER_SELECTOR);
292298
await page.waitForSelector('#export-data-modal');
293299
await page.waitForSelector('#send:disabled');
294300
await page.waitForSelector('.form-control');

test/public/runs/runsPerSimulationPass.overview.test.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ module.exports = () => {
7474
[page, browser] = await defaultAfter(page, browser);
7575
});
7676

77+
const EXPORT_RUNS_TRIGGER_SELECTOR = '#export-data-trigger';
78+
79+
const waitForExportButton = async () =>
80+
await page.waitForFunction((selector) => {
81+
const button = document.querySelector(selector);
82+
return button && !button.disabled;
83+
}, {}, EXPORT_RUNS_TRIGGER_SELECTOR);
84+
7785
it('loads the page successfully', async () => {
7886
const response = await goToPage(page, 'runs-per-simulation-pass', { queryParameters: { simulationPassId: 2 } });
7987

@@ -235,11 +243,10 @@ module.exports = () => {
235243

236244
it('should successfully export runs', async () => {
237245
await navigateToRunsPerSimulationPass(page, 1, 2, 3);
238-
const EXPORT_RUNS_TRIGGER_SELECTOR = '#export-data-trigger';
239-
240246
const targetFileName = 'data.json';
241247

242248
// Export
249+
await waitForExportButton();
243250
await pressElement(page, EXPORT_RUNS_TRIGGER_SELECTOR);
244251
await page.waitForSelector('#export-data-modal');
245252
await page.waitForSelector('#send:disabled');
@@ -270,7 +277,7 @@ module.exports = () => {
270277
const targetFileName = 'data.csv';
271278

272279
// Export
273-
await pressElement(page, '#export-data-trigger');
280+
await pressElement(page, EXPORT_RUNS_TRIGGER_SELECTOR);
274281
await page.waitForSelector('#export-data-modal');
275282
await page.waitForSelector('#send:disabled');
276283
await page.waitForSelector('.form-control');

0 commit comments

Comments
 (0)