Skip to content

Commit 0c6885f

Browse files
committed
playwright click
1 parent 75dc520 commit 0c6885f

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

playwright/click.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
15+
// Import the Chromium browser into our scraper.
16+
import { chromium } from 'playwright';
17+
18+
// browserAddress
19+
const browserAddress = process.env.BROWSER_ADDRESS ? process.env.BROWSER_ADDRESS : 'ws://127.0.0.1:9222';
20+
21+
// web serveur url
22+
const baseURL = process.env.BASE_URL ? process.env.BASE_URL : 'http://127.0.0.1:1234';
23+
24+
// measure general time.
25+
const gstart = process.hrtime.bigint();
26+
// store all run durations
27+
let metrics = [];
28+
29+
// Connect to an existing browser
30+
console.log("Connection to browser on " + browserAddress);
31+
const browser = await chromium.connectOverCDP({
32+
endpointURL: browserAddress,
33+
logger: {
34+
isEnabled: (name, severity) => true,
35+
log: (name, severity, message, args) => console.log(`${name} ${message}`)
36+
}
37+
});
38+
39+
const context = await browser.newContext({
40+
baseURL: baseURL,
41+
});
42+
43+
const page = await context.newPage();
44+
45+
await page.locator("a[href='campfire-commerce/']").waitFor();
46+
await page.locator("a[href='campfire-commerce/']").click();
47+
48+
if (page.url() !== 'http://127.0.0.1:1234/campfire-commerce/') {
49+
throw new Error('The new page URL is not as expected.');
50+
}
51+
52+
await page.close();
53+
await context.close();
54+
55+
// Turn off the browser to clean up after ourselves.
56+
await browser.close();

runner/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer) error {
103103
{Bin: "node", Args: []string{"puppeteer/click.js"}},
104104
{Bin: "node", Args: []string{"playwright/connect.js"}},
105105
{Bin: "node", Args: []string{"playwright/cdp.js"}, Env: []string{"RUNS=2"}},
106+
{Bin: "node", Args: []string{"playwright/click.js"}},
106107
{Bin: "go", Args: []string{"run", "fetch/main.go", "http://127.0.0.1:1234/"}, Dir: "chromedp"},
107108
{Bin: "go", Args: []string{"run", "links/main.go", "http://127.0.0.1:1234/"}, Dir: "chromedp"},
108109
} {

0 commit comments

Comments
 (0)