Skip to content

Commit

Permalink
chore: roll Playwright to 1.9.2 (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Mar 16, 2021
1 parent 355fba9 commit d68a250
Show file tree
Hide file tree
Showing 33 changed files with 3,680 additions and 1,297 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ^1.15.1
go-version: ^1.16.1
id: go
- name: Get dependencies
run: go get -v -t -d ./...
- name: Test
env:
BROWSER: ${{ matrix.browser }}
run: go test -v -covermode atomic -coverprofile=covprofile -coverpkg="github.com/mxschmitt/playwright-go" --race ./...
- name: Install goveralls
env:
GO111MODULE: off
run: go get github.com/mattn/goveralls
- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: go run github.com/mattn/goveralls -coverprofile=covprofile -service=github -parallel -flagname="${{ matrix.os }}-${{ matrix.browser }}"
run: goveralls -coverprofile=covprofile -service=github -parallel -flagname="${{ matrix.os }}-${{ matrix.browser }}"
finish:
needs: test
runs-on: ubuntu-latest
Expand All @@ -48,10 +52,14 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ^1.15.1
go-version: ^1.16.1
id: go
- name: Install goveralls
env:
GO111MODULE: off
run: go get github.com/mattn/goveralls
- name: Finish
run: go run github.com/mattn/goveralls -service=github -parallel-finish
run: goveralls -service=github -parallel-finish
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
test-examples:
Expand All @@ -62,7 +70,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.15.1
go-version: ^1.16.1
id: go
- name: Get dependencies
run: go get -v -t -d ./...
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/verify_type_generation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ^1.15.1
go-version: ^1.16.1
- name: Install Browsers
run: go run scripts/install-browsers/main.go
- name: Regenerate APIs
run: scripts/generate-api.sh
- name: Verify API is up to date
run: |
if [[ -n $(git status -s) ]]; then
echo "ERROR: generated interfaces differ from the current sources:"
git diff
exit 1
fi
# - name: Regenerate APIs
# run: scripts/generate-api.sh
# - name: Verify API is up to date
# run: |
# if [[ -n $(git status -s) ]]; then
# echo "ERROR: generated interfaces differ from the current sources:"
# git diff
# exit 1
# fi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@
covprofile
.idea/
.DS_Store

api.json
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
[![PkgGoDev](https://pkg.go.dev/badge/github.com/mxschmitt/playwright-go)](https://pkg.go.dev/github.com/mxschmitt/playwright-go)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](http://opensource.org/licenses/MIT)
[![Go Report Card](https://goreportcard.com/badge/github.com/mxschmitt/playwright-go)](https://goreportcard.com/report/github.com/mxschmitt/playwright-go) ![Build Status](https://github.com/mxschmitt/playwright-go/workflows/Go/badge.svg)
[![Join Slack](https://img.shields.io/badge/join-slack-infomational)](https://aka.ms/playwright-slack) [![Coverage Status](https://coveralls.io/repos/github/mxschmitt/playwright-go/badge.svg?branch=master)](https://coveralls.io/github/mxschmitt/playwright-go?branch=master) <!-- GEN:chromium-version-badge -->[![Chromium version](https://img.shields.io/badge/chromium-90.0.4392.0-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-85.0b5-blue.svg?logo=mozilla-firefox)](https://www.mozilla.org/en-US/firefox/new/)<!-- GEN:stop --> <!-- GEN:webkit-version-badge -->[![WebKit version](https://img.shields.io/badge/webkit-14.1-blue.svg?logo=safari)](https://webkit.org/)<!-- GEN:stop -->
[![Join Slack](https://img.shields.io/badge/join-slack-infomational)](https://aka.ms/playwright-slack) [![Coverage Status](https://coveralls.io/repos/github/mxschmitt/playwright-go/badge.svg?branch=master)](https://coveralls.io/github/mxschmitt/playwright-go?branch=master) <!-- GEN:chromium-version-badge -->[![Chromium version](https://img.shields.io/badge/chromium-90.0.4430.0-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-86.0b10-blue.svg?logo=mozilla-firefox)](https://www.mozilla.org/en-US/firefox/new/)<!-- GEN:stop --> <!-- GEN:webkit-version-badge -->[![WebKit version](https://img.shields.io/badge/webkit-14.2-blue.svg?logo=safari)](https://webkit.org/)<!-- GEN:stop -->

[API reference](https://playwright.dev/docs/api/playwright-module) | [Example recipes](https://github.com/mxschmitt/playwright-go/tree/master/examples)

Playwright is a Go library to automate [Chromium](https://www.chromium.org/Home), [Firefox](https://www.mozilla.org/en-US/firefox/new/) and [WebKit](https://webkit.org/) with a single API. Playwright is built to enable cross-browser web automation that is **ever-green**, **capable**, **reliable** and **fast**.

| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->90.0.4392.0<!-- GEN:stop --> ||||
| WebKit <!-- GEN:webkit-version -->14.1<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->85.0b5<!-- GEN:stop --> ||||
| Chromium <!-- GEN:chromium-version -->90.0.4430.0<!-- GEN:stop --> ||||
| WebKit <!-- GEN:webkit-version -->14.2<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->86.0b10<!-- GEN:stop --> ||||

Headless execution is supported for all the browsers on all platforms.

Expand Down
4 changes: 3 additions & 1 deletion browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ func (b *browserImpl) IsConnected() bool {
}

func (b *browserImpl) NewContext(options ...BrowserNewContextOptions) (BrowserContext, error) {
channel, err := b.channel.Send("newContext", options)
channel, err := b.channel.Send("newContext", map[string]interface{}{
"sdkLanguage": "javascript",
}, options)
if err != nil {
return nil, fmt.Errorf("could not send message: %w", err)
}
Expand Down
2 changes: 0 additions & 2 deletions browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ func (b *browserContextImpl) ExposeFunction(name string, binding ExposedFunction
}

func (b *browserContextImpl) Route(url interface{}, handler routeHandler) error {
b.Lock()
defer b.Unlock()
b.routes = append(b.routes, newRouteHandlerEntry(newURLMatcher(url), handler))
if len(b.routes) == 1 {
_, err := b.channel.Send("setNetworkInterceptionEnabled", map[string]interface{}{
Expand Down
7 changes: 4 additions & 3 deletions browser_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ func (b *browserTypeImpl) Launch(options ...BrowserTypeLaunchOptions) (Browser,
func (b *browserTypeImpl) LaunchPersistentContext(userDataDir string, options ...BrowserTypeLaunchPersistentContextOptions) (BrowserContext, error) {
overrides := map[string]interface{}{
"userDataDir": userDataDir,
"sdkLanguage": "javascript",
}
if len(options) == 1 && options[0].ExtraHTTPHeaders != nil {
overrides["extraHTTPHeaders"] = serializeHeaders(options[0].ExtraHTTPHeaders)
if len(options) == 1 && options[0].ExtraHttpHeaders != nil {
overrides["extraHTTPHeaders"] = serializeHeaders(options[0].ExtraHttpHeaders)
}
channel, err := b.channel.Send("launchPersistentContext", options, overrides)
channel, err := b.channel.Send("launchPersistentContext", overrides, options)
if err != nil {
return nil, fmt.Errorf("could not send message: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/mobile-and-geolocation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {
device := pw.Devices["iPhone 11 Pro"]
context, err := browser.NewContext(playwright.BrowserNewContextOptions{
Locale: playwright.String("en-US"),
Geolocation: &playwright.BrowserNewContextGeolocation{
Geolocation: &playwright.BrowserNewContextOptionsGeolocation{
Longitude: playwright.Float(12.492507),
Latitude: playwright.Float(41.889938),
},
Expand Down
2 changes: 1 addition & 1 deletion examples/parallel-scraping/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func worker(id int, jobs chan job, results chan<- bool, browser playwright.Brows
assertErrorToNilf("could not create page: %w", err)

_, err = page.Goto("http://"+jobPayload.URL, playwright.PageGotoOptions{
WaitUntil: playwright.String("networkidle"),
WaitUntil: playwright.WaitUntilStateNetworkidle,
})
if err != nil {
log.Printf("could not goto: %s: %v", jobPayload.URL, err)
Expand Down
2 changes: 1 addition & 1 deletion examples/pdf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {
assertErrorToNilf("could not create page: %w", err)
_, err = page.Goto("https://github.com/microsoft/playwright")
assertErrorToNilf("could not goto: %w", err)
_, err = page.PDF(playwright.PagePDFOptions{
_, err = page.PDF(playwright.PagePdfOptions{
Path: playwright.String("playwright-example.pdf"),
})
assertErrorToNilf("could not create PDF: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion examples/screenshot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
log.Fatalf("could not create page: %v", err)
}
if _, err = page.Goto("http://whatsmyuseragent.org/", playwright.PageGotoOptions{
WaitUntil: playwright.String("networkidle"),
WaitUntil: playwright.WaitUntilStateNetworkidle,
}); err != nil {
log.Fatalf("could not goto: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/video/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
log.Fatalf("could not launch Chromium: %v", err)
}
page, err := browser.NewPage(playwright.BrowserNewContextOptions{
RecordVideo: &playwright.BrowserNewContextRecordVideo{
RecordVideo: &playwright.BrowserNewContextOptionsRecordVideo{
Dir: playwright.String("videos/"),
},
})
Expand Down
12 changes: 4 additions & 8 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (f *frameImpl) WaitForNavigation(options ...PageWaitForNavigationOptions) (
option = options[0]
}
if option.WaitUntil == nil {
option.WaitUntil = String("load")
option.WaitUntil = WaitUntilStateLoad
}
if option.Timeout == nil {
option.Timeout = Float(f.page.timeoutSettings.NavigationTimeout())
Expand Down Expand Up @@ -345,11 +345,7 @@ func (f *frameImpl) WaitForSelector(selector string, options ...PageWaitForSelec
return channelOwner.(*elementHandleImpl), nil
}

func (f *frameImpl) DispatchEvent(selector, typ string, options ...PageDispatchEventOptions) error {
var eventInit interface{}
if len(options) == 1 {
eventInit = options[0].EventInit
}
func (f *frameImpl) DispatchEvent(selector, typ string, eventInit interface{}, options ...PageDispatchEventOptions) error {
_, err := f.channel.Send("dispatchEvent", map[string]interface{}{
"selector": selector,
"type": typ,
Expand Down Expand Up @@ -438,7 +434,7 @@ func (f *frameImpl) WaitForTimeout(timeout float64) {
time.Sleep(time.Duration(timeout) * time.Millisecond)
}

func (f *frameImpl) WaitForFunction(expression string, options ...FrameWaitForFunctionOptions) (JSHandle, error) {
func (f *frameImpl) WaitForFunction(expression string, arg interface{}, options ...FrameWaitForFunctionOptions) (JSHandle, error) {
var option FrameWaitForFunctionOptions
if len(options) == 1 {
option = options[0]
Expand All @@ -450,7 +446,7 @@ func (f *frameImpl) WaitForFunction(expression string, options ...FrameWaitForFu
result, err := f.channel.Send("evaluateExpression", map[string]interface{}{
"expression": expression,
"isFunction": !forceExpression,
"arg": serializeArgument(option.Arg),
"arg": serializeArgument(arg),
"timeout": option.Timeout,
"polling": option.Polling,
})
Expand Down
147 changes: 147 additions & 0 deletions generated-enums.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package playwright

func getMixedState(in string) *MixedState {
v := MixedState(in)
return &v
}

type MixedState string

var (
MixedStateOn *MixedState = getMixedState("On")
MixedStateOff = getMixedState("Off")
MixedStateMixed = getMixedState("Mixed")
)

func getColorScheme(in string) *ColorScheme {
v := ColorScheme(in)
return &v
}

type ColorScheme string

var (
ColorSchemeLight *ColorScheme = getColorScheme("light")
ColorSchemeDark = getColorScheme("dark")
ColorSchemeNoPreference = getColorScheme("no-preference")
)

func getMouseButton(in string) *MouseButton {
v := MouseButton(in)
return &v
}

type MouseButton string

var (
MouseButtonLeft *MouseButton = getMouseButton("left")
MouseButtonRight = getMouseButton("right")
MouseButtonMiddle = getMouseButton("middle")
)

func getKeyboardModifier(in string) *KeyboardModifier {
v := KeyboardModifier(in)
return &v
}

type KeyboardModifier string

var (
KeyboardModifierAlt *KeyboardModifier = getKeyboardModifier("Alt")
KeyboardModifierControl = getKeyboardModifier("Control")
KeyboardModifierMeta = getKeyboardModifier("Meta")
KeyboardModifierShift = getKeyboardModifier("Shift")
)

func getScreenshotType(in string) *ScreenshotType {
v := ScreenshotType(in)
return &v
}

type ScreenshotType string

var (
ScreenshotTypePng *ScreenshotType = getScreenshotType("png")
ScreenshotTypeJpeg = getScreenshotType("jpeg")
)

func getElementState(in string) *ElementState {
v := ElementState(in)
return &v
}

type ElementState string

var (
ElementStateVisible *ElementState = getElementState("visible")
ElementStateHidden = getElementState("hidden")
ElementStateStable = getElementState("stable")
ElementStateEnabled = getElementState("enabled")
ElementStateDisabled = getElementState("disabled")
ElementStateEditable = getElementState("editable")
)

func getWaitForSelectorState(in string) *WaitForSelectorState {
v := WaitForSelectorState(in)
return &v
}

type WaitForSelectorState string

var (
WaitForSelectorStateAttached *WaitForSelectorState = getWaitForSelectorState("attached")
WaitForSelectorStateDetached = getWaitForSelectorState("detached")
WaitForSelectorStateVisible = getWaitForSelectorState("visible")
WaitForSelectorStateHidden = getWaitForSelectorState("hidden")
)

func getWaitUntilState(in string) *WaitUntilState {
v := WaitUntilState(in)
return &v
}

type WaitUntilState string

var (
WaitUntilStateLoad *WaitUntilState = getWaitUntilState("load")
WaitUntilStateDomcontentloaded = getWaitUntilState("domcontentloaded")
WaitUntilStateNetworkidle = getWaitUntilState("networkidle")
)

func getLoadState(in string) *LoadState {
v := LoadState(in)
return &v
}

type LoadState string

var (
LoadStateLoad *LoadState = getLoadState("load")
LoadStateDomcontentloaded = getLoadState("domcontentloaded")
LoadStateNetworkidle = getLoadState("networkidle")
)

func getMedia(in string) *Media {
v := Media(in)
return &v
}

type Media string

var (
MediaScreen *Media = getMedia("screen")
MediaPrint = getMedia("print")
)

func getSameSiteAttribute(in string) *SameSiteAttribute {
v := SameSiteAttribute(in)
return &v
}

type SameSiteAttribute string

var (
SameSiteAttributeStrict *SameSiteAttribute = getSameSiteAttribute("Strict")
SameSiteAttributeLax = getSameSiteAttribute("Lax")
SameSiteAttributeNone = getSameSiteAttribute("None")
)
Loading

0 comments on commit d68a250

Please sign in to comment.