-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchromedriver.go
62 lines (48 loc) · 1.07 KB
/
chromedriver.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
package webdriver
import (
"fmt"
"time"
)
type chromeDriver struct {
webDriver
path string
}
func NewChromeDriver(path string, optFns ...func(o *Options)) (WebDriver, error) {
opts := Options{
Port: 0,
BootTimeout: 10 * time.Second, //nolint gomnd
}
for _, fn := range optFns {
fn(&opts)
}
if opts.Port == 0 {
port, err := GetFreePort()
if err != nil {
return nil, err
}
opts.Port = port
}
cd := &chromeDriver{
path: path,
}
cd.port = opts.Port
cd.service = NewService(path, []string{fmt.Sprintf("--port=%d", opts.Port)})
cd.timeout = opts.BootTimeout
cd.client = NewRestClient(fmt.Sprintf("http://127.0.0.1:%d", opts.Port))
return cd, nil
}
func (d *chromeDriver) NewSession(optFns ...func(o *SessionOptions)) (*Session, error) {
opts := SessionOptions{
AlwaysMatch: newDefaultChromeDriverCapabilities(),
}
for _, fn := range optFns {
fn(&opts)
}
return d.newSession(opts)
}
func newDefaultChromeDriverCapabilities() Capabilities {
caps := Capabilities{}
caps.SetBrowserName("chrome")
caps.SetWebSocketURL(true)
return caps
}