@@ -24,35 +24,58 @@ import (
24
24
_ "embed"
25
25
"testing"
26
26
27
+ "github.com/grafana/xk6-browser/api"
27
28
"github.com/grafana/xk6-browser/testutils/browsertest"
28
29
"github.com/stretchr/testify/assert"
29
30
)
30
31
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 ) {
32
38
bt := browsertest .NewBrowserTest (t )
33
- defer bt .Browser .Close ( )
39
+ t . Cleanup ( bt .Browser .Close )
34
40
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
+ }
38
46
}
39
47
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 )
42
50
defer p .Close (nil )
43
51
44
52
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 )
49
57
50
58
value := p .InputValue ("input" , nil )
51
- assert .Equal (t , value , "hello1" , `expected input value "hello1", got %q` , value )
59
+ assert .Equal (t , value , "hello1" )
52
60
53
61
value = p .InputValue ("select" , nil )
54
- assert .Equal (t , value , "hello2" , `expected input value "hello2", got %q` , value )
62
+ assert .Equal (t , value , "hello2" )
55
63
56
64
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 )
58
81
}
0 commit comments