Skip to content

Commit

Permalink
Merge pull request #19 from alcounit/develop
Browse files Browse the repository at this point in the history
Fix issue #18
  • Loading branch information
alcounit authored Mar 5, 2021
2 parents 8d1c84c + a8c227c commit 95fb996
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:alpine AS builder
FROM golang:1.15-alpine AS builder

ARG BUILD_VERSION

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/alcounit/selenosis

go 1.14
go 1.15

require (
github.com/fsnotify/fsnotify v1.4.9
Expand Down
28 changes: 12 additions & 16 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,43 +70,39 @@ func (app *App) HandleSession(w http.ResponseWriter, r *http.Request) {
}
defer r.Body.Close()

type request struct {
var request struct {
DesiredCapabilities selenium.Capabilities `json:"desiredCapabilities"`
Capabilities struct {
AlwaysMatch selenium.Capabilities `json:"alwaysMatch"`
FirstMatch []*selenium.Capabilities `json:"firstMatch"`
} `json:"capabilities"`
}

caps := request{}
err = json.Unmarshal(body, &caps)
err = json.Unmarshal(body, &request)
if err != nil {
logger.WithField("time_elapsed", tools.TimeElapsed(start)).Errorf("failed to parse request: %v", err)
tools.JSONError(w, err.Error(), http.StatusBadRequest)
return
}

caps.DesiredCapabilities.ValidateCapabilities()
caps.Capabilities.AlwaysMatch.ValidateCapabilities()

if caps.DesiredCapabilities.BrowserName != "" && caps.Capabilities.AlwaysMatch.BrowserName != "" {
caps.DesiredCapabilities = caps.Capabilities.AlwaysMatch
if request.Capabilities.AlwaysMatch.GetBrowserName() != "" && request.DesiredCapabilities.GetBrowserName() == "" {
request.DesiredCapabilities = request.Capabilities.AlwaysMatch
}

firstMatchCaps := caps.Capabilities.FirstMatch
firstMatchCaps := request.Capabilities.FirstMatch
if len(firstMatchCaps) == 0 {
firstMatchCaps = append(firstMatchCaps, &selenium.Capabilities{})
}

var browser *platform.BrowserSpec
var capabilities selenium.Capabilities
var caps selenium.Capabilities

for _, first := range firstMatchCaps {
capabilities = caps.DesiredCapabilities
mergo.Merge(&capabilities, first)
capabilities.ValidateCapabilities()
for _, fmc := range firstMatchCaps {
caps = request.DesiredCapabilities
mergo.Merge(&caps, *fmc)
caps.ValidateCapabilities()

browser, err = app.browsers.Find(capabilities.BrowserName, capabilities.BrowserVersion)
browser, err = app.browsers.Find(caps.BrowserName, caps.BrowserVersion)
if err == nil {
break
}
Expand All @@ -121,7 +117,7 @@ func (app *App) HandleSession(w http.ResponseWriter, r *http.Request) {
image := parseImage(browser.Image)
template := &platform.ServiceSpec{
SessionID: fmt.Sprintf("%s-%s", image, uuid.New()),
RequestedCapabilities: capabilities,
RequestedCapabilities: caps,
Template: browser,
}

Expand Down
16 changes: 10 additions & 6 deletions selenium/selenium.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@ type Capabilities struct {

//ValidateCapabilities ...
func (c *Capabilities) ValidateCapabilities() {
if c.BrowserName == "" {
c.BrowserName = c.DeviceName
}

if c.BrowserVersion == "" {
if c.W3CBrowserVersion == "" {
c.BrowserVersion = c.W3CBrowserVersion
}

if c.Platform == "" {
if c.WC3PlatformName == "" {
c.Platform = c.WC3PlatformName
}
}

//GetBrowserName ...
func (c *Capabilities) GetBrowserName() string {
browserName := c.BrowserName
if browserName != "" {
return browserName
}
return c.DeviceName
}

0 comments on commit 95fb996

Please sign in to comment.