From 204c575de9ab5992048076a66be576385b04b939 Mon Sep 17 00:00:00 2001 From: Brandon Shien <44730413+bshien@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:12:14 -0700 Subject: [PATCH] Added click UI tests to Canary URL monitoring (#42) Signed-off-by: Brandon Shien --- .../canary/nodejs/node_modules/urlMonitor.js | 20 +++++++++++++++---- infrastructure/test/monitoring-stack.test.ts | 3 +-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/infrastructure/canary/nodejs/node_modules/urlMonitor.js b/infrastructure/canary/nodejs/node_modules/urlMonitor.js index 607a6fa..7ca0921 100644 --- a/infrastructure/canary/nodejs/node_modules/urlMonitor.js +++ b/infrastructure/canary/nodejs/node_modules/urlMonitor.js @@ -68,7 +68,18 @@ const loadUrl = async function (page, url, takeScreenshot) { networkidle2: Navigation is successful when the page has no more then 2 network requests for half a second. domcontentloaded: It's fired as soon as the page DOM has been loaded, without waiting for resources to finish loading. If needed add explicit wait with await new Promise(r => setTimeout(r, milliseconds)) */ - const response = await page.goto(url, { waitUntil: ['domcontentloaded'], timeout: 30000}); + + const response = await page.goto(url, { waitUntil: ['load', 'networkidle0'], timeout: 30000}); + + await page.click('[aria-label="Closes this modal window"]'); + await new Promise(r => setTimeout(r, 3000)); + await page.click('button[aria-label="Toggle primary navigation"]'); + await new Promise(r => setTimeout(r, 3000)); + await Promise.all([ + page.waitForNavigation(), + page.click('div[data-test-subj="collapsibleNavGroup-opensearchDashboards"] span[title="Dashboards"]'), + ]); + if (response) { domcontentloaded = true; const status = response.status(); @@ -80,6 +91,7 @@ const loadUrl = async function (page, url, takeScreenshot) { if (response.status() < 200 || response.status() > 299) { throw new Error(`Failed to load url: ${sanitizedUrl} ${response.status()} ${response.statusText()}`); } + } else { const logNoResponseString = `No response returned for url: ${sanitizedUrl}`; log.error(logNoResponseString); @@ -87,9 +99,9 @@ const loadUrl = async function (page, url, takeScreenshot) { } }); - // Wait for 15 seconds to let page load fully before taking screenshot. + // Wait for 5 seconds to let page load fully before taking screenshot. if (domcontentloaded && takeScreenshot) { - await new Promise(r => setTimeout(r, 15000)); + await new Promise(r => setTimeout(r, 5000)); await synthetics.takeScreenshot(stepName, 'loaded'); } @@ -99,4 +111,4 @@ const loadUrl = async function (page, url, takeScreenshot) { exports.handler = async () => { return await loadBlueprint(); -}; \ No newline at end of file +}; diff --git a/infrastructure/test/monitoring-stack.test.ts b/infrastructure/test/monitoring-stack.test.ts index 5c99213..d609ba1 100644 --- a/infrastructure/test/monitoring-stack.test.ts +++ b/infrastructure/test/monitoring-stack.test.ts @@ -164,8 +164,7 @@ test('Monitoring Stack Test', () => { "Handler": "urlMonitor.handler", "S3Bucket": { "Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}" - }, - "S3Key": "3add60a2b13650e2ad0c97ef8b24082c52ea91e59b8b8bac89874c602a6b908d.zip" + } }, "ExecutionRoleArn": { "Fn::GetAtt": [