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

Commit

Permalink
Added MicrosoftEdge support (fixes #283)
Browse files Browse the repository at this point in the history
  • Loading branch information
vania-pooh committed Nov 26, 2020
1 parent 14baea8 commit c83fa65
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 16 deletions.
20 changes: 8 additions & 12 deletions selenoid/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ import (
"github.com/aerokube/cm/render/rewriter"
dc "github.com/aerokube/util/docker"
"github.com/fatih/color"
. "github.com/fvbommel/sortorder"
"io"
"net/url"
. "github.com/fvbommel/sortorder"
)

const (
Expand All @@ -49,6 +49,7 @@ const (
Latest = "latest"
firefox = "firefox"
android = "android"
edge = "MicrosoftEdge"
opera = "opera"
tag_1216 = "12.16"
selenoidImage = "aerokube/selenoid"
Expand Down Expand Up @@ -375,8 +376,7 @@ func (c *DockerConfigurator) createConfig() SelenoidConfig {
c.Titlef(`Processing browser "%v"...`, color.GreenString(browserName))
tags := c.fetchImageTags(image)
if c.VNC {
c.Pointf("Requested to download VNC images...")
image = fmt.Sprintf("selenoid/vnc_%s", browserName)
c.Pointf("Requested to download VNC images but this feature is now deprecated as all images contain VNC.")
}
versionConstraint := requestedBrowsers[browserName]
pulledTags := c.filterTags(tags, versionConstraint)
Expand Down Expand Up @@ -431,6 +431,9 @@ func (c *DockerConfigurator) getBrowsersToIterate(requestedBrowsers map[string][
if _, ok := requestedBrowsers[android]; ok {
defaultBrowsers[android] = "selenoid/android"
}
if _, ok := requestedBrowsers[edge]; ok {
defaultBrowsers[edge] = "browsers/edge"
}
ret := make(map[string]string)
for browserName := range requestedBrowsers {
if image, ok := defaultBrowsers[browserName]; ok {
Expand Down Expand Up @@ -497,11 +500,11 @@ func (c *DockerConfigurator) filterTags(tags []string, versionConstraints []*sem

func (c *DockerConfigurator) createVersions(browserName string, image string, tags []string) config.Versions {
versions := config.Versions{
Default: c.getVersionFromTag(browserName, tags[0]),
Default: tags[0],
Versions: make(map[string]*config.Browser),
}
for _, tag := range tags {
version := c.getVersionFromTag(browserName, tag)
version := tag
browser := &config.Browser{
Image: imageWithTag(image, tag),
Port: "4444",
Expand Down Expand Up @@ -556,13 +559,6 @@ func (c *DockerConfigurator) getFullyQualifiedImageRef(ref string) string {
return ref
}

func (c *DockerConfigurator) getVersionFromTag(browserName string, tag string) string {
if c.VNC {
return strings.TrimPrefix(tag, browserName+"_")
}
return tag
}

// JSONMessage defines a message struct from docker.
type JSONMessage struct {
Status string `json:"status,omitempty"`
Expand Down
59 changes: 55 additions & 4 deletions selenoid/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ func mux() http.Handler {
},
))

mux.HandleFunc("/v2/selenoid/android/tags/list", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
fmt.Fprintln(w, `{"name":"android", "tags": ["10.0"]}`)
},
))

mux.HandleFunc("/v2/browsers/edge/tags/list", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
fmt.Fprintln(w, `{"name":"edge", "tags": ["88.0"]}`)
},
))

//Docker API mock
mux.HandleFunc("/v1.29/version", http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -306,7 +320,7 @@ func testConfigure(t *testing.T, download bool) {
LastVersions: 2,
Tmpfs: 512,
ShmSize: 256,
Browsers: "firefox:>45.0;opera",
Browsers: "firefox:>45.0;opera;android;MicrosoftEdge",
Args: "-limit 42",
VNC: true,
Env: testEnv,
Expand All @@ -321,7 +335,7 @@ func testConfigure(t *testing.T, download bool) {
AssertThat(t, cfgPointer, Is{Not{nil}})

cfg := *cfgPointer
AssertThat(t, len(cfg), EqualTo{2})
AssertThat(t, len(cfg), EqualTo{4})

firefoxVersions, hasFirefoxKey := cfg["firefox"]
AssertThat(t, hasFirefoxKey, Is{true})
Expand All @@ -332,7 +346,7 @@ func testConfigure(t *testing.T, download bool) {

correctFFBrowsers := make(map[string]*config.Browser)
correctFFBrowsers["46.0"] = &config.Browser{
Image: c.getFullyQualifiedImageRef("selenoid/vnc_firefox:46.0"),
Image: c.getFullyQualifiedImageRef("selenoid/firefox:46.0"),
Port: "4444",
Path: "/wd/hub",
Tmpfs: tmpfsMap,
Expand All @@ -351,7 +365,7 @@ func testConfigure(t *testing.T, download bool) {

correctOperaBrowsers := make(map[string]*config.Browser)
correctOperaBrowsers["44.0"] = &config.Browser{
Image: c.getFullyQualifiedImageRef("selenoid/vnc_opera:44.0"),
Image: c.getFullyQualifiedImageRef("selenoid/opera:44.0"),
Port: "4444",
Path: "/",
Tmpfs: tmpfsMap,
Expand All @@ -362,6 +376,43 @@ func testConfigure(t *testing.T, download bool) {
Default: "44.0",
Versions: correctOperaBrowsers,
}})

androidVersions, hasAndroidKey := cfg["android"]
AssertThat(t, hasAndroidKey, Is{true})
AssertThat(t, androidVersions, Is{Not{nil}})

correctAndroidBrowsers := make(map[string]*config.Browser)
correctAndroidBrowsers["10.0"] = &config.Browser{
Image: c.getFullyQualifiedImageRef("selenoid/android:10.0"),
Port: "4444",
Path: "/wd/hub",
Tmpfs: tmpfsMap,
ShmSize: 268435456,
Env: []string{testEnv},
}
AssertThat(t, androidVersions, EqualTo{config.Versions{
Default: "10.0",
Versions: correctAndroidBrowsers,
}})

edgeVersions, hasEdgeKey := cfg["MicrosoftEdge"]
AssertThat(t, hasEdgeKey, Is{true})
AssertThat(t, edgeVersions, Is{Not{nil}})

correctEdgeBrowsers := make(map[string]*config.Browser)
correctEdgeBrowsers["88.0"] = &config.Browser{
Image: c.getFullyQualifiedImageRef("browsers/edge:88.0"),
Port: "4444",
Path: "/",
Tmpfs: tmpfsMap,
ShmSize: 268435456,
Env: []string{testEnv},
}
AssertThat(t, edgeVersions, EqualTo{config.Versions{
Default: "88.0",
Versions: correctEdgeBrowsers,
}})

})
}

Expand Down

0 comments on commit c83fa65

Please sign in to comment.