This repository has been archived by the owner on Jun 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
/
agouti.go
123 lines (114 loc) · 4.47 KB
/
agouti.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
118
119
120
121
122
123
// Package agouti is a universal WebDriver client for Go.
// It extends the agouti/api package to provide a feature-rich interface for
// controlling a web browser.
package agouti
import (
"fmt"
"path/filepath"
"runtime"
)
// PhantomJS returns an instance of a PhantomJS WebDriver.
//
// Provided Options will apply as default arguments for new pages.
// New pages will accept invalid SSL certificates by default. This
// may be disabled using the RejectInvalidSSL Option.
//
// The RejectInvalidSSL Option must be provided to the PhantomJS function
// (and not the NewPage method) for this Option to take effect on any
// PhantomJS page.
func PhantomJS(options ...Option) *WebDriver {
command := []string{"phantomjs", "--webdriver={{.Address}}"}
defaultOptions := config{}.Merge(options)
if !defaultOptions.RejectInvalidSSL {
command = append(command, "--ignore-ssl-errors=true")
}
return NewWebDriver("http://{{.Address}}", command, options...)
}
// ChromeDriver returns an instance of a ChromeDriver WebDriver.
//
// Provided Options will apply as default arguments for new pages.
// New pages will accept invalid SSL certificates by default. This
// may be disabled using the RejectInvalidSSL Option.
func ChromeDriver(options ...Option) *WebDriver {
var binaryName string
if runtime.GOOS == "windows" {
binaryName = "chromedriver.exe"
} else {
binaryName = "chromedriver"
}
command := []string{binaryName, "--port={{.Port}}"}
return NewWebDriver("http://{{.Address}}", command, options...)
}
// EdgeDriver returns an instance of a EdgeDriver WebDriver.
//
// Provided Options will apply as default arguments for new pages.
// New pages will accept invalid SSL certificates by default. This
// may be disabled using the RejectInvalidSSL Option.
func EdgeDriver(options ...Option) *WebDriver {
var binaryName string
if runtime.GOOS == "windows" {
binaryName = "MicrosoftWebDriver.exe"
} else {
return nil
}
command := []string{binaryName, "--port={{.Port}}"}
// Using {{.Address}} means using 127.0.0.1
// But MicrosoftWebDriver only supports localhost, not 127.0.0.1
return NewWebDriver("http://localhost:{{.Port}}", command, options...)
}
// Selenium returns an instance of a Selenium WebDriver.
//
// Provided Options will apply as default arguments for new pages.
// New pages will accept invalid SSL certificates by default. This
// may be disabled using the RejectInvalidSSL Option.
func Selenium(options ...Option) *WebDriver {
command := []string{"selenium-server", "-port", "{{.Port}}"}
return NewWebDriver("http://{{.Address}}/wd/hub", command, options...)
}
// Selendroid returns an instance of a Selendroid WebDriver.
//
// Provided Options will apply as default arguments for new pages.
// New pages will accept invalid SSL certificates by default. This
// may be disabled using the RejectInvalidSSL Option.
//
// The jarFile is a relative or absolute path to Selendroid JAR file.
// Selendroid will return nil if an invalid path is provided.
func Selendroid(jarFile string, options ...Option) *WebDriver {
absJARPath, err := filepath.Abs(jarFile)
if err != nil {
return nil
}
command := []string{
"java",
"-jar", absJARPath,
"-port", "{{.Port}}",
}
options = append([]Option{Timeout(90), Browser("android")}, options...)
return NewWebDriver("http://{{.Address}}/wd/hub", command, options...)
}
// SauceLabs opens a Sauce Labs session and returns a *Page. Does not support Sauce Connect.
//
// This method takes the same Options as NewPage. Passing the Desired Option will
// completely override the provided name, platform, browser, and version.
func SauceLabs(name, platform, browser, version, username, accessKey string, options ...Option) (*Page, error) {
url := fmt.Sprintf("http://%s:%[email protected]/wd/hub", username, accessKey)
capabilities := NewCapabilities().Browser(browser).Platform(platform).Version(version)
capabilities["name"] = name
return NewPage(url, append([]Option{Desired(capabilities)}, options...)...)
}
// GeckoDriver returns an instance of a geckodriver WebDriver which supports
// gecko based brwoser like Firefox.
//
// Provided Options will apply as default arguments for new pages.
//
// See https://github.com/mozilla/geckodriver for geckodriver details.
func GeckoDriver(options ...Option) *WebDriver {
var binaryName string
if runtime.GOOS == "windows" {
binaryName = "geckodriver.exe"
} else {
binaryName = "geckodriver"
}
command := []string{binaryName, "--port={{.Port}}"}
return NewWebDriver("http://{{.Address}}", command, options...)
}