Skip to content

Commit

Permalink
Turn Browser.Version to return err
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed May 30, 2024
1 parent 07fc248 commit df5aade
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion browser/browser_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func mapBrowser(vu moduleVU) mapping { //nolint:funlen,cyclop
if err != nil {
return "", err
}
return b.Version(), nil
return b.Version() //nolint:wrapcheck
},
"newPage": func(opts goja.Value) (mapping, error) {
b, err := vu.browser()
Expand Down
2 changes: 1 addition & 1 deletion browser/mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ type browserAPI interface {
NewPage(opts goja.Value) (*common.Page, error)
On(string) (bool, error)
UserAgent() (string, error)
Version() string
Version() (string, error)
}

// browserContextAPI is the public interface of a CDP browser context.
Expand Down
10 changes: 5 additions & 5 deletions common/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,17 +638,17 @@ func (b *Browser) UserAgent() (string, error) {
}

// Version returns the controlled browser's version.
func (b *Browser) Version() string {
func (b *Browser) Version() (string, error) {
action := cdpbrowser.GetVersion()
_, product, _, _, _, err := action.Do(cdp.WithExecutor(b.ctx, b.conn))
_, product, _, _, _, err := action.Do(cdp.WithExecutor(b.ctx, b.conn)) //nolint:dogsled
if err != nil {
k6ext.Panic(b.ctx, "getting browser version: %w", err)
return "", fmt.Errorf("getting browser version: %w", err)
}
i := strings.Index(product, "/")
if i == -1 {
return product
return product, nil
}
return product[i+1:]
return product[i+1:], nil
}

// WsURL returns the Websocket URL that the browser is listening on for CDP clients.
Expand Down
6 changes: 4 additions & 2 deletions tests/browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ func TestBrowserVersion(t *testing.T) {
t.Parallel()

const re = `^\d+\.\d+\.\d+\.\d+$`
r, _ := regexp.Compile(re)
ver := newTestBrowser(t).Version()
r, err := regexp.Compile(re) //nolint:gocritic
require.NoError(t, err)
ver, err := newTestBrowser(t).Version()
require.NoError(t, err)
assert.Regexp(t, r, ver, "expected browser version to match regex %q, but found %q", re, ver)
}

Expand Down

0 comments on commit df5aade

Please sign in to comment.