Synthetic Monitoring
Simulating end users through synthetic monitoring and how generative AI can help
Puppeteer
Example: Synthetic Monitoring for User Journeys
Prompt
Write a Puppeteer script in Node.js that simulates a user journey on a bicycle rental app, including searching for a mountain bike, adding it to the cart, filling in the {checkout_form_form}, and submitting the order. Make sure to validate that the cart updates and the order confirmation is displayed.Response
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('http://localhost:3000/bicycle-rental-app');
// Simulate user journey: Search for a bicycle, view details, and add to cart
await page.type('input[name=search]', 'mountain bike');
await page.click('button[type=submit]');
await page.waitForSelector('.bicycle-list-item');
await page.click('.bicycle-list-item');
await page.waitForSelector('.bicycle-details');
await page.click('button.add-to-cart');
// Check that the cart has been updated
const cartItems = await page.$eval('.cart-items', (el) => el.textContent);
expect(cartItems).toContain('1');
// Continue user journey: Proceed to checkout and fill in the form
await page.click('button.proceed-to-checkout');
await page.waitForSelector('.checkout-form');
await page.type('input[name=name]', 'John Doe');
await page.type('input[name=email]', '[email protected]');
await page.type('input[name=address]', '123 Main St');
await page.type('input[name=city]', 'New York');
await page.type('input[name=state]', 'NY');
await page.type('input[name=zip]', '10001');
await page.click('button[type=submit]');
// Verify that the order has been submitted successfully
await page.waitForSelector('.order-confirmation');
const orderConfirmation = await page.$eval('.order-confirmation', (el) => el.textContent);
expect(orderConfirmation).toContain('Thank you for your order!');
await browser.close();
})();Last updated