forked from sclevine/agouti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
agouti.go
46 lines (40 loc) · 1.98 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
// Package agouti is a universal WebDriver client for Go.
// It extends the api package to provide a feature-rich interface for
// controlling a web browser.
package agouti
import "fmt"
// PhantomJS returns an instance of a PhantomJS WebDriver.
// The RejectInvalidSSL Option must be provided to this 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 {
command := []string{"chromedriver", "--silent", "--port={{.Port}}"}
return NewWebDriver("http://{{.Address}}", 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...)
}
// SauceLabs opens a Sauce Labs session and returns a *Page. Does not support Sauce Connect.
func SauceLabs(name, platform, browser, version, username, accessKey string) (*Page, error) {
url := fmt.Sprintf("http://%s:%s@ondemand.saucelabs.com/wd/hub", username, accessKey)
capabilities := NewCapabilities().Browser(name).Platform(platform).Version(version)
capabilities["name"] = name
return NewPage(url, Desired(capabilities))
}