diff --git a/puppeteer/click.js b/puppeteer/click.js index 941a85f..e5e1e21 100644 --- a/puppeteer/click.js +++ b/puppeteer/click.js @@ -14,6 +14,7 @@ 'use scrict' import puppeteer from 'puppeteer-core'; +import assert from 'assert'; // ws address const browserAddress = process.env.BROWSER_ADDRESS ? process.env.BROWSER_ADDRESS : 'ws://127.0.0.1:9222'; @@ -35,6 +36,29 @@ await page.goto('http://127.0.0.1:1234', {waitUntil: 'load'}); await page.click("a[href='campfire-commerce/']"); +assert.strictEqual(page.url(), 'http://127.0.0.1:1234/campfire-commerce/', 'The new page URL is not as expected.'); + +// ensure product's details is loaded +const price = parseFloat(await page.evaluate(() => { return document.querySelector('#product-price').textContent.substring(1); })); +if (price != 244.99) { + console.log(res); + throw new Error("invalid product price"); +} + +// ensure reviews are loaded +const reviews = await page.evaluate(() => { + return Array.from(document.querySelectorAll('#product-reviews > div')).map(row => { + return { + name: row.querySelector('h4').textContent, + text: row.querySelector('p').textContent, + }; + }); +}); +if (reviews.length != 3) { + console.log(res); + throw new Error("invalid reviews length"); +} + await page.close(); await context.close(); await browser.disconnect(); diff --git a/runner/main.go b/runner/main.go index 829f3a0..107e6c0 100644 --- a/runner/main.go +++ b/runner/main.go @@ -100,6 +100,7 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer) error { {Bin: "node", Args: []string{"puppeteer/cdp.js"}, Env: []string{"RUNS=10"}}, {Bin: "node", Args: []string{"puppeteer/dump.js"}, Env: []string{"URL=http://127.0.0.1:1234/campfire-commerce/"}}, {Bin: "node", Args: []string{"puppeteer/links.js"}, Env: []string{"URL=http://127.0.0.1:1234/campfire-commerce/"}}, + {Bin: "node", Args: []string{"puppeteer/click.js"}}, {Bin: "node", Args: []string{"playwright/connect.js"}}, {Bin: "node", Args: []string{"playwright/cdp.js"}, Env: []string{"RUNS=2"}}, {Bin: "go", Args: []string{"run", "fetch/main.go", "http://127.0.0.1:1234/"}, Dir: "chromedp"},