Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 93b3bd4

Browse files
committed
Add testPageInputSpecialCharacters
1 parent 853f7e8 commit 93b3bd4

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

tests/page_input_value_test.go

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,58 @@ import (
2424
_ "embed"
2525
"testing"
2626

27+
"github.com/grafana/xk6-browser/api"
2728
"github.com/grafana/xk6-browser/testutils/browsertest"
2829
"github.com/stretchr/testify/assert"
2930
)
3031

31-
func TestPageInputValue(t *testing.T) {
32+
var pageInputTests = map[string]func(*testing.T, api.Browser){
33+
"value": testPageInputValue,
34+
"special_characters": testPageInputSpecialCharacters,
35+
}
36+
37+
func TestPageInput(t *testing.T) {
3238
bt := browsertest.NewBrowserTest(t)
33-
defer bt.Browser.Close()
39+
t.Cleanup(bt.Browser.Close)
3440

35-
t.Run("Page.inputValue", func(t *testing.T) {
36-
t.Run("should work", func(t *testing.T) { testPageInputValue(t, bt) })
37-
})
41+
for name, test := range pageInputTests {
42+
t.Run(name, func(t *testing.T) {
43+
test(t, bt.Browser)
44+
})
45+
}
3846
}
3947

40-
func testPageInputValue(t *testing.T, bt *browsertest.BrowserTest) {
41-
p := bt.Browser.NewPage(nil)
48+
func testPageInputValue(t *testing.T, b api.Browser) {
49+
p := b.NewPage(nil)
4250
defer p.Close(nil)
4351

4452
p.SetContent(`
45-
<input value="hello1">
46-
<select><option value="hello2" selected></option></select>
47-
<textarea>hello3</textarea>
48-
`, nil)
53+
<input value="hello1">
54+
<select><option value="hello2" selected></option></select>
55+
<textarea>hello3</textarea>
56+
`, nil)
4957

5058
value := p.InputValue("input", nil)
51-
assert.Equal(t, value, "hello1", `expected input value "hello1", got %q`, value)
59+
assert.Equal(t, value, "hello1")
5260

5361
value = p.InputValue("select", nil)
54-
assert.Equal(t, value, "hello2", `expected input value "hello2", got %q`, value)
62+
assert.Equal(t, value, "hello2")
5563

5664
value = p.InputValue("textarea", nil)
57-
assert.Equal(t, value, "hello3", `expected input value "hello3", got %q`, value)
65+
assert.Equal(t, value, "hello3")
66+
}
67+
68+
// test for: https://github.com/grafana/xk6-browser/issues/132
69+
func testPageInputSpecialCharacters(t *testing.T, b api.Browser) {
70+
const want = "test@k6.io"
71+
72+
p := b.NewPage(nil)
73+
defer p.Close(nil)
74+
75+
p.SetContent(`<input id="username">`, nil)
76+
el := p.Query("#username")
77+
el.Type(want, nil)
78+
79+
got := el.InputValue(nil)
80+
assert.Equal(t, want, got)
5881
}

0 commit comments

Comments
 (0)