Skip to content

Commit 0b24a3c

Browse files
authored
Merge pull request #43 from lightpanda-io/puppeterr_wait_for_network
add wait_for_network puppeteer tests to runner
2 parents dd5463c + 7822850 commit 0b24a3c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

puppeteer/wait_for_network.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2023-2024 Lightpanda (Selecy SAS)
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
'use scrict'
15+
16+
import puppeteer from 'puppeteer-core';
17+
18+
const browserAddress = process.env.BROWSER_ADDRESS ? process.env.BROWSER_ADDRESS : 'ws://127.0.0.1:9222';
19+
const url = process.env.URL ? process.env.URL : 'https://httpbin.io/xhr/get';
20+
21+
// use browserWSEndpoint to pass the Lightpanda's CDP server address.
22+
const browser = await puppeteer.connect({
23+
browserWSEndpoint: browserAddress,
24+
});
25+
26+
// The rest of your script remains the same.
27+
const context = await browser.createBrowserContext();
28+
const page = await context.newPage();
29+
30+
await page.goto(url);
31+
await page.waitForNetworkIdle();
32+
33+
const xhr_content = await page.evaluate(() => { return document.querySelector('#response').textContent; });
34+
const parsed = JSON.parse(xhr_content);
35+
if (parsed.headers['User-Agent'] != 'Lightpanda/1.0') {
36+
console.log(xhr_content);
37+
throw new Error("invalid XHR content");
38+
}
39+
40+
await page.close();
41+
await context.close();
42+
await browser.disconnect();

runner/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer) error {
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/"}},
103103
{Bin: "node", Args: []string{"puppeteer/click.js"}},
104+
{Bin: "node", Args: []string{"puppeteer/wait_for_network.js"}},
104105
{Bin: "node", Args: []string{"playwright/connect.js"}},
105106
{Bin: "node", Args: []string{"playwright/cdp.js"}, Env: []string{"RUNS=2"}},
106107
{Bin: "node", Args: []string{"playwright/click.js"}},

0 commit comments

Comments
 (0)