Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #108 from folbricht/chromeoptions
Browse files Browse the repository at this point in the history
Add ChromeOptions
  • Loading branch information
sclevine authored Jun 19, 2017
2 parents b933c81 + 5d090ee commit dfc6680
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type config struct {
RejectInvalidSSL bool
Debug bool
HTTPClient *http.Client
ChromeOptions map[string]interface{}
}

// An Option specifies configuration for a new WebDriver or Page.
Expand All @@ -31,6 +32,16 @@ func Timeout(seconds int) Option {
}
}

// ChromeOptions is used to pass additional options to Chrome via ChromeDriver.
func ChromeOptions(opt string, value interface{}) Option {
return func(c *config) {
if c.ChromeOptions == nil {
c.ChromeOptions = make(map[string]interface{})
}
c.ChromeOptions[opt] = value
}
}

// Desired provides an Option for specifying desired WebDriver Capabilities.
func Desired(capabilities Capabilities) Option {
return func(c *config) {
Expand Down Expand Up @@ -72,6 +83,9 @@ func (c *config) Capabilities() Capabilities {
if c.BrowserName != "" {
merged.Browser(c.BrowserName)
}
if c.ChromeOptions != nil {
merged["chromeOptions"] = c.ChromeOptions
}
if c.RejectInvalidSSL {
merged.Without("acceptSslCerts")
}
Expand Down
15 changes: 15 additions & 0 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ var _ = Describe("Options", func() {
})
})

Describe("#ChromeOptions", func() {
It("should return an Option with ChromeOptions set", func() {
config := NewTestConfig()
ChromeOptions("args", []string{"v1", "v2"})(config)
Expect(config.ChromeOptions["args"]).To(Equal([]string{"v1", "v2"}))
ChromeOptions("other", "value")(config)
Expect(config.ChromeOptions["args"]).To(Equal([]string{"v1", "v2"}))
Expect(config.ChromeOptions["other"]).To(Equal("value"))
})
})

Describe("#Merge", func() {
It("should apply any provided options to an existing config", func() {
config := NewTestConfig()
Expand All @@ -85,6 +96,10 @@ var _ = Describe("Options", func() {
RejectInvalidSSL(config)
Expect(config.Capabilities()["browserName"]).To(Equal("some other browser"))
Expect(config.Capabilities()["acceptSslCerts"]).To(BeFalse())
ChromeOptions("args", "someArg")(config)
Expect(config.Capabilities()["chromeOptions"]).To(
Equal(map[string]interface{}{"args": "someArg"}),
)
})
})
})

0 comments on commit dfc6680

Please sign in to comment.