Added script

This commit is contained in:
alexjanousekGSA
2024-09-23 13:07:24 -04:00
parent df22530fa4
commit 70c9801f1d
17 changed files with 50 additions and 24 deletions

View File

@@ -1,14 +1,10 @@
const { urls } = require('./urls');
const { urls, baseUrl } = require('./urls');
// Helper function to automatically generate scenarios from the URLs
const createScenariosFromUrls = (urlsObj, delay = 1000) => {
return Object.keys(urlsObj).map((label) => ({
const createScenariosFromUrls = (urls, delay = 1000) => {
return Object.keys(urls).map((label) => ({
label,
url: urlsObj[label],
hideSelectors: [],
removeSelectors: [],
url: urls[label],
selectors: ['document'],
selectorExpansion: true,
misMatchThreshold: 0.1,
requireSameDimensions: true,
delay,
@@ -16,7 +12,7 @@ const createScenariosFromUrls = (urlsObj, delay = 1000) => {
};
module.exports = {
id: 'my_project_tests',
id: 'backstop_test',
viewports: [
{
label: 'desktop',
@@ -24,7 +20,18 @@ module.exports = {
height: 768,
},
],
scenarios: createScenariosFromUrls(urls),
scenarios: [
...createScenariosFromUrls(urls),
// example page with script
{
label: 'Get Started Page - Highlight Trial Mode',
url: `${baseUrl}/using-notify/get-started`,
selectors: ['document'],
misMatchThreshold: 0.1,
requireSameDimensions: true,
onBeforeScript: 'puppeteer/onBefore.js',
},
],
paths: {
bitmaps_reference: 'backstop_data/bitmaps_reference',
bitmaps_test: 'backstop_data/bitmaps_test',
@@ -38,5 +45,5 @@ module.exports = {
timeout: 30000,
},
report: ['browser'],
debug: true,
debug: false,
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

View File

@@ -0,0 +1,18 @@
module.exports = async (page, scenario) => {
await page.goto(scenario.url, { waitUntil: 'networkidle2' });
console.log('Page loaded.');
// Count the number of items in the side navigation and log their text
const navItems = await page.$$eval('nav ul li.usa-sidenav__item a', (items) =>
items.map((item) => item.textContent.trim())
);
console.log(`Found ${navItems.length} navigation items:`);
navItems.forEach((itemText, index) => {
console.log(`${index + 1}: ${itemText}`);
});
// Wait a moment for the logging to complete
await new Promise((resolve) => setTimeout(resolve, 1000));
};

27
urls.js
View File

@@ -1,19 +1,19 @@
const baseUrl = "http://localhost:6012";
const baseUrl = 'http://localhost:6012';
// List of routes with paths and labels
const sublinks = [
{ label: "Homepage", path: "/" },
{ label: "Accounts", path: "/accounts" },
{ label: "Add Service", path: "/add-service" },
{ label: "Get Started", path: "/using-notify/get-started" },
{ label: "Trial Mode", path: "/using-notify/trial-mode" },
{ label: "Pricing", path: "/using-notify/pricing" },
{ label: "Delivery Status", path: "/using-notify/delivery-status" },
{ label: "Guidance", path: "/using-notify/guidance" },
{ label: "Features", path: "/features" },
{ label: "Roadmaps", path: "/features/roadmaps" },
{ label: "Security", path: "/features/security" },
{ label: "Support", path: "/support" },
{ label: 'Homepage', path: '/' },
{ label: 'Accounts', path: '/accounts' },
{ label: 'Add Service', path: '/add-service' },
{ label: 'Get Started', path: '/using-notify/get-started' },
{ label: 'Trial Mode', path: '/using-notify/trial-mode' },
{ label: 'Pricing', path: '/using-notify/pricing' },
{ label: 'Delivery Status', path: '/using-notify/delivery-status' },
{ label: 'Guidance', path: '/using-notify/guidance' },
{ label: 'Features', path: '/features' },
{ label: 'Roadmaps', path: '/features/roadmaps' },
{ label: 'Security', path: '/features/security' },
{ label: 'Support', path: '/support' },
// Add more links here as needed
];
@@ -26,5 +26,6 @@ const constructUrls = (base, sublinks) =>
}, {});
module.exports = {
baseUrl,
urls: constructUrls(baseUrl, sublinks),
};