Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #344 from vania-pooh/master
Browse files Browse the repository at this point in the history
Explicitly setting browserVersion in top-level capabilites only
  • Loading branch information
vania-pooh authored May 13, 2021
2 parents 79cc283 + 3a0db10 commit d9b0000
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 10 additions & 7 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,27 @@ type Routes map[string]*Host

type caps map[string]interface{}

func (c caps) capabilities(fn func(m map[string]interface{}, w3c bool)) {
func (c caps) capabilities(fn func(m map[string]interface{}, w3c bool, extension bool)) {
if desiredCapabilities, ok := c[keys.desiredCapabilities]; ok {
if m, ok := desiredCapabilities.(map[string]interface{}); ok {
fn(m, false)
fn(m, false, false)
}
}
if w3cCapabilities, ok := c[keys.w3cCapabilities]; ok {
if m, ok := w3cCapabilities.(map[string]interface{}); ok {
if alwaysMatch, ok := m[keys.alwaysMatch]; ok {
if m, ok := alwaysMatch.(map[string]interface{}); ok {
fn(m, true)
fn(m, true, false)
for k, v := range m { // Extension capabilities have ":" in key
if ec, ok := v.(map[string]interface{}); ok && strings.Contains(k, ":") {
fn(ec, true)
fn(ec, true, true)
}
}
}
}
}
} else {
fn(make(map[string]interface{}), false)
fn(make(map[string]interface{}), false, false)
}
}

Expand All @@ -117,7 +117,7 @@ func (c caps) capability(k string) string {

func (c caps) capabilityJsonWireW3C(jsonWire, W3C string) string {
result := ""
c.capabilities(func(m map[string]interface{}, w3c bool) {
c.capabilities(func(m map[string]interface{}, w3c bool, _ bool) {
k := jsonWire
if w3c {
k = W3C
Expand Down Expand Up @@ -162,7 +162,10 @@ func (c caps) labels() string {
}

func (c caps) setVersion(version string) {
c.capabilities(func(m map[string]interface{}, w3c bool) {
c.capabilities(func(m map[string]interface{}, w3c bool, extension bool) {
if extension {
return
}
if w3c {
m["browserVersion"] = version
} else {
Expand Down
6 changes: 6 additions & 0 deletions proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,12 @@ func TestStartSessionWithDefaultVersionW3C(t *testing.T) {
AssertThat(t, err, Is{nil})
AssertThat(t, sess["capabilities"]["alwaysMatch"]["browserVersion"], EqualTo{"2.0"})

so, ok := sess["capabilities"]["alwaysMatch"]["selenoid:options"]
AssertThat(t, ok, Is{true})
selenoidOptions, ok := so.(map[string]interface{})
AssertThat(t, ok, Is{true})
_, ok = selenoidOptions["browserVersion"]
AssertThat(t, ok, Is{false})
}))
selenium := httptest.NewServer(mux)
defer selenium.Close()
Expand Down

0 comments on commit d9b0000

Please sign in to comment.