Skip to content

Commit 75dc520

Browse files
authored
Merge pull request #37 from lightpanda-io/Enable-puppeteer-click.js
Enable puppeteer click.js
2 parents c913075 + d7ebc13 commit 75dc520

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

puppeteer/click.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
'use scrict'
1515

1616
import puppeteer from 'puppeteer-core';
17+
import assert from 'assert';
1718

1819
// ws address
1920
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'});
3536

3637
await page.click("a[href='campfire-commerce/']");
3738

39+
assert.strictEqual(page.url(), 'http://127.0.0.1:1234/campfire-commerce/', 'The new page URL is not as expected.');
40+
41+
// ensure product's details is loaded
42+
const price = parseFloat(await page.evaluate(() => { return document.querySelector('#product-price').textContent.substring(1); }));
43+
if (price != 244.99) {
44+
console.log(res);
45+
throw new Error("invalid product price");
46+
}
47+
48+
// ensure reviews are loaded
49+
const reviews = await page.evaluate(() => {
50+
return Array.from(document.querySelectorAll('#product-reviews > div')).map(row => {
51+
return {
52+
name: row.querySelector('h4').textContent,
53+
text: row.querySelector('p').textContent,
54+
};
55+
});
56+
});
57+
if (reviews.length != 3) {
58+
console.log(res);
59+
throw new Error("invalid reviews length");
60+
}
61+
3862
await page.close();
3963
await context.close();
4064
await browser.disconnect();

runner/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer) error {
100100
{Bin: "node", Args: []string{"puppeteer/cdp.js"}, Env: []string{"RUNS=10"}},
101101
{Bin: "node", Args: []string{"puppeteer/dump.js"}, Env: []string{"URL=http://127.0.0.1:1234/campfire-commerce/"}},
102102
{Bin: "node", Args: []string{"puppeteer/links.js"}, Env: []string{"URL=http://127.0.0.1:1234/campfire-commerce/"}},
103+
{Bin: "node", Args: []string{"puppeteer/click.js"}},
103104
{Bin: "node", Args: []string{"playwright/connect.js"}},
104105
{Bin: "node", Args: []string{"playwright/cdp.js"}, Env: []string{"RUNS=2"}},
105106
{Bin: "go", Args: []string{"run", "fetch/main.go", "http://127.0.0.1:1234/"}, Dir: "chromedp"},

0 commit comments

Comments
 (0)