-
Notifications
You must be signed in to change notification settings - Fork 73
/
api_test.go
59 lines (46 loc) · 1.37 KB
/
api_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package selenium
import (
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestExecuteScript_Args(t *testing.T) {
setup()
defer teardown()
input := map[string]interface{}{"script": "return 'foo'", "args": []interface{}{}}
mux.HandleFunc("/session/123/execute", func(w http.ResponseWriter, r *http.Request) {
var v map[string]interface{}
json.NewDecoder(r.Body).Decode(&v)
testMethod(t, r, "POST")
testHeader(t, r, "content-type", "application/json")
testHeader(t, r, "accept", "application/json")
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
fmt.Fprint(w, `{"status": 0, "value": "foo"}`)
})
result, err := client.ExecuteScript("return 'foo'", []interface{}{})
if err != nil {
t.Errorf("ExecuteScript returned error: %v", err)
}
want := "foo"
if !reflect.DeepEqual(result, want) {
t.Errorf("ExecuteScript returned %+v, want %+v", result, want)
}
}
func TestExecuteScript_NoArgs(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/session/123/execute", func(w http.ResponseWriter, r *http.Request) {
var v map[string]interface{}
json.NewDecoder(r.Body).Decode(&v)
args := []interface{}{}
if !reflect.DeepEqual(v["args"], args) {
t.Errorf("Args = %+v, want %+v", v["args"], args)
}
fmt.Fprint(w, `{"status": 0, "value": "foo"}`)
})
client.ExecuteScript("return 'foo'", nil)
}