Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions public/dynamic_scripts/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<body>
<script>
const el = document.createElement('script');
el.src = 'script.js';
document.getElementsByTagName('body')[0].appendChild(el);
</script>
<div id=product></div>
</body>
3 changes: 3 additions & 0 deletions public/dynamic_scripts/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(() => {
document.getElementById('product').innerText = 'Keemun';
})();
5 changes: 5 additions & 0 deletions public/location_write/index1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE html>
<body>
<div id=page>1</div>
<script>location.assign('index2.html')</script>
</body>
5 changes: 5 additions & 0 deletions public/location_write/index2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE html>
<body>
<div id=page>2</div>
<script>document.location = `http://${location.host}/location_write/index3.html`</script>
</body>
5 changes: 5 additions & 0 deletions public/location_write/index3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE html>
<body>
<div id=page>3</div>
<script>top.location = '../location_write/index4.html'</script>
</body>
4 changes: 4 additions & 0 deletions public/location_write/index4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<body>
<div id=page>4</div>
</body>
45 changes: 45 additions & 0 deletions puppeteer/dynamic_scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2023-2024 Lightpanda (Selecy SAS)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
'use scrict'

import puppeteer from 'puppeteer-core';

const browserAddress = process.env.BROWSER_ADDRESS ? process.env.BROWSER_ADDRESS : 'ws://127.0.0.1:9222';
const baseURL = process.env.URL ? process.env.URL : 'http://127.0.0.1:1234'

// use browserWSEndpoint to pass the Lightpanda's CDP server address.
const browser = await puppeteer.connect({
browserWSEndpoint: browserAddress,
});

// The rest of your script remains the same.
const context = await browser.createBrowserContext();
const page = await context.newPage();

await page.goto(baseURL + '/dynamic_scripts/index.html');;

await page.waitForFunction(() => {
const products = document.querySelector('#product');
return products.textContent.length > 0;
}, {timeout: 1000});

const product = await page.evaluate(() => { return document.querySelector('#product').textContent; });
if (product !== 'Keemun') {
console.log(res);
throw new Error("invalid product");
}

await page.close();
await context.close();
await browser.disconnect();
39 changes: 39 additions & 0 deletions puppeteer/location_write.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2023-2024 Lightpanda (Selecy SAS)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
'use scrict'

import puppeteer from 'puppeteer-core';

const browserAddress = process.env.BROWSER_ADDRESS ? process.env.BROWSER_ADDRESS : 'ws://127.0.0.1:9222';
const baseURL = process.env.URL ? process.env.URL : 'http://127.0.0.1:1234'

// use browserWSEndpoint to pass the Lightpanda's CDP server address.
const browser = await puppeteer.connect({
browserWSEndpoint: browserAddress,
});

// The rest of your script remains the same.
const context = await browser.createBrowserContext();
const page = await context.newPage();

await page.goto(baseURL + '/location_write/index1.html');;
await page.waitForFunction(() => {
const p = document.querySelector('#page');
return p.textContent == '4';

}, {timeout: 2000});

await page.close();
await context.close();
await browser.disconnect();
2 changes: 2 additions & 0 deletions runner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer) error {
{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{"puppeteer/wait_for_network.js"}},
{Bin: "node", Args: []string{"puppeteer/dynamic_scripts.js"}},
{Bin: "node", Args: []string{"puppeteer/location_write.js"}},
{Bin: "node", Args: []string{"playwright/connect.js"}},
{Bin: "node", Args: []string{"playwright/cdp.js"}, Env: []string{"RUNS=2"}},
{Bin: "node", Args: []string{"playwright/click.js"}},
Expand Down