From 2b2694f7d7be2f83aadeaa479880cadf06546262 Mon Sep 17 00:00:00 2001 From: hupe1980 Date: Mon, 20 Feb 2023 21:03:22 +0100 Subject: [PATCH] Add chromeOptions --- capabilities.go | 22 ++++++++++++++++++++++ capabilities_test.go | 22 ++++++++++++++++++++++ go.mod | 8 ++++++++ go.sum | 17 +++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 capabilities_test.go diff --git a/capabilities.go b/capabilities.go index a0be423..1200aa6 100644 --- a/capabilities.go +++ b/capabilities.go @@ -70,3 +70,25 @@ func (c Capabilities) Set(key string, value string) Capabilities { c[key] = value return c } + +type ChromeOptions map[string]interface{} + +func (co ChromeOptions) AddArg(arg string) ChromeOptions { + if _, ok := co["args"]; ok { + co["args"] = append(co["args"].([]string), arg) + } else { + co["args"] = []string{arg} + } + + return co +} + +func (co ChromeOptions) Binary(binaryLocation string) ChromeOptions { + co["binary"] = binaryLocation + return co +} + +func (c Capabilities) ChromeOptions(co ChromeOptions) Capabilities { + c["goog:chromeOptions"] = co + return c +} diff --git a/capabilities_test.go b/capabilities_test.go new file mode 100644 index 0000000..bfeaee3 --- /dev/null +++ b/capabilities_test.go @@ -0,0 +1,22 @@ +package webdriver + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestCapabilities(t *testing.T) { + caps := NewCapabilities() + caps.BrowserName("chrome") + assert.Equal(t, "chrome", caps["browserName"]) +} + +func TestChromeOptions(t *testing.T) { + co := ChromeOptions{} + co.AddArg("--headless") + assert.ElementsMatch(t, co["args"], []string{"--headless"}) + + co.AddArg("--disable-blink-features=AutomationControlled") + assert.ElementsMatch(t, co["args"], []string{"--headless", "--disable-blink-features=AutomationControlled"}) +} diff --git a/go.mod b/go.mod index 53d4f9f..2173a88 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,11 @@ module github.com/hupe1980/gowebdriver go 1.19 + +require github.com/stretchr/testify v1.8.1 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum index e69de29..2ec90f7 100644 --- a/go.sum +++ b/go.sum @@ -0,0 +1,17 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=