Skip to content

Commit

Permalink
chore: roll to playwright v1.42.1 (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
canstand committed Mar 2, 2024
1 parent 664e25d commit 24eab96
Show file tree
Hide file tree
Showing 38 changed files with 484 additions and 109,172 deletions.
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-121.0.6167.57-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-121.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-17.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-123.0.6312.4-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-123.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-17.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 -->121.0.6167.57<!-- GEN:stop --> ||||
| Chromium <!-- GEN:chromium-version -->123.0.6312.4<!-- GEN:stop --> ||||
| WebKit <!-- GEN:webkit-version -->17.4<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->121.0<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->123.0<!-- GEN:stop --> ||||

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

Expand Down
2 changes: 2 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func (e *Error) Is(target error) bool {
func parseError(err Error) error {
if err.Name == "TimeoutError" {
return fmt.Errorf("%w: %w: %w", ErrPlaywright, ErrTimeout, &err)
} else if err.Name == "TargetClosedError" {
return fmt.Errorf("%w: %w: %w", ErrPlaywright, ErrTargetClosed, &err)
}
return fmt.Errorf("%w: %w", ErrPlaywright, &err)
}
Expand Down
58 changes: 44 additions & 14 deletions generated-interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ type BrowserContext interface {
// - The [Browser.Close] method was called.
OnClose(fn func(BrowserContext))

// Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. Also
// emitted if the page throws an error or a warning.
// Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`.
// The arguments passed into `console.log` and the page are available on the [ConsoleMessage] event handler argument.
OnConsole(fn func(ConsoleMessage))

Expand Down Expand Up @@ -905,8 +904,8 @@ type ElementHandle interface {
// Holding down `Shift` will type the text that corresponds to the “key” in the upper case.
// If “key” is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
// texts.
// 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.
// Shortcuts such as `key: "Control+o"`, `key: "Control++` 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.
//
// Deprecated: Use locator-based [Locator.Press] instead. Read more about [locators].
//
Expand Down Expand Up @@ -1597,8 +1596,8 @@ type Frame interface {
// Holding down `Shift` will type the text that corresponds to the “key” in the upper case.
// If “key” is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
// texts.
// 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.
// Shortcuts such as `key: "Control+o"`, `key: "Control++` 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.
//
// Deprecated: Use locator-based [Locator.Press] instead. Read more about [locators].
//
Expand Down Expand Up @@ -2031,8 +2030,8 @@ type Keyboard interface {
// Holding down `Shift` will type the text that corresponds to the “key” in the upper case.
// If “key” is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
// texts.
// 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.
// Shortcuts such as `key: "Control+o"`, `key: "Control++` 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.
//
// key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`.
//
Expand Down Expand Up @@ -2536,8 +2535,8 @@ type Locator interface {
// Holding down `Shift` will type the text that corresponds to the “key” in the upper case.
// If “key” is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
// texts.
// 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.
// Shortcuts such as `key: "Control+o"`, `key: "Control++` 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.
//
// key: Name of the key to press or a character to generate, such as `ArrowLeft` or `a`.
//
Expand Down Expand Up @@ -2870,8 +2869,7 @@ type Page interface {
// Emitted when the page closes.
OnClose(fn func(Page))

// Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`. Also
// emitted if the page throws an error or a warning.
// Emitted when JavaScript within the page calls one of console API methods, e.g. `console.log` or `console.dir`.
// The arguments passed into `console.log` are available on the [ConsoleMessage] event handler argument.
OnConsole(fn func(ConsoleMessage))

Expand Down Expand Up @@ -3489,8 +3487,8 @@ type Page interface {
// Holding down `Shift` will type the text that corresponds to the “key” in the upper case.
// If “key” is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
// texts.
// 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.
// Shortcuts such as `key: "Control+o"`, `key: "Control++` 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.
//
// Deprecated: Use locator-based [Locator.Press] instead. Read more about [locators].
//
Expand Down Expand Up @@ -3523,6 +3521,38 @@ type Page interface {
// [locators]: https://playwright.dev/docs/locators
QuerySelectorAll(selector string) ([]ElementHandle, error)

// When testing a web page, sometimes unexpected overlays like a coookie consent dialog appear and block actions you
// want to automate, e.g. clicking a button. These overlays don't always show up in the same way or at the same time,
// making them tricky to handle in automated tests.
// This method lets you set up a special function, called a handler, that activates when it detects that overlay is
// visible. The handler's job is to remove the overlay, allowing your test to continue as if the overlay wasn't there.
// Things to keep in mind:
// - When an overlay is shown predictably, we recommend explicitly waiting for it in your test and dismissing it as
// a part of your normal test flow, instead of using [Page.AddLocatorHandler].
// - Playwright checks for the overlay every time before executing or retrying an action that requires an
// [actionability check], or before performing an auto-waiting assertion check. When overlay
// is visible, Playwright calls the handler first, and then proceeds with the action/assertion.
// - The execution time of the handler counts towards the timeout of the action/assertion that executed the handler.
// If your handler takes too long, it might cause timeouts.
// - You can register multiple handlers. However, only a single handler will be running at a time. Make sure the
// actions within a handler don't depend on another handler.
// **NOTE** Running the handler will alter your page state mid-test. For example it will change the currently focused
// element and move the mouse. Make sure that actions that run after the handler are self-contained and do not rely on
// the focus and mouse state being unchanged. <br /> <br /> For example, consider a test that calls [Locator.Focus]
// followed by [Keyboard.Press]. If your handler clicks a button between these two actions, the focused element most
// likely will be wrong, and key press will happen on the unexpected element. Use [Locator.Press] instead to avoid
// this problem. <br /> <br /> Another example is a series of mouse actions, where [Mouse.Move] is followed by
// [Mouse.Down]. Again, when the handler runs between these two actions, the mouse position will be wrong during the
// mouse down. Prefer self-contained actions like [Locator.Click] that do not rely on the state being unchanged by a
// handler.
//
// 1. locator: Locator that triggers the handler.
// 2. handler: Function that should be run once “locator” appears. This function should get rid of the element that blocks actions
// like click.
//
// [actionability check]: https://playwright.dev/docs/actionability
AddLocatorHandler(locator Locator, handler func()) error

// 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.
Expand Down
4 changes: 4 additions & 0 deletions generated-structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3165,6 +3165,8 @@ type PagePdfOptions struct {
Landscape *bool `json:"landscape"`
// Paper margins, defaults to none.
Margin *Margin `json:"margin"`
// Whether or not to embed the document outline into the PDF. Defaults to `false`.
Outline *bool `json:"outline"`
// Paper ranges to print, e.g., '1-5, 8, 11-13'. Defaults to the empty string, which means print all pages.
PageRanges *string `json:"pageRanges"`
// The file path to save the PDF to. If “path” is a relative path, then it is resolved relative to the current working
Expand All @@ -3177,6 +3179,8 @@ type PagePdfOptions struct {
PrintBackground *bool `json:"printBackground"`
// Scale of the webpage rendering. Defaults to `1`. Scale amount must be between 0.1 and 2.
Scale *float64 `json:"scale"`
// Whether or not to generate tagged (accessible) PDF. Defaults to `false`.
Tagged *bool `json:"tagged"`
// Paper width, accepts values labeled with units.
Width *string `json:"width"`
}
Expand Down
55 changes: 50 additions & 5 deletions page.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,47 @@ type pageImpl struct {
closeReason *string
closeWasCalled bool
harRouters []*harRouter
locatorHandlers map[float64]func()
}

func (p *pageImpl) AddLocatorHandler(locator Locator, handler func()) error {
if locator == nil || handler == nil {
return errors.New("locator or handler must not be nil")
}
if locator.Err() != nil {
return locator.Err()
}
loc := locator.(*locatorImpl)
if loc.frame != p.mainFrame {
return errors.New("locator must belong to the main frame of this page")
}
uid, err := p.channel.Send("registerLocatorHandler", map[string]any{
"selector": loc.selector,
})
if err != nil {
return err
}
p.locatorHandlers[uid.(float64)] = handler
return nil
}

func (p *pageImpl) onLocatorHandlerTriggered(uid float64) {
handler, ok := p.locatorHandlers[uid]
if !ok {
return
}
go func() {
defer func() {
_, _ = p.connection.WrapAPICall(func() (interface{}, error) {
p.channel.SendNoReply("resolveLocatorHandlerNoReply", map[string]any{
"uid": uid,
})
return nil, nil
}, true)
}()

handler()
}()
}

func (p *pageImpl) Context() BrowserContext {
Expand Down Expand Up @@ -740,11 +781,12 @@ func newPage(parent *channelOwner, objectType string, guid string, initializer m
viewportSize.Width = int(initializer["viewportSize"].(map[string]interface{})["width"].(float64))
}
bt := &pageImpl{
workers: make([]Worker, 0),
routes: make([]*routeHandlerEntry, 0),
bindings: make(map[string]BindingCallFunction),
viewportSize: viewportSize,
harRouters: make([]*harRouter, 0),
workers: make([]Worker, 0),
routes: make([]*routeHandlerEntry, 0),
bindings: make(map[string]BindingCallFunction),
viewportSize: viewportSize,
harRouters: make([]*harRouter, 0),
locatorHandlers: make(map[float64]func(), 0),
}
bt.createChannelOwner(bt, parent, objectType, guid, initializer)
bt.browserContext = fromChannel(parent.channel).(*browserContextImpl)
Expand Down Expand Up @@ -775,6 +817,9 @@ func newPage(parent *channelOwner, objectType string, guid string, initializer m
bt.channel.On("frameDetached", func(ev map[string]interface{}) {
bt.onFrameDetached(fromChannel(ev["frame"]).(*frameImpl))
})
bt.channel.On("locatorHandlerTriggered", func(ev map[string]interface{}) {
bt.onLocatorHandlerTriggered(ev["uid"].(float64))
})
bt.channel.On(
"load", func(ev map[string]interface{}) {
bt.Emit("load", bt)
Expand Down

0 comments on commit 24eab96

Please sign in to comment.