Skip to content

Commit

Permalink
Improve TestPageFill comment
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Aug 31, 2023
1 parent 06e2e5a commit 122818f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
9 changes: 7 additions & 2 deletions tests/element_handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ func TestElementHandleIsChecked(t *testing.T) {
}

func TestElementHandleQueryAll(t *testing.T) {
// tests are faster than parallel execution.
// do not make this test parallel.
t.Parallel()

const (
wantLiLen = 2
Expand All @@ -316,6 +315,8 @@ func TestElementHandleQueryAll(t *testing.T) {
`, nil)

t.Run("element_handle", func(t *testing.T) {
t.Parallel()

el, err := p.Query("#aul")
require.NoError(t, err)

Expand All @@ -325,12 +326,16 @@ func TestElementHandleQueryAll(t *testing.T) {
assert.Equal(t, wantLiLen, len(els))
})
t.Run("page", func(t *testing.T) {
t.Parallel()

els, err := p.QueryAll(query)
require.NoError(t, err)

assert.Equal(t, wantLiLen, len(els))
})
t.Run("frame", func(t *testing.T) {
t.Parallel()

els, err := p.MainFrame().QueryAll(query)
require.NoError(t, err)
assert.Equal(t, wantLiLen, len(els))
Expand Down
35 changes: 25 additions & 10 deletions tests/page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,17 +350,11 @@ func TestPageInputSpecialCharacters(t *testing.T) {
}

func TestPageFill(t *testing.T) {
// these tests are not parallel by intention because
// they're testing the same page instance and they're
// faster when run sequentially.
t.Parallel()

p := newTestBrowser(t).NewPage(nil)
p.SetContent(`
<input id="text" type="text" value="something" />
<input id="date" type="date" value="2012-03-12"/>
<input id="number" type="number" value="42"/>
<input id="unfillable" type="radio" />
`, nil)
// Subtests race with each other since they change the same page content.
// We could make each subtest to create and run their own browsers
// (and not share them), but that would make the test run 2X.

happy := []struct{ name, selector, value string }{
{name: "text", selector: "#text", value: "fill me up"},
Expand All @@ -373,13 +367,34 @@ func TestPageFill(t *testing.T) {
{name: "unfillable", selector: "#unfillable", value: "can't touch this"},
}
for _, tt := range happy {
tt := tt
t.Run("happy/"+tt.name, func(t *testing.T) {
t.Parallel()

p := newTestBrowser(t).NewPage(nil)
p.SetContent(`
<input id="text" type="text" value="something" />
<input id="date" type="date" value="2012-03-12"/>
<input id="number" type="number" value="42"/>
<input id="unfillable" type="radio" />
`, nil)

p.Fill(tt.selector, tt.value, nil)
require.Equal(t, tt.value, p.InputValue(tt.selector, nil))
})
}
for _, tt := range sad {
tt := tt
t.Run("sad/"+tt.name, func(t *testing.T) {
t.Parallel()

p := newTestBrowser(t).NewPage(nil)
p.SetContent(`
<input id="text" type="text" value="something" />
<input id="date" type="date" value="2012-03-12"/>
<input id="number" type="number" value="42"/>
<input id="unfillable" type="radio" />
`, nil)
require.Panics(t, func() { p.Fill(tt.selector, tt.value, nil) })
})
}
Expand Down

0 comments on commit 122818f

Please sign in to comment.