-
Notifications
You must be signed in to change notification settings - Fork 410
/
sauce_test.go
89 lines (82 loc) · 2.4 KB
/
sauce_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
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
package selenium_test
import (
"flag"
"fmt"
"strings"
"testing"
"github.com/blang/semver"
"github.com/tebeka/selenium"
"github.com/tebeka/selenium/internal/seleniumtest"
"github.com/tebeka/selenium/sauce"
)
var (
enableSauce = flag.Bool("experimental_enable_sauce", false, "If true, perform integration tests on SauceLabs remote infrastructure.")
sauceUserName = flag.String("sauce_user_name", "", "The username to use for SauceLabs.")
sauceAccessKey = flag.String("sauce_access_key", "", "The access key to use for SauceLabs.")
sauceConnectPath = flag.String("sauce_connect_path", "vendor/sauce-connect/bin/sc", "The path to the Sauce Connect binary.")
)
func TestSauce(t *testing.T) {
if !*enableSauce {
t.Skip("Skipping Sauce tests. Enable via --experimental_sauce_tests")
}
if testing.Verbose() {
selenium.SetDebug(true)
}
if *sauceUserName == "" {
t.Fatalf("--sauce_user_name is required.")
}
if *sauceAccessKey == "" {
t.Fatalf("--sauce_access_key is required.")
}
addr := sauce.Addr(*sauceUserName, *sauceAccessKey)
if *sauceConnectPath != "" {
port, err := pickUnusedPort()
if err != nil {
t.Fatalf("pickUnusedPort() returned error: %s", err)
}
sc := sauce.Connect{
Path: *sauceConnectPath,
UserName: *sauceUserName,
AccessKey: *sauceAccessKey,
SeleniumPort: port,
QuitProcessUponExit: true,
}
if testing.Verbose() {
sc.ExtraVerbose = true
}
if err := sc.Start(); err != nil {
t.Fatalf("sc.Start() returned error: %s", err)
}
defer func() {
if err := sc.Stop(); err != nil {
t.Fatalf("sc.Stop() returned error: %s", err)
}
}()
addr = sc.Addr()
}
const browser = "Firefox"
for _, tc := range []struct {
version, platform, selenium string
}{
{"Latest", "Windows 10", "3.4.0"},
{"45.0", "Linux", "2.53.1"},
} {
name := fmt.Sprintf("%s/%s/%s/%s", browser, tc.version, tc.platform, tc.selenium)
browser, version := strings.ToLower(browser), strings.ToLower(tc.version)
t.Run(name, func(t *testing.T) {
c := seleniumtest.Config{
Browser: browser,
SeleniumVersion: semver.MustParse(tc.selenium),
Sauce: &sauce.Capabilities{
Browser: browser,
Version: version,
Platform: tc.platform,
SeleniumVersion: tc.selenium,
},
Addr: addr,
}
seleniumtest.RunCommonTests(t, c)
seleniumtest.RunFirefoxTests(t, c)
})
}
}