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

Commit

Permalink
Automatic update ggr fork with upstream changes (#23)
Browse files Browse the repository at this point in the history
Upstream update
Co-authored-by: Ivan Krutov <[email protected]>
Co-authored-by: Alexander Andryashin <[email protected]>
Co-authored-by: Ivan Krutov <[email protected]>
Co-authored-by: kbilchenko <[email protected]>
  • Loading branch information
hf-platform authored Sep 21, 2021
1 parent e38d366 commit ef65f02
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
23 changes: 9 additions & 14 deletions docs/quick-start-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,39 @@ To use Go Grid Router do the following:
----
$ mkdir -p /etc/grid-router/quota
----

. Create ```users.htpasswd``` file:
+
----
$ htpasswd -bc /etc/grid-router/users.htpasswd test test-password
----
. Start Selenium standalone server on port 4445:
+
----
$ java -jar selenium-server-standalone.jar -port 4445
----
NOTE: We are showing Selenium server command here because it is a well-known example. We recommend you to use http://aerokube.com/selenoid/latest/[Selenoid] instead - it is more efficient.

. Start https://aerokube.com/selenoid/latest/[Selenoid] on host `selenoid.example.com` and port `4444`.
. Create quota file (use correct browser name and version):
+
----
$ cat /etc/grid-router/quota/test.xml
<qa:browsers xmlns:qa="urn:config.gridrouter.qatools.ru">
<browser name="firefox" defaultVersion="45.0">
<version number="45.0">
<browser name="firefox" defaultVersion="88.0">
<version number="88.0">
<region name="1">
<host name="localhost" port="4445" count="1"/>
<host name="selenoid.example.com" port="4444" count="1"/>
</region>
</version>
</browser>
</qa:browsers>
----
+
NOTE: File name should correspond to user name you added to `htpasswd` file. For user ```test``` we added on previous steps you should create ```test.xml```.
+
NOTE: For Mac OS instead of "localhost" you have to use "docker.for.mac.localhost".
link:++https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds++[Docker for Mac - Networking].
+
NOTE: File name should correspond to user name you added to `htpasswd` file.
For user `test` we added on previous steps you should create `test.xml`.
. Start Ggr container:
+
----
# docker run -d --name \
ggr -v /etc/grid-router/:/etc/grid-router:ro \
--net host aerokube/ggr:latest-release
----

. Access Ggr on port 4444 in the same way you do for Selenium Hub but using the following url:
+
----
Expand Down
33 changes: 18 additions & 15 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,28 @@ 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)
}
} else {
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)
for k, v := range m { // Extension capabilities have ":" in key
if ec, ok := v.(map[string]interface{}); ok && strings.Contains(k, ":") {
fn(ec, true)
}
}
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, 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, true)
}
}
}
}
}
} else {
fn(make(map[string]interface{}), false, false)
}
fn(make(map[string]interface{}), false)
}

func (c caps) capability(k string) string {
Expand All @@ -118,7 +118,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 @@ -163,7 +163,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 @@ -920,6 +920,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 ef65f02

Please sign in to comment.