Skip to content

Commit

Permalink
Refactor isHidden to return an error
Browse files Browse the repository at this point in the history
This is for frame, elementHandle and page.
  • Loading branch information
ankur22 committed Nov 23, 2023
1 parent b971314 commit a2b836a
Show file tree
Hide file tree
Showing 2 changed files with 8 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 @@ -1242,19 +1242,19 @@ func (f *Frame) isDisabled(selector string, opts *FrameIsDisabledOptions) (bool,

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

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

return hidden
return hidden, nil
}

func (f *Frame) isHidden(selector string, opts *FrameIsHiddenOptions) (bool, error) {
Expand Down
5 changes: 4 additions & 1 deletion common/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,10 @@ func (p *Page) IsEnabled(selector string, opts goja.Value) bool {
return p.MainFrame().IsEnabled(selector, opts)
}

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

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

0 comments on commit a2b836a

Please sign in to comment.