Skip to content

Commit

Permalink
Add integration tests for isVisible
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur22 committed Nov 23, 2023
1 parent bf55c56 commit be914dc
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1235,3 +1235,70 @@ func performPingTest(t *testing.T, tb *testBrowser, page *common.Page, iteration

return ms / int64(iterations)
}

func TestPageIsVisible(t *testing.T) {
t.Parallel()

testCases := []struct {
name string
selector string
options common.FrameIsVisibleOptions
want bool
wantErr string
}{
{
name: "visible",
selector: "div[id=my-div]",
want: true,
},
{
name: "not_visible",
selector: "div[id=my-div-3]",
want: false,
},
{
name: "not_found",
selector: "div[id=does-not-exist]",
want: false,
},
{
name: "first_div",
selector: "div",
want: true,
},
{
name: "first_div",
selector: "div",
options: common.FrameIsVisibleOptions{
FrameBaseOptions: common.FrameBaseOptions{
Strict: true,
},
},
wantErr: "error:strictmodeviolation",
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

tb := newTestBrowser(t, withFileServer())

page := tb.NewPage(nil)

_, err := page.Goto(tb.staticURL("visible.html"), nil)
require.NoError(t, err)

got, err := page.IsVisible(tc.selector, tb.toGojaValue(tc.options))

if tc.wantErr != "" {
assert.ErrorContains(t, err, tc.wantErr)
return
}

assert.NoError(t, err)
assert.Equal(t, tc.want, got)
})
}
}
8 changes: 8 additions & 0 deletions tests/static/visible.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html lang="en">
<head></head>
<body>
<div id='my-div'>My DIV</div>
<div id='my-div-2'>My DIV 2</div>
<div id='my-div-3' style='display: none;'>My DIV 3</div>
</body>
</html>

0 comments on commit be914dc

Please sign in to comment.