Skip to content

Commit

Permalink
Add page.waitForSelector integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
ka3de committed Sep 27, 2023
1 parent 30b0798 commit 9e5893a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1044,3 +1044,55 @@ func TestPageTimeout(t *testing.T) {
})
}
}

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

testCases := []struct {
name string
url string
opts map[string]any
selector string
errAssert func(*testing.T, error)
}{
{
name: "should wait for selector",
url: "wait_for.html",
selector: "#my-div",
errAssert: func(t *testing.T, e error) {
t.Helper()
assert.Nil(t, e)
},
},
{
name: "should TO waiting for selector",
url: "wait_for.html",
opts: map[string]any{
// set a timeout smaller than the time
// it takes the element to show up
"timeout": "50",
},
selector: "#my-div",
errAssert: func(t *testing.T, e error) {
t.Helper()
assert.ErrorContains(t, e, "timed out after")
},
},
}

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(tc.url), nil)
require.NoError(t, err)

_, err = page.WaitForSelector(tc.selector, tb.toGojaValue(tc.opts))
tc.errAssert(t, err)
})
}
}
15 changes: 15 additions & 0 deletions tests/static/wait_for.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html lang="en">
<head></head>
<body>
<div id='my-div' style='display: none;'>My DIV</div>
<script>
function showDiv() {
setTimeout(function() {
document.getElementById('my-div').style.display = 'block';
}, 200);
}

showDiv();
</script>
</body>
</html>

0 comments on commit 9e5893a

Please sign in to comment.