Skip to content

Commit

Permalink
Refactor isVisible to return an error
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur22 committed Nov 23, 2023
1 parent 04b9035 commit 36f4fdb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions common/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -1283,19 +1283,19 @@ func (f *Frame) isHidden(selector string, opts *FrameIsHiddenOptions) (bool, err

// IsVisible returns true if the first element that matches the selector
// is visible. Otherwise, returns false.
func (f *Frame) IsVisible(selector string, opts goja.Value) bool {
func (f *Frame) IsVisible(selector string, opts goja.Value) (bool, error) {
f.log.Debugf("Frame:IsVisible", "fid:%s furl:%q sel:%q", f.ID(), f.URL(), selector)

popts := NewFrameIsVisibleOptions(f.defaultTimeout())
if err := popts.Parse(f.ctx, opts); err != nil {
k6ext.Panic(f.ctx, "parsing is visible options: %w", err)
return false, fmt.Errorf("parsing is visible options: %w", err)
}
visible, err := f.isVisible(selector, popts)
if err != nil {
k6ext.Panic(f.ctx, "checking is %q visible: %w", selector, err)
return false, err
}

return visible
return visible, nil
}

func (f *Frame) isVisible(selector string, opts *FrameIsVisibleOptions) (bool, error) {
Expand Down
4 changes: 3 additions & 1 deletion common/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,9 @@ func (p *Page) IsHidden(selector string, opts goja.Value) bool {
return p.MainFrame().IsHidden(selector, opts)
}

func (p *Page) IsVisible(selector string, opts goja.Value) bool {
// IsVisible will look for an element in the dom with given selector. It will
// not wait for a match to occur. If no elements match `false` will be returned.
func (p *Page) IsVisible(selector string, opts goja.Value) (bool, error) {
p.logger.Debugf("Page:IsVisible", "sid:%v selector:%s", p.sessionID(), selector)

return p.MainFrame().IsVisible(selector, opts)
Expand Down

0 comments on commit 36f4fdb

Please sign in to comment.