Skip to content

Commit

Permalink
Refactor locator.isHidden 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 2fbd59c commit a86503d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 4 additions & 4 deletions common/locator.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,19 @@ func (l *Locator) isVisible(opts *FrameIsVisibleOptions) (bool, error) {

// IsHidden returns true if the element matches the locator's
// selector and is hidden. Otherwise, returns false.
func (l *Locator) IsHidden(opts goja.Value) bool {
func (l *Locator) IsHidden(opts goja.Value) (bool, error) {
l.log.Debugf("Locator:IsHidden", "fid:%s furl:%q sel:%q opts:%+v", l.frame.ID(), l.frame.URL(), l.selector, opts)

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

return hidden
return hidden, nil
}

// isHidden is like IsHidden but takes parsed options and does not
Expand Down
8 changes: 6 additions & 2 deletions tests/locator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func TestLocatorElementState(t *testing.T) {
{
"hidden",
`() => document.getElementById('inputText').style.visibility = 'hidden'`,
func(l *common.Locator) bool { return !l.IsHidden(nil) },
func(l *common.Locator) bool { resp, _ := l.IsHidden(nil); return !resp },
},
{
"readOnly",
Expand Down Expand Up @@ -398,7 +398,11 @@ func TestLocatorElementState(t *testing.T) {
"IsDisabled", func(l *common.Locator, tb *testBrowser) { l.IsDisabled(timeout(tb)) },
},
{
"IsHidden", func(l *common.Locator, tb *testBrowser) { l.IsHidden(timeout(tb)) },
"IsHidden", func(l *common.Locator, tb *testBrowser) {
if _, err := l.IsHidden(timeout(tb)); err != nil {
panic(err)
}
},
},
}
for _, tt := range sanityTests {
Expand Down

0 comments on commit a86503d

Please sign in to comment.