-
Notifications
You must be signed in to change notification settings - Fork 1
/
capabilities.go
117 lines (94 loc) · 3.04 KB
/
capabilities.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package webdriver
type Capabilities map[string]interface{}
// SetBrowserName sets the desired browser name.
func (c Capabilities) SetBrowserName(name string) Capabilities {
c["browserName"] = name
return c
}
// A ProxyConfig instance defines the desired proxy configuration the WebDriver
// should use to proxy a Page.
//
// See: https://www.w3.org/TR/webdriver/#proxy
type ProxyConfig struct {
ProxyType string `json:"proxyType"`
ProxyAutoconfigURL string `json:"proxyAutoconfigUrl,omitempty"`
FTPProxy string `json:"ftpProxy,omitempty"`
HTTPProxy string `json:"httpProxy,omitempty"`
SSLProxy string `json:"sslProxy,omitempty"`
SOCKSProxy string `json:"socksProxy,omitempty"`
SOCKSUsername string `json:"socksUsername,omitempty"`
SOCKSPassword string `json:"socksPassword,omitempty"`
NoProxy string `json:"noProxy,omitempty"`
}
// Proxy sets the desired proxy configuration.
func (c Capabilities) SetProxy(p ProxyConfig) Capabilities {
c["proxy"] = p
return c
}
// SetBrowserVersion sets the desired browser version.
func (c Capabilities) SetBrowserVersion(version string) Capabilities {
c["browserVersion"] = version
return c
}
// SetPlatformName sets the desired browser platform.
func (c Capabilities) SetPlatformName(platform string) Capabilities {
c["platformName"] = platform
return c
}
func (c Capabilities) SetAcceptInsecureCerts(acceptInsecureCerts bool) Capabilities {
c["acceptInsecureCerts"] = acceptInsecureCerts
return c
}
func (c Capabilities) SetWebSocketURL(webSocketURL bool) Capabilities {
c["webSocketUrl"] = webSocketURL
return c
}
func (c Capabilities) WebSocketURL() string {
if val, ok := c["webSocketUrl"]; ok {
return val.(string)
}
return ""
}
// Sets an arbitrary key-value pair
func (c Capabilities) Set(key string, value string) Capabilities {
c[key] = value
return c
}
/****************************************************************************************************************
* Chrome Options *
****************************************************************************************************************/
type ChromeOptions map[string]interface{}
func (c Capabilities) SetChromeOptions(co ChromeOptions) Capabilities {
c["goog:chromeOptions"] = co
return c
}
func (c Capabilities) ChromeOptions() ChromeOptions {
if opts, ok := c["goog:chromeOptions"]; ok {
return opts.(map[string]interface{})
}
return nil
}
func (co ChromeOptions) AddArg(arg string) ChromeOptions {
if _, ok := co["args"]; ok {
co["args"] = append(co["args"].([]string), arg)
} else {
co["args"] = []string{arg}
}
return co
}
func (co ChromeOptions) SetBinary(binary string) ChromeOptions {
co["binary"] = binary
return co
}
func (co ChromeOptions) Binary() string {
if val, ok := co["binary"]; ok {
return val.(string)
}
return ""
}
func (co ChromeOptions) DebuggerAddress() string {
if val, ok := co["debuggerAddress"]; ok {
return val.(string)
}
return ""
}