Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(synthetics): node playwright 1.0 and python selenium 4.1 runtime #32245

Open
wants to merge 38 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
bf3d3d4
add runtime version
badmintoncryer Nov 22, 2024
e5a2786
Merge remote-tracking branch 'origin/main' into synthetics-runtime
badmintoncryer Nov 28, 2024
79046e1
update integ test
badmintoncryer Nov 28, 2024
2e5a4ca
update integ test
badmintoncryer Nov 29, 2024
2856673
update unit test
badmintoncryer Nov 29, 2024
8ef293d
Merge branch 'main' into synthetics-runtime
badmintoncryer Nov 29, 2024
788848c
fix unit test
badmintoncryer Nov 29, 2024
bc19f3c
Merge remote-tracking branch 'origin/main' into synthetics-runtime
badmintoncryer Dec 21, 2024
a0af52a
tracing config
badmintoncryer Dec 21, 2024
6cd56c0
Merge remote-tracking branch 'origin/main' into synthetics-runtime
badmintoncryer Dec 21, 2024
b998d6a
update integ
badmintoncryer Dec 21, 2024
461a4ef
update test
badmintoncryer Dec 21, 2024
ed5c9ac
backward compatibility
badmintoncryer Dec 22, 2024
bba5689
Merge branch 'main' into synthetics-runtime
badmintoncryer Dec 24, 2024
52cdadc
update s3encryption integ
badmintoncryer Dec 27, 2024
d275e24
update runtimr description
badmintoncryer Dec 29, 2024
b31f0cb
Merge branch 'main' into synthetics-runtime
badmintoncryer Dec 29, 2024
18314a5
updat ereadme
badmintoncryer Dec 29, 2024
41bab80
refactor
badmintoncryer Dec 31, 2024
c71eb38
Merge branch 'main' into synthetics-runtime
badmintoncryer Dec 31, 2024
501b150
fix build error
badmintoncryer Jan 1, 2025
79a7766
Merge branch 'main' into synthetics-runtime
badmintoncryer Jan 1, 2025
c37bd6e
fix unit test
badmintoncryer Jan 2, 2025
91152e5
remove unused import
badmintoncryer Jan 2, 2025
9c863c1
update validation
badmintoncryer Jan 2, 2025
2e58dc5
Merge branch 'main' into synthetics-runtime
badmintoncryer Jan 2, 2025
ab93688
Merge branch 'main' into synthetics-runtime
badmintoncryer Jan 3, 2025
cf20be2
Update packages/aws-cdk-lib/aws-synthetics/lib/code.ts
badmintoncryer Jan 4, 2025
fdd294d
refactor validation
badmintoncryer Jan 4, 2025
81fc1c3
update comments
badmintoncryer Jan 4, 2025
a18fa6e
Merge branch 'main' into synthetics-runtime
badmintoncryer Jan 4, 2025
1e8e434
Merge branch 'main' into synthetics-runtime
badmintoncryer Jan 4, 2025
16256e8
Merge branch 'main' into synthetics-runtime
badmintoncryer Jan 6, 2025
30063d4
Merge branch 'main' into synthetics-runtime
badmintoncryer Jan 7, 2025
707472a
update
badmintoncryer Jan 10, 2025
14ea05f
Merge branch 'main' into synthetics-runtime
badmintoncryer Jan 10, 2025
d99e091
update comments
badmintoncryer Jan 10, 2025
33c557d
update
badmintoncryer Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { URL } from 'url';
import { synthetics } from '@amzn/synthetics-playwright';

const loadBlueprints = async function () {
const urls = [process.env.URL];

const browser = await synthetics.launch();
const browserContext = await browser.newContext();
let page = await synthetics.newPage(browserContext);

for (const url of urls) {
await loadUrl(page, url);
}

// Ensure browser is closed
await synthetics.close();
};

// Reset the page in-between
const resetPage = async function(page) {
try {
// Set page.goto timeout to 30 seconds, adjust as needed
// See https://playwright.dev/docs/api/class-page for page.goto options
await page.goto('about:blank', { waitUntil: 'load', timeout: 30000 });
} catch (e) {
console.error('Unable to open a blank page. ', e);
}
};

const loadUrl = async function (page, url) {
let stepName = null;
let domcontentloaded = false;

try {
stepName = new URL(url).hostname;
} catch (e) {
const errorString = `Error parsing url: ${url}. ${e}`;
log.error(errorString);
/* If we fail to parse the URL, don't emit a metric with a stepName based on it.
It may not be a legal CloudWatch metric dimension name and we may not have an alarms
setup on the malformed URL stepName. Instead, fail this step which will
show up in the logs and will fail the overall canary and alarm on the overall canary
success rate.
*/
throw e;
};

await synthetics.executeStep(stepName, async function () {
try {
/* You can customize the wait condition here.
'domcontentloaded' - consider operation to be finished when the DOMContentLoaded event is fired.
'load' - consider operation to be finished when the load event is fired.
'networkidle' - DISCOURAGED consider operation to be finished when there are no network connections for at least 500 ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
'commit' - consider operation to be finished when network response is received and the document started loading.

Set page.goto timeout to 30 seconds, adjust as needed
See https://playwright.dev/docs/api/class-page for page.goto options
*/
const response = await page.goto(url, { waitUntil: 'load', timeout: 30000 });
if (response) {
domcontentloaded = true;
const status = response.status();
console.log(`Response status: ${status}`);

// If the response status code is not a 2xx success code
if (status < 200 || status > 299) {
console.error(`Failed to load url: ${url}, status code: ${status}`);
throw new Error('Failed');
}
} else {
console.error(`No response returned for url: ${url}`);
throw new Error(logNoResponseString);
}
} catch (e) {
const errorString = `Error navigating to url: ${url}. ${e}`;
console.error(errorString);
throw e;
}
});

// Reset page
await resetPage(page);
};

export const handler = async (event, context) => {
return await loadBlueprints();
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { URL } from 'url';
import { synthetics } from '@amzn/synthetics-playwright';

const loadBlueprints = async function () {
const urls = [process.env.URL];

const browser = await synthetics.launch();
const browserContext = await browser.newContext();
let page = await synthetics.newPage(browserContext);

for (const url of urls) {
await loadUrl(page, url);
}

// Ensure browser is closed
await synthetics.close();
};

// Reset the page in-between
const resetPage = async function(page) {
try {
// Set page.goto timeout to 30 seconds, adjust as needed
// See https://playwright.dev/docs/api/class-page for page.goto options
await page.goto('about:blank', { waitUntil: 'load', timeout: 30000 });
} catch (e) {
console.error('Unable to open a blank page. ', e);
}
};

const loadUrl = async function (page, url) {
let stepName = null;
let domcontentloaded = false;

try {
stepName = new URL(url).hostname;
} catch (e) {
const errorString = `Error parsing url: ${url}. ${e}`;
log.error(errorString);
/* If we fail to parse the URL, don't emit a metric with a stepName based on it.
It may not be a legal CloudWatch metric dimension name and we may not have an alarms
setup on the malformed URL stepName. Instead, fail this step which will
show up in the logs and will fail the overall canary and alarm on the overall canary
success rate.
*/
throw e;
};

await synthetics.executeStep(stepName, async function () {
try {
/* You can customize the wait condition here.
'domcontentloaded' - consider operation to be finished when the DOMContentLoaded event is fired.
'load' - consider operation to be finished when the load event is fired.
'networkidle' - DISCOURAGED consider operation to be finished when there are no network connections for at least 500 ms. Don't use this method for testing, rely on web assertions to assess readiness instead.
'commit' - consider operation to be finished when network response is received and the document started loading.

Set page.goto timeout to 30 seconds, adjust as needed
See https://playwright.dev/docs/api/class-page for page.goto options
*/
const response = await page.goto(url, { waitUntil: 'load', timeout: 30000 });
if (response) {
domcontentloaded = true;
const status = response.status();
console.log(`Response status: ${status}`);

// If the response status code is not a 2xx success code
if (status < 200 || status > 299) {
console.error(`Failed to load url: ${url}, status code: ${status}`);
throw new Error('Failed');
}
} else {
console.error(`No response returned for url: ${url}`);
throw new Error(logNoResponseString);
}
} catch (e) {
const errorString = `Error navigating to url: ${url}. ${e}`;
console.error(errorString);
throw e;
}
});

// Reset page
await resetPage(page);
};

export const handler = async (event, context) => {
return await loadBlueprints();
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading