forked from sclevine/agouti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
79 lines (68 loc) · 1.88 KB
/
options.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
package agouti
import (
"net/http"
"time"
)
type config struct {
Timeout time.Duration
DesiredCapabilities Capabilities
BrowserName string
RejectInvalidSSL bool
Debug bool
HTTPClient *http.Client
}
// An Option specifies configuration for a new WebDriver or Page.
type Option func(*config)
// Browser provides an Option for specifying a browser.
func Browser(name string) Option {
return func(c *config) {
c.BrowserName = name
}
}
// Timeout provides an Option for specifying a timeout in seconds.
func Timeout(seconds int) Option {
return func(c *config) {
c.Timeout = time.Duration(seconds) * time.Second
}
}
// Desired provides an Option for specifying desired WebDriver Capabilities.
func Desired(capabilities Capabilities) Option {
return func(c *config) {
c.DesiredCapabilities = capabilities
}
}
// RejectInvalidSSL is an Option specifying that the WebDriver should reject
// invalid SSL certificates. All WebDrivers should accept invalid SSL certificates
// by default. See: http://www.w3.org/TR/webdriver/#invalid-ssl-certificates
var RejectInvalidSSL Option = func(c *config) {
c.RejectInvalidSSL = true
}
// Debug is an Option that connects the running WebDriver to stdout and stdin.
var Debug Option = func(c *config) {
c.Debug = true
}
// HTTPClient provides an Option for specifying a *http.Client
func HTTPClient(client *http.Client) Option {
return func(c *config) {
c.HTTPClient = client
}
}
func (c config) Merge(options []Option) *config {
for _, option := range options {
option(&c)
}
return &c
}
func (c *config) Capabilities() Capabilities {
merged := Capabilities{"acceptSslCerts": true}
for feature, value := range c.DesiredCapabilities {
merged[feature] = value
}
if c.BrowserName != "" {
merged.Browser(c.BrowserName)
}
if c.RejectInvalidSSL {
merged.Without("acceptSslCerts")
}
return merged
}