Created
April 26, 2020 18:18
-
-
Save TanAlex/5c5984dfc4a2005f1908fc7f9e5218e5 to your computer and use it in GitHub Desktop.
AWS CloudWatch Synthetics Canary Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var synthetics = require('Synthetics'); | |
const log = require('SyntheticsLogger'); | |
const pageLoadBlueprint = async function () { | |
// INSERT URL here | |
const URL = "https://example.com"; | |
const username = "user@example.com"; | |
const passwd = "@#^!abcd1234" | |
let page = await synthetics.getPage(); | |
const response = await page.goto(URL, {waitUntil: 'domcontentloaded', timeout: 30000}); | |
//Wait for page to render. | |
//Increase or decrease wait time based on endpoint being monitored. | |
await page.waitFor(10000); | |
await page.type('input[name="email"][type="text"]', username) | |
await page.type('input[name="password"][placeholder="Password"]', passwd) | |
try { | |
await synthetics.takeScreenshot("click", 'result'); | |
} catch(ex) { | |
synthetics.addExecutionError('Unable to capture screenshot.', ex); | |
} | |
await page.click('span[class="sign-in-form__title"]') | |
await page.waitFor(10000); | |
await synthetics.takeScreenshot('loaded', 'loaded'); | |
let pageTitle = await page.title(); | |
log.info('Page title: ' + pageTitle); | |
if (response.status() !== 200) { | |
throw "Failed to load page!"; | |
} | |
}; | |
exports.handler = async () => { | |
return await pageLoadBlueprint(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment