Skip to content

Commit

Permalink
chore: roll to 1.20.0-beta-1647057403000 (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Mar 12, 2022
1 parent 5c5ce58 commit 21654cc
Show file tree
Hide file tree
Showing 37 changed files with 550 additions and 186 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
id: go
- run: |
go install ./...
playwright install-deps
playwright install --with-deps ${{ matrix.browser }}
- name: Test
env:
BROWSER: ${{ matrix.browser }}
Expand Down Expand Up @@ -83,6 +83,11 @@ jobs:
id: go
- run: |
go install ./...
playwright install-deps
playwright install --with-deps
- name: Run examples
run: xvfb-run bash -c "for dir in examples/*; do go run \$dir/main.go; done"
run: |
for dir in examples/*; do
echo "::group::go run $dir/main.go"
xvfb-run go run $dir/main.go
echo "::endgroup::"
done
4 changes: 3 additions & 1 deletion .github/workflows/verify_type_generation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ jobs:
with:
go-version: ^1.16.1
- name: Install Browsers
run: go run scripts/install-browsers/main.go
run: |
go install ./...
playwright install --with-deps
- name: Regenerate APIs
run: |
git config --global user.email "[email protected]"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
[![PkgGoDev](https://pkg.go.dev/badge/github.com/playwright-community/playwright-go)](https://pkg.go.dev/github.com/playwright-community/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/playwright-community/playwright-go)](https://goreportcard.com/report/github.com/playwright-community/playwright-go) ![Build Status](https://github.com/playwright-community/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/playwright-community/playwright-go/badge.svg?branch=main)](https://coveralls.io/github/playwright-community/playwright-go?branch=main) <!-- GEN:chromium-version-badge -->[![Chromium version](https://img.shields.io/badge/chromium-97.0.4666.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-93.0-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-15.4-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/playwright-community/playwright-go/badge.svg?branch=main)](https://coveralls.io/github/playwright-community/playwright-go?branch=main) <!-- GEN:chromium-version-badge -->[![Chromium version](https://img.shields.io/badge/chromium-101.0.4929.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-97.0.1-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-15.4-blue.svg?logo=safari)](https://webkit.org/)<!-- GEN:stop -->

[API reference](https://playwright.dev/docs/api/class-playwright) | [Example recipes](https://github.com/playwright-community/playwright-go/tree/main/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 -->97.0.4666.0<!-- GEN:stop --> ||||
| Chromium <!-- GEN:chromium-version -->101.0.4929.0<!-- GEN:stop --> ||||
| WebKit <!-- GEN:webkit-version -->15.4<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->93.0<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->97.0.1<!-- GEN:stop --> ||||

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

Expand Down
2 changes: 1 addition & 1 deletion browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func newBrowserContext(parent *channelOwner, objectType string, guid string, ini
bindings: make(map[string]BindingCallFunction),
}
bt.createChannelOwner(bt, parent, objectType, guid, initializer)
bt.tracing = newTracing(bt)
bt.tracing = fromChannel(initializer["tracing"]).(*tracingImpl)
bt.channel.On("bindingCall", func(params map[string]interface{}) {
bt.onBinding(fromChannel(params["binding"]).(*bindingCallImpl))
})
Expand Down
3 changes: 3 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ func (c *connection) Dispatch(msg *message) {
)
return
}
if object == nil {
return
}
if method == "__dispose__" {
object.dispose()
return
Expand Down
2 changes: 1 addition & 1 deletion examples/download/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {
pw, err := playwright.Run()
assertErrorToNilf("could not launch playwright: %w", err)
browser, err := pw.Chromium.Launch(playwright.BrowserTypeLaunchOptions{
Headless: playwright.Bool(false),
Headless: playwright.Bool(true),
})
assertErrorToNilf("could not launch Chromium: %w", err)
context, err := browser.NewContext()
Expand Down
11 changes: 4 additions & 7 deletions examples/mobile-and-geolocation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package main

import (
"log"
"regexp"

"github.com/playwright-community/playwright-go"
)
Expand All @@ -15,13 +14,12 @@ func main() {
if err != nil {
log.Fatalf("could not start playwright: %v", err)
}
browser, err := pw.WebKit.Launch()
browser, err := pw.Chromium.Launch()
if err != nil {
log.Fatalf("could not launch browser: %v", err)
}
device := pw.Devices["iPhone 11 Pro"]
device := pw.Devices["Pixel 5"]
context, err := browser.NewContext(playwright.BrowserNewContextOptions{
Locale: playwright.String("en-US"),
Geolocation: &playwright.BrowserNewContextOptionsGeolocation{
Longitude: playwright.Float(12.492507),
Latitude: playwright.Float(41.889938),
Expand All @@ -40,13 +38,12 @@ func main() {
if err != nil {
log.Fatalf("could not create page: %v", err)
}
if _, err = page.Goto("https://maps.google.com"); err != nil {
if _, err = page.Goto("https://www.openstreetmap.org"); err != nil {
log.Fatalf("could not goto: %v", err)
}
if err = page.Click(".ml-my-location-fab button"); err != nil {
if err = page.Click("a[data-original-title='Show My Location']"); err != nil {
log.Fatalf("could not click on location: %v", err)
}
page.WaitForRequest(regexp.MustCompile(".*preview/pwa"))
if _, err = page.Screenshot(playwright.PageScreenshotOptions{
Path: playwright.String("colosseum-iphone.png"),
}); err != nil {
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 @@ -32,7 +32,7 @@ func worker(id int, jobs chan job, results chan<- bool, browser playwright.Brows
results <- true
continue
}
fmt.Printf("starting (%d): %s\n", jobPayload.Try, jobPayload.URL)
fmt.Printf("starting (try: %d): %s\n", jobPayload.Try, jobPayload.URL)

context, err := browser.NewContext(playwright.BrowserNewContextOptions{
UserAgent: playwright.String("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36"),
Expand Down
37 changes: 37 additions & 0 deletions generated-enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,42 @@ var (
KeyboardModifierShift = getKeyboardModifier("Shift")
)

func getScreenshotAnimations(in string) *ScreenshotAnimations {
v := ScreenshotAnimations(in)
return &v
}

type ScreenshotAnimations string

var (
ScreenshotAnimationsDisabled *ScreenshotAnimations = getScreenshotAnimations("disabled")
ScreenshotAnimationsAllow = getScreenshotAnimations("allow")
)

func getScreenshotFonts(in string) *ScreenshotFonts {
v := ScreenshotFonts(in)
return &v
}

type ScreenshotFonts string

var (
ScreenshotFontsReady *ScreenshotFonts = getScreenshotFonts("ready")
ScreenshotFontsNowait = getScreenshotFonts("nowait")
)

func getScreenshotSize(in string) *ScreenshotSize {
v := ScreenshotSize(in)
return &v
}

type ScreenshotSize string

var (
ScreenshotSizeCss *ScreenshotSize = getScreenshotSize("css")
ScreenshotSizeDevice = getScreenshotSize("device")
)

func getScreenshotType(in string) *ScreenshotType {
v := ScreenshotType(in)
return &v
Expand Down Expand Up @@ -130,6 +166,7 @@ var (
WaitUntilStateLoad *WaitUntilState = getWaitUntilState("load")
WaitUntilStateDomcontentloaded = getWaitUntilState("domcontentloaded")
WaitUntilStateNetworkidle = getWaitUntilState("networkidle")
WaitUntilStateCommit = getWaitUntilState("commit")
)

func getLoadState(in string) *LoadState {
Expand Down
37 changes: 25 additions & 12 deletions generated-interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ type Tracing interface {
// Start a new trace chunk. If you'd like to record multiple traces on the same `BrowserContext`, use
// Tracing.start`] once, and then create multiple trace chunks with [`method: Tracing.startChunk() and
// Tracing.stopChunk().
StartChunk() error
StartChunk(options ...TracingStartChunkOptions) error
// Stop the trace chunk. See Tracing.startChunk() for more details about multiple trace chunks.
StopChunk(options ...TracingStopChunkOptions) error
}
Expand Down Expand Up @@ -246,9 +246,6 @@ type Dialog interface {
// `Download` objects are dispatched by page via the [`event: Page.download`] event.
// All the downloaded files belonging to the browser context are deleted when the browser context is closed.
// Download event is emitted once the download starts. Download path becomes available once download completes:
// > NOTE: Browser context **must** be created with the `acceptDownloads` set to `true` when user needs access to the
// downloaded content. If `acceptDownloads` is not set, download events are emitted, but the actual download is not
// performed and user has no access to the downloaded files.
type Download interface {
// Deletes the downloaded file. Will wait for the download to finish if necessary.
Delete() error
Expand Down Expand Up @@ -279,12 +276,11 @@ type Download interface {

// ElementHandle represents an in-page DOM element. ElementHandles can be created with the Page.querySelector()
// method.
// > NOTE: The use of ElementHandle is discouraged, use `Locator` objects and web-first assertions instead.
// ElementHandle prevents DOM element from garbage collection unless the handle is disposed with
// JSHandle.dispose(). ElementHandles are auto-disposed when their origin frame gets navigated.
// ElementHandle instances can be used as an argument in Page.evalOnSelector`] and [`method: Page.evaluate()
// methods.
// > NOTE: In most cases, you would want to use the `Locator` object instead. You should only use `ElementHandle` if you
// want to retain a handle to a particular DOM Node that you intend to pass into Page.evaluate() as an argument.
// The difference between the `Locator` and ElementHandle is that the ElementHandle points to a particular element, while
// `Locator` captures the logic of how to retrieve an element.
// In the example below, handle points to a particular DOM element on page. If that element changes text or is used by
Expand Down Expand Up @@ -645,6 +641,8 @@ type Frame interface {
// `JSHandle` instances can be passed as an argument to the Frame.evaluateHandle():
EvaluateHandle(expression string, options ...interface{}) (JSHandle, error)
// Returns the return value of `expression`.
// > NOTE: This method does not wait for the element to pass actionability checks and therefore can lead to the flaky
// tests. Use Locator.evaluate(), other `Locator` helper methods or web-first assertions instead.
// The method finds an element matching the specified selector within the frame and passes it as a first argument to
// `expression`. See [Working with selectors](./selectors.md) for more details. If no elements match the selector, the
// method throws an error.
Expand All @@ -653,6 +651,8 @@ type Frame interface {
// Examples:
EvalOnSelector(selector string, expression string, options ...interface{}) (interface{}, error)
// Returns the return value of `expression`.
// > NOTE: In most cases, Locator.evaluateAll(), other `Locator` helper methods and web-first assertions do a
// better job.
// The method finds all elements matching the specified selector within the frame and passes an array of matched elements
// as a first argument to `expression`. See [Working with selectors](./selectors.md) for more details.
// If `expression` returns a [Promise], then Frame.evalOnSelectorAll() would wait for the promise to resolve and
Expand Down Expand Up @@ -745,10 +745,12 @@ type Frame interface {
// modifier, modifier is pressed and being held while the subsequent key is being pressed.
Press(selector, key string, options ...PagePressOptions) error
// Returns the ElementHandle pointing to the frame element.
// > NOTE: The use of `ElementHandle` is discouraged, use `Locator` objects and web-first assertions instead.
// The method finds an element matching the specified selector within the frame. See
// [Working with selectors](./selectors.md) for more details. If no elements match the selector, returns `null`.
QuerySelector(selector string) (ElementHandle, error)
// Returns the ElementHandles pointing to the frame elements.
// > NOTE: The use of `ElementHandle` is discouraged, use `Locator` objects instead.
// The method finds all elements matching the specified selector within the frame. See
// [Working with selectors](./selectors.md) for more details. If no elements match the selector, returns empty array.
QuerySelectorAll(selector string) ([]ElementHandle, error)
Expand Down Expand Up @@ -821,6 +823,8 @@ type Frame interface {
WaitForURL(url string, options ...FrameWaitForURLOptions) error
// Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
// `detached`.
// > NOTE: Playwright automatically waits for element to be ready before performing an action. Using `Locator` objects and
// web-first assertions make the code wait-for-selector-free.
// Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at
// the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
// selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.
Expand Down Expand Up @@ -1087,13 +1091,17 @@ type Page interface {
// A string can also be passed in instead of a function:
// `JSHandle` instances can be passed as an argument to the Page.evaluateHandle():
EvaluateHandle(expression string, options ...interface{}) (JSHandle, error)
// > NOTE: This method does not wait for the element to pass actionability checks and therefore can lead to the flaky
// tests. Use Locator.evaluate(), other `Locator` helper methods or web-first assertions instead.
// The method finds an element matching the specified selector within the page and passes it as a first argument to
// `expression`. If no elements match the selector, the method throws an error. Returns the value of `expression`.
// If `expression` returns a [Promise], then Page.evalOnSelector() would wait for the promise to resolve and
// return its value.
// Examples:
// Shortcut for main frame's Frame.evalOnSelector().
EvalOnSelector(selector string, expression string, options ...interface{}) (interface{}, error)
// > NOTE: In most cases, Locator.evaluateAll(), other `Locator` helper methods and web-first assertions do a
// better job.
// The method finds all elements matching the specified selector within the page and passes an array of matched elements as
// a first argument to `expression`. Returns the result of `expression` invocation.
// If `expression` returns a [Promise], then Page.evalOnSelectorAll() would wait for the promise to resolve and
Expand Down Expand Up @@ -1236,16 +1244,18 @@ type Page interface {
// Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
// modifier, modifier is pressed and being held while the subsequent key is being pressed.
Press(selector, key string, options ...PagePressOptions) error
// > NOTE: The use of `ElementHandle` is discouraged, use `Locator` objects and web-first assertions instead.
// The method finds an element matching the specified selector within the page. If no elements match the selector, the
// return value resolves to `null`. To wait for an element on the page, use Page.waitForSelector().
// return value resolves to `null`. To wait for an element on the page, use Locator.waitFor().
// Shortcut for main frame's Frame.querySelector().
QuerySelector(selector string) (ElementHandle, error)
// > NOTE: The use of `ElementHandle` is discouraged, use `Locator` objects and web-first assertions instead.
// The method finds all elements matching the specified selector within the page. If no elements match the selector, the
// return value resolves to `[]`.
// Shortcut for main frame's Frame.querySelectorAll().
QuerySelectorAll(selector string) ([]ElementHandle, error)
// Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
// last redirect.
// This method reloads the current page, in the same way as if the user had triggered a browser refresh. Returns the main
// resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
Reload(options ...PageReloadOptions) (Response, error)
// Routing provides the capability to modify network requests that are made by a page.
// Once routing is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
Expand Down Expand Up @@ -1298,9 +1308,10 @@ type Page interface {
SetInputFiles(selector string, files []InputFile, options ...FrameSetInputFilesOptions) error
// In the case of multiple pages in a single browser, each page can have its own viewport size. However,
// Browser.newContext() allows to set viewport size (and more) for all pages in the context at once.
// `page.setViewportSize` will resize the page. A lot of websites don't expect phones to change size, so you should set the
// viewport size before navigating to the page. Page.setViewportSize() will also reset `screen` size, use
// Browser.newContext() with `screen` and `viewport` parameters if you need better control of these properties.
// Page.setViewportSize() will resize the page. A lot of websites don't expect phones to change size, so you
// should set the viewport size before navigating to the page. Page.setViewportSize() will also reset `screen`
// size, use Browser.newContext() with `screen` and `viewport` parameters if you need better control of these
// properties.
SetViewportSize(width, height int) error
// This method taps an element matching `selector` by performing the following steps:
// 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
Expand Down Expand Up @@ -1374,6 +1385,8 @@ type Page interface {
WaitForResponse(url interface{}, options ...interface{}) Response
// Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
// `detached`.
// > NOTE: Playwright automatically waits for element to be ready before performing an action. Using `Locator` objects and
// web-first assertions make the code wait-for-selector-free.
// Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at
// the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
// selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.
Expand Down
Loading

0 comments on commit 21654cc

Please sign in to comment.