From e6bbaecc5344e799300711da80e4bb5d209868fa Mon Sep 17 00:00:00 2001 From: sjorsdonkers <72333389+sjorsdonkers@users.noreply.github.com> Date: Tue, 6 May 2025 12:32:02 +0200 Subject: [PATCH 1/3] Enable puppeteer click.js --- runner/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/runner/main.go b/runner/main.go index 829f3a0..b8a6d97 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"}, Env: []string{"URL=http://127.0.0.1:1234/campfire-commerce/"}}, {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"}, From 63dc1791b671629496becf75511fcd4acf32e12a Mon Sep 17 00:00:00 2001 From: sjorsdonkers <72333389+sjorsdonkers@users.noreply.github.com> Date: Wed, 7 May 2025 13:27:04 +0200 Subject: [PATCH 2/3] assert page navigated --- puppeteer/click.js | 3 +++ runner/main.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/puppeteer/click.js b/puppeteer/click.js index 941a85f..ce88979 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,8 @@ 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.'); + await page.close(); await context.close(); await browser.disconnect(); diff --git a/runner/main.go b/runner/main.go index b8a6d97..107e6c0 100644 --- a/runner/main.go +++ b/runner/main.go @@ -100,7 +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"}, 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"}, From d7ebc13d164ab0344633d3f33b23feca799f2026 Mon Sep 17 00:00:00 2001 From: Pierre Tachoire Date: Thu, 8 May 2025 15:18:12 +0200 Subject: [PATCH 3/3] puppeteer/click.js: add more tests --- puppeteer/click.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/puppeteer/click.js b/puppeteer/click.js index ce88979..e5e1e21 100644 --- a/puppeteer/click.js +++ b/puppeteer/click.js @@ -38,6 +38,27 @@ 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();