Skip to content

Commit

Permalink
chore: roll to playwright v1.37.1 (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
canstand authored Aug 25, 2023
1 parent d1bed75 commit 8575a75
Show file tree
Hide file tree
Showing 28 changed files with 589 additions and 181 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ jobs:
with:
go-version: ^1.19.9
id: go
- name: Cache drivers
uses: actions/cache@v3
with:
# In order:
# * Driver for linux
# * Driver for macOS
# * Driver for windows
path: |
~/.cache/ms-playwright-go
~/.cache/ms-playwright
~/Library/Caches/ms-playwright-go
~/Library/Caches/ms-playwright
~\AppData\Local\ms-playwright-go
~\AppData\Local\ms-playwright
key: ${{ runner.os }}-go-${{ matrix.browser }}-${{ hashFiles('**/run.go') }}
- run: |
go install ./...
playwright install --with-deps ${{ matrix.browser }}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
[![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-115.0.5790.75-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-115.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.0-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-116.0.5845.82-blue.svg?logo=google-chrome)](https://www.chromium.org/Home)<!-- GEN:stop --> <!-- GEN:firefox-version-badge -->[![Firefox version](https://img.shields.io/badge/firefox-115.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.0-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 -->115.0.5790.75<!-- GEN:stop --> ||||
| Chromium <!-- GEN:chromium-version -->116.0.5845.82<!-- GEN:stop --> ||||
| WebKit <!-- GEN:webkit-version -->17.0<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->115.0<!-- GEN:stop --> ||||

Expand Down
24 changes: 18 additions & 6 deletions artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,36 @@ func (a *artifactImpl) SaveAs(path string) error {
return stream.SaveAs(path)
}

func (d *artifactImpl) Failure() error {
failure, err := d.channel.Send("failure")
func (a *artifactImpl) Failure() error {
failure, err := a.channel.Send("failure")
if failure == nil {
return err
}
return fmt.Errorf("%v", failure)
}

func (d *artifactImpl) Delete() error {
_, err := d.channel.Send("delete")
func (a *artifactImpl) Delete() error {
_, err := a.channel.Send("delete")
return err
}

func (d *artifactImpl) Cancel() error {
_, err := d.channel.Send("cancel")
func (a *artifactImpl) Cancel() error {
_, err := a.channel.Send("cancel")
return err
}

func (a *artifactImpl) ReadIntoBuffer() ([]byte, error) {
streamChannel, err := a.channel.Send("stream")
if err != nil {
return nil, err
}
stream := fromNullableChannel(streamChannel)
if stream == nil {
return nil, nil
}
return stream.(*streamImpl).ReadAll()
}

func newArtifact(parent *channelOwner, objectType string, guid string, initializer map[string]interface{}) *artifactImpl {
artifact := &artifactImpl{}
artifact.createChannelOwner(artifact, parent, objectType, guid, initializer)
Expand Down
6 changes: 5 additions & 1 deletion assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ import (
"strings"
)

const assertionsDefaultTimeout = 5000 // 5s

type playwrightAssertionsImpl struct {
defaultTimeout *float64
}

// NewPlaywrightAssertions creates a new instance of PlaywrightAssertions
// - timeout: default value is 5000 (ms)
func NewPlaywrightAssertions(timeout ...float64) PlaywrightAssertions {
if len(timeout) > 0 {
return &playwrightAssertionsImpl{Float(timeout[0])}
}
return &playwrightAssertionsImpl{Float(5000)}
return &playwrightAssertionsImpl{Float(assertionsDefaultTimeout)}
}

func (pa *playwrightAssertionsImpl) APIResponse(response APIResponse) APIResponseAssertions {
Expand Down
30 changes: 25 additions & 5 deletions browser.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package playwright

import (
"encoding/base64"
"encoding/json"
"fmt"
"os"
"path/filepath"
)

type browserImpl struct {
Expand All @@ -14,6 +14,7 @@ type browserImpl struct {
shouldCloseConnectionOnClose bool
contexts []BrowserContext
browserType BrowserType
chromiumTracingPath *string
}

func (b *browserImpl) BrowserType() BrowserType {
Expand Down Expand Up @@ -121,7 +122,7 @@ func (b *browserImpl) Close() error {
b.Unlock()
_, err := b.channel.Send("close")
if err != nil && !isSafeCloseError(err) {
return fmt.Errorf("could not send message: %w", err)
return fmt.Errorf("close browser failed: %w", err)
}
if b.shouldCloseConnectionOnClose {
return b.connection.Stop()
Expand All @@ -143,18 +144,37 @@ func (b *browserImpl) StartTracing(options ...BrowserStartTracingOptions) error
overrides["page"] = option.Page.(*pageImpl).channel
option.Page = nil
}
if option.Path != nil {
b.chromiumTracingPath = option.Path
option.Path = nil
}
_, err := b.channel.Send("startTracing", option, overrides)
return err
}

func (b *browserImpl) StopTracing() ([]byte, error) {
data, err := b.channel.Send("stopTracing")
channel, err := b.channel.Send("stopTracing")
if err != nil {
return nil, err
}
binary, err := base64.StdEncoding.DecodeString(data.(string))
artifact := fromChannel(channel).(*artifactImpl)
binary, err := artifact.ReadIntoBuffer()
if err != nil {
return nil, fmt.Errorf("could not decode base64 :%w", err)
return nil, err
}
err = artifact.Delete()
if err != nil {
return binary, err
}
if b.chromiumTracingPath != nil {
err := os.MkdirAll(filepath.Dir(*b.chromiumTracingPath), 0777)
if err != nil {
return binary, err
}
err = os.WriteFile(*b.chromiumTracingPath, binary, 0644)
if err != nil {
return binary, err
}
}
return binary, nil
}
Expand Down
38 changes: 10 additions & 28 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,31 +132,11 @@ func (c *connection) createRemoteObject(parent *channelOwner, objectType string,
}

func (c *connection) WrapAPICall(cb func() (interface{}, error), isInternal bool) (interface{}, error) {
call := func() (interface{}, error) {
result := reflect.ValueOf(cb).Call(nil)
// accept 0 to 2 return values
switch len(result) {
case 2:
val := result[0].Interface()
err, ok := result[1].Interface().(error)
if ok && err != nil {
return val, err
}
return val, nil
case 1:
return result[0].Interface(), nil
default:
return nil, nil
}
}
if _, ok := c.apiZone.Load("apiZone"); !ok {
return call()
if _, ok := c.apiZone.Load("apiZone"); ok {
return cb()
}
defer func() {
c.apiZone.Delete("apiZone")
}()
c.apiZone.Store("apiZone", serializeCallStack(isInternal))
return call()
return cb()
}

func (c *connection) replaceChannelsWithGuids(payload interface{}) interface{} {
Expand Down Expand Up @@ -222,10 +202,12 @@ func (c *connection) sendMessageToServer(guid string, method string, params inte
metadata = make(map[string]interface{}, 0)
stack = make([]map[string]interface{}, 0)
)
apiZone, ok := c.apiZone.Load("apiZone")
apiZone, ok := c.apiZone.LoadAndDelete("apiZone")
if ok {
metadata = apiZone.(*parsedStackTrace).metadata
stack = apiZone.(*parsedStackTrace).frames
for k, v := range apiZone.(parsedStackTrace).metadata {
metadata[k] = v
}
stack = append(stack, apiZone.(parsedStackTrace).frames...)
}
metadata["wallTime"] = time.Now().Nanosecond()
message := map[string]interface{}{
Expand Down Expand Up @@ -259,7 +241,7 @@ type parsedStackTrace struct {
metadata map[string]interface{}
}

func serializeCallStack(isInternal bool) *parsedStackTrace {
func serializeCallStack(isInternal bool) parsedStackTrace {
st := stack.Trace().TrimRuntime()

lastInternalIndex := 0
Expand Down Expand Up @@ -296,7 +278,7 @@ func serializeCallStack(isInternal bool) *parsedStackTrace {
}
metadata["apiName"] = apiName
metadata["isInternal"] = isInternal
return &parsedStackTrace{
return parsedStackTrace{
metadata: metadata,
frames: callStack,
}
Expand Down
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var TimeoutError = &Error{
Name: "TimeoutError",
}

func parseError(err errorPayload) error {
func parseError(err Error) error {
return &Error{
Name: err.Name,
Message: err.Message,
Expand Down
1 change: 0 additions & 1 deletion examples/screenshot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func main() {
log.Fatalf("could not create page: %v", err)
}
if _, err = page.Goto("https://playwright.dev/", playwright.PageGotoOptions{
// networkidle is DISCOURAGED
WaitUntil: playwright.WaitUntilStateDomcontentloaded,
}); err != nil {
log.Fatalf("could not goto: %v", err)
Expand Down
3 changes: 2 additions & 1 deletion fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"os"
"strings"
)

type apiRequestImpl struct {
Expand Down Expand Up @@ -397,7 +398,7 @@ func countNonNil(args ...interface{}) int {
func isJsonContentType(headers []map[string]string) bool {
if len(headers) > 0 {
for _, v := range headers {
if v["name"] == "Content-Type" {
if strings.ToLower(v["name"]) == "content-type" {
if v["value"] == "application/json" {
return true
}
Expand Down
4 changes: 2 additions & 2 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,11 @@ func (f *frameImpl) Focus(selector string, options ...FrameFocusOptions) error {
}

func (f *frameImpl) FrameElement() (ElementHandle, error) {
elementHandle, err := f.channel.Send("frameElement")
channel, err := f.channel.Send("frameElement")
if err != nil {
return nil, err
}
return elementHandle.(*elementHandleImpl), nil
return fromChannel(channel).(*elementHandleImpl), nil
}

func (f *frameImpl) IsDetached() bool {
Expand Down
21 changes: 16 additions & 5 deletions generated-interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ type BrowserContext interface {
// har: Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If `path` is a
// relative path, then it is resolved relative to the current working directory.
//
// [Replaying from HAR]: https://playwright.dev/docs/network#replaying-from-har
// [Replaying from HAR]: https://playwright.dev/docs/mock#replaying-from-har
// [this]: https://github.com/microsoft/playwright/issues/1090
RouteFromHAR(har string, options ...BrowserContextRouteFromHAROptions) error

Expand Down Expand Up @@ -1559,8 +1559,12 @@ type Frame interface {
// [locators]: https://playwright.dev/docs/locators
SetChecked(selector string, checked bool, options ...FrameSetCheckedOptions) error

// This method internally calls [document.Write()],
// inheriting all its specific characteristics and behaviors.
//
// html: HTML markup to assign to the page.
//
// [document.Write()]: https://developer.mozilla.org/en-US/docs/Web/API/Document/write
SetContent(html string, options ...FrameSetContentOptions) error

// Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then
Expand Down Expand Up @@ -1933,12 +1937,13 @@ type Keyboard interface {
}

// Locators are the central piece of Playwright's auto-waiting and retry-ability. In a nutshell, locators represent a
// way to find element(s) on the page at any moment. Locator can be created with the [Page.Locator] method.
// way to find element(s) on the page at any moment. A locator can be created with the [Page.Locator] method.
// [Learn more about locators].
//
// [Learn more about locators]: https://playwright.dev/docs/locators
type Locator interface {
// When locator points to a list of elements, returns array of locators, pointing to respective elements.
// When the locator points to a list of elements, this returns an array of locators, pointing to their respective
// elements.
// **NOTE** [Locator.All] does not wait for elements to match the locator, and instead immediately returns whatever is
// present in the page. When the list of elements changes dynamically, [Locator.All] will produce unpredictable and
// flaky results. When the list of elements is stable, but loaded dynamically, wait for the full list to finish
Expand Down Expand Up @@ -2482,6 +2487,8 @@ type Locator interface {
// [`node.textContent`]: https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent
TextContent(options ...LocatorTextContentOptions) (string, error)

// **NOTE** In most cases, you should use [Locator.Fill] instead. You only need to type characters if there is special
// keyboard handling on the page.
// Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the
// text.
// To press a special key, like `Control` or `ArrowDown`, use [Locator.Press].
Expand Down Expand Up @@ -2722,7 +2729,7 @@ type Page interface {
OnLoad(fn func(Page))

// Emitted when an uncaught exception happens within the page.
OnPageError(fn func(Error))
OnPageError(fn func(*Error))

// Emitted when the page opens a new tab or window. This event is emitted in addition to the [BrowserContext.OnPage],
// but only for popups relevant to this page.
Expand Down Expand Up @@ -3359,7 +3366,7 @@ type Page interface {
// har: Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If `path` is a
// relative path, then it is resolved relative to the current working directory.
//
// [Replaying from HAR]: https://playwright.dev/docs/network#replaying-from-har
// [Replaying from HAR]: https://playwright.dev/docs/mock#replaying-from-har
// [this]: https://github.com/microsoft/playwright/issues/1090
RouteFromHAR(har string, options ...PageRouteFromHAROptions) error

Expand Down Expand Up @@ -3408,8 +3415,12 @@ type Page interface {
// [locators]: https://playwright.dev/docs/locators
SetChecked(selector string, checked bool, options ...PageSetCheckedOptions) error

// This method internally calls [document.Write()],
// inheriting all its specific characteristics and behaviors.
//
// html: HTML markup to assign to the page.
//
// [document.Write()]: https://developer.mozilla.org/en-US/docs/Web/API/Document/write
SetContent(html string, options ...PageSetContentOptions) error

// This setting will change the default maximum navigation time for the following methods and related shortcuts:
Expand Down
Loading

0 comments on commit 8575a75

Please sign in to comment.