diff --git a/options.go b/options.go index 4c42296..34028cf 100644 --- a/options.go +++ b/options.go @@ -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. @@ -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) { @@ -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") } diff --git a/options_test.go b/options_test.go index 6f3480c..9e701a4 100644 --- a/options_test.go +++ b/options_test.go @@ -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() @@ -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"}), + ) }) }) })