Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 112befb

Browse files
feat: add testdata (#13)
* feat: add testdata * feat: setup GitHub Actions for testdata * fix: update README
1 parent 3649413 commit 112befb

File tree

6 files changed

+150
-8
lines changed

6 files changed

+150
-8
lines changed

.github/workflows/test.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Test
2+
on:
3+
workflow_dispatch:
4+
push:
5+
tags:
6+
- "v*.*.*"
7+
pull_request:
8+
branches:
9+
- "main"
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
defaults:
14+
run:
15+
working-directory: testdata
16+
steps:
17+
- uses: actions/checkout@v3
18+
- run: docker run --rm $(docker build -q .)

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
# Instruction
44

5-
To use this base image, please specify `DriverDirectory` to `/root/.cache`.
6-
Also, we are recommend to specify `SkipInstallBrowsers` to `true`.
5+
To use this base image, please specify followng arguments of `BrowserTypeLaunchOptions`.
76

87
```go
9-
pw, err := playwright.Run(&playwright.RunOptions{
10-
DriverDirectory: "/root/.cache",
11-
SkipInstallBrowsers: true,
8+
pw, _ := playwright.Run()
9+
10+
browser, _ := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
11+
Args: []string{
12+
"--disable-dev-shm-usage",
13+
"--single-process",
14+
"--no-sandbox",
15+
},
1216
})
13-
if err != nil {
14-
return nil, fmt.Errorf("failed to start playwright: %w", err)
15-
}
1617
```

testdata/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM golang:1.20 as builder
2+
3+
WORKDIR /go/src/app
4+
5+
COPY . .
6+
7+
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o pw ./main.go
8+
9+
FROM ghcr.io/mokmok-dev/playwright-go:latest as runner
10+
11+
WORKDIR /
12+
13+
COPY --from=builder /go/src/app/pw /pw
14+
15+
ENTRYPOINT ["/pw"]

testdata/go.mod

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module github.com/mokmok-dev/playwright-go/testdata
2+
3+
go 1.20
4+
5+
require (
6+
github.com/playwright-community/playwright-go v0.2000.1
7+
github.com/volatiletech/null/v8 v8.1.2
8+
)
9+
10+
require (
11+
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
12+
github.com/friendsofgo/errors v0.9.2 // indirect
13+
github.com/go-stack/stack v1.8.1 // indirect
14+
github.com/gofrs/uuid v3.2.0+incompatible // indirect
15+
github.com/volatiletech/inflect v0.0.1 // indirect
16+
github.com/volatiletech/randomize v0.0.1 // indirect
17+
github.com/volatiletech/strmangle v0.0.1 // indirect
18+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 // indirect
19+
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
20+
)

testdata/go.sum

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ=
2+
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk=
3+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
5+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6+
github.com/friendsofgo/errors v0.9.2 h1:X6NYxef4efCBdwI7BgS820zFaN7Cphrmb+Pljdzjtgk=
7+
github.com/friendsofgo/errors v0.9.2/go.mod h1:yCvFW5AkDIL9qn7suHVLiI/gH228n7PC4Pn44IGoTOI=
8+
github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw=
9+
github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4=
10+
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
11+
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
12+
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
13+
github.com/h2non/filetype v1.1.1/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
14+
github.com/playwright-community/playwright-go v0.2000.1 h1:2JViSHpJQ/UL/PO1Gg6gXV5IcXAAsoBJ3KG9L3wKXto=
15+
github.com/playwright-community/playwright-go v0.2000.1/go.mod h1:1y9cM9b9dVHnuRWzED1KLM7FtbwTJC8ibDjI6MNqewU=
16+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
17+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
18+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
19+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
20+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
21+
github.com/volatiletech/inflect v0.0.1 h1:2a6FcMQyhmPZcLa+uet3VJ8gLn/9svWhJxJYwvE8KsU=
22+
github.com/volatiletech/inflect v0.0.1/go.mod h1:IBti31tG6phkHitLlr5j7shC5SOo//x0AjDzaJU1PLA=
23+
github.com/volatiletech/null/v8 v8.1.2 h1:kiTiX1PpwvuugKwfvUNX/SU/5A2KGZMXfGD0DUHdKEI=
24+
github.com/volatiletech/null/v8 v8.1.2/go.mod h1:98DbwNoKEpRrYtGjWFctievIfm4n4MxG0A6EBUcoS5g=
25+
github.com/volatiletech/randomize v0.0.1 h1:eE5yajattWqTB2/eN8df4dw+8jwAzBtbdo5sbWC4nMk=
26+
github.com/volatiletech/randomize v0.0.1/go.mod h1:GN3U0QYqfZ9FOJ67bzax1cqZ5q2xuj2mXrXBjWaRTlY=
27+
github.com/volatiletech/strmangle v0.0.1 h1:UKQoHmY6be/R3tSvD2nQYrH41k43OJkidwEiC74KIzk=
28+
github.com/volatiletech/strmangle v0.0.1/go.mod h1:F6RA6IkB5vq0yTG4GQ0UsbbRcl3ni9P76i+JrTBKFFg=
29+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=
30+
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
31+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
32+
gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI=
33+
gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
34+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
35+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

testdata/main.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
playwright "github.com/playwright-community/playwright-go"
7+
)
8+
9+
const url = "https://playwright.dev/"
10+
11+
func main() {
12+
pw, err := playwright.Run()
13+
if err != nil {
14+
panic(err)
15+
}
16+
17+
browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
18+
Args: []string{
19+
"--disable-dev-shm-usage",
20+
"--single-process",
21+
"--no-sandbox",
22+
},
23+
})
24+
if err != nil {
25+
panic(err)
26+
}
27+
28+
bCtx, err := browser.NewContext()
29+
if err != nil {
30+
panic(err)
31+
}
32+
33+
page, err := bCtx.NewPage()
34+
if err != nil {
35+
panic(err)
36+
}
37+
38+
if _, err := page.Goto(url); err != nil {
39+
panic(err)
40+
}
41+
42+
elm, err := page.Locator("header > div > h1 > span")
43+
if err != nil {
44+
panic(err)
45+
}
46+
47+
txt, err := elm.InnerText()
48+
if err != nil {
49+
panic(err)
50+
}
51+
52+
fmt.Println(txt)
53+
}

0 commit comments

Comments
 (0)