-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdriver.go
78 lines (66 loc) · 1.38 KB
/
driver.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
package webtester
import (
"os"
"strings"
"testing"
"github.com/bborbe/webdriver"
)
type Driver struct {
testing.TB
webDriver webdriver.WebDriver
sessions []*webdriver.Session
}
func Setup(tb testing.TB, path string) *Driver {
tb.Helper()
webDriver := webdriver.NewChromeDriver(path)
err := webDriver.Start()
if err != nil {
tb.Fatal(err)
}
return &Driver{
TB: tb,
webDriver: webDriver,
}
}
func (d *Driver) TearDown() {
for _, session := range d.sessions {
session.Delete()
}
d.webDriver.Stop()
}
func (d *Driver) OpenBrowser() *Browser {
d.Helper()
desired := webdriver.Capabilities{"Platform": "Linux"}
required := webdriver.Capabilities{}
var args []string
if os.Getenv("CI") != "" {
args = []string{
"start-maximized",
"enable-automation",
"--headless",
"--no-sandbox",
"--disable-infobars",
"--disable-extensions",
"--disable-dev-shm-usage",
"--disable-browser-side-navigation",
"--disable-gpu",
"--ignore-certificate-errors",
"--ignore-ssl-errors",
}
}
if v := os.Getenv("CHROME_OPTIONS_ARGS"); v != "" {
args = strings.Split(v, " ")
}
if args != nil {
desired["chromeOptions"] = webdriver.Capabilities{"args": args}
}
session, err := d.webDriver.NewSession(desired, required)
if err != nil {
d.Fatal(err)
}
d.sessions = append(d.sessions, session)
return &Browser{
TB: d.TB,
session: session,
}
}