diff --git a/Dockerfile b/Dockerfile index c452c0a..5e3257f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:alpine AS builder +FROM golang:1.15-alpine AS builder ARG BUILD_VERSION diff --git a/go.mod b/go.mod index 61e98e5..fddfdab 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/alcounit/selenosis -go 1.14 +go 1.15 require ( github.com/fsnotify/fsnotify v1.4.9 diff --git a/handlers.go b/handlers.go index 6c68b7c..ea1c2ed 100644 --- a/handlers.go +++ b/handlers.go @@ -70,7 +70,7 @@ 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"` @@ -78,35 +78,31 @@ func (app *App) HandleSession(w http.ResponseWriter, r *http.Request) { } `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 } @@ -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, } diff --git a/selenium/selenium.go b/selenium/selenium.go index 1292db5..24ee116 100644 --- a/selenium/selenium.go +++ b/selenium/selenium.go @@ -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 }