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

Commit

Permalink
Fixed tests run for Firefox browser
Browse files Browse the repository at this point in the history
  • Loading branch information
ruescar committed Sep 14, 2020
1 parent b8fbbae commit 04b7380
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ $ ./selenoid-images firefox -b 79.0+build1-0ubuntu0.18.04.1 -t selenoid/firefox:

If you wish to pack a local Debian package instead of APT - just replace package version with full path to **deb** file:
```
$ ./selenoid-images firefox -b /path/to/firefox_79.0+build1-0ubuntu0.18.04.1_amd64.dev -t selenoid/firefox:79.0
$ ./selenoid-images firefox -b /path/to/firefox_79.0+build1-0ubuntu0.18.04.1_amd64.deb -t selenoid/firefox:79.0
```
It is important to use package files with full version specified name because automation scripts determine browser version by parsing package file name!

Expand Down
22 changes: 22 additions & 0 deletions build/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,31 @@ func extractVersion(name string) string {
}
pieces = strings.Split(version, "+")
pieces = strings.Split(pieces[0], "-")
pieces = strings.Split(pieces[0], "~")
return pieces[0]
}

func versionN(pkgVersion string, n int) string {
buildVersion := pkgVersion
pieces := strings.Split(pkgVersion, ".")
if len(pieces) >= n {
buildVersion = strings.Join(pieces[0:n], ".")
}
return buildVersion
}

func majorVersion(pkgVersion string) string {
return versionN(pkgVersion, 1)
}

func majorMinorVersion(pkgVersion string) string {
return versionN(pkgVersion, 2)
}

func buildVersion(pkgVersion string) string {
return versionN(pkgVersion, 3)
}

type Image struct {
Dir string
BuildArgs []string
Expand Down
19 changes: 19 additions & 0 deletions build/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,31 @@ import (

func TestVersionFromPackageName(t *testing.T) {
AssertThat(t, extractVersion("firefox_45.0.2+build1-0ubuntu0.14.04.1+aerokube0_amd64.deb"), EqualTo{"45.0.2"})
AssertThat(t, extractVersion("firefox_71.0_b11+build1-0ubuntu0.18.04.1_amd64.deb"), EqualTo{"71.0"})
AssertThat(t, extractVersion("firefox-trunk_72.0_a1_hg20191114r501767-0ubuntu0.18.04.1_umd1_amd64.deb"), EqualTo{"72.0"})
AssertThat(t, extractVersion("google-chrome-stable_48.0.2564.109-1+aerokube0_amd64.deb"), EqualTo{"48.0.2564.109"})
AssertThat(t, extractVersion("google-chrome-beta_79.0.3945.36-1_amd64.deb"), EqualTo{"79.0.3945.36"})
AssertThat(t, extractVersion("google-chrome-unstable_80.0.3964.0-1_amd64.deb"), EqualTo{"80.0.3964.0"})
AssertThat(t, extractVersion("opera-stable_38.0.2220.31_amd64.deb"), EqualTo{"38.0.2220.31"})
AssertThat(t, extractVersion("opera-beta_65.0.3467.32_amd64.deb"), EqualTo{"65.0.3467.32"})
AssertThat(t, extractVersion("opera-developer_66.0.3502.0_amd64.deb"), EqualTo{"66.0.3502.0"})
AssertThat(t, extractVersion("yandex-browser-beta_19.9.3.358-1_amd64.deb"), EqualTo{"19.9.3.358"})
}

func TestVersionToTag(t *testing.T) {
AssertThat(t, extractVersion("45.0.2+build1-0ubuntu0.14.04.1+aerokube0"), EqualTo{"45.0.2"})
AssertThat(t, extractVersion("48.0.2564.109-1+aerokube0"), EqualTo{"48.0.2564.109"})
AssertThat(t, extractVersion("78.0.3904.108-1"), EqualTo{"78.0.3904.108"})
AssertThat(t, extractVersion("38.0.2220.31"), EqualTo{"38.0.2220.31"})
AssertThat(t, extractVersion("71.0~b11+build1-0ubuntu0.18.04.1"), EqualTo{"71.0"})
AssertThat(t, extractVersion("74.0~a1~hg20200205r512485-0ubuntu0.18.04.1~umd1"), EqualTo{"74.0"})
}

func TestParseVersion(t *testing.T) {
AssertThat(t, majorVersion("78.0.3904.108"), EqualTo{"78"})
AssertThat(t, majorVersion("78"), EqualTo{"78"})
AssertThat(t, majorMinorVersion("78.0.3904.108"), EqualTo{"78.0"})
AssertThat(t, majorMinorVersion("78.0"), EqualTo{"78.0"})
AssertThat(t, buildVersion("78.0.3904.108"), EqualTo{"78.0.3904"})
AssertThat(t, buildVersion("78.0.3904"), EqualTo{"78.0.3904"})
}
22 changes: 0 additions & 22 deletions build/chrome.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"path/filepath"
"strconv"
"strings"
)

const (
Expand Down Expand Up @@ -164,24 +163,3 @@ func (c *Chrome) getLatestChromeDriver(baseUrl string, pkgVersion string) (strin
return fetchVersion(u)
}
}

func versionN(pkgVersion string, n int) string {
buildVersion := pkgVersion
pieces := strings.Split(pkgVersion, ".")
if len(pieces) >= n {
buildVersion = strings.Join(pieces[0:n], ".")
}
return buildVersion
}

func majorVersion(pkgVersion string) string {
return versionN(pkgVersion, 1)
}

func majorMinorVersion(pkgVersion string) string {
return versionN(pkgVersion, 2)
}

func buildVersion(pkgVersion string) string {
return versionN(pkgVersion, 3)
}
4 changes: 2 additions & 2 deletions build/firefox.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (c *Firefox) Build() error {
}
image.BuildArgs = append(image.BuildArgs, fmt.Sprintf("VERSION=%s", pkgTagVersion))

firefoxMajorMinorVersion := majorMinorVersion(pkgTagVersion)
if geckoDriverCompatible {
driverVersion, err := c.downloadGeckoDriver(image.Dir)
if err != nil {
Expand All @@ -99,7 +100,6 @@ func (c *Firefox) Build() error {
labels = append(labels, fmt.Sprintf("selenoid=%s", selenoidVersion))
image.Labels = labels

firefoxMajorMinorVersion := majorMinorVersion(pkgTagVersion)
browsersJsonFile := filepath.Join(image.Dir, "browsers.json")
data, err := ioutil.ReadFile(browsersJsonFile)
if err != nil {
Expand All @@ -123,7 +123,7 @@ func (c *Firefox) Build() error {
return fmt.Errorf("build image: %v", err)
}

err = image.Test(c.TestsDir, "firefox", pkgTagVersion)
err = image.Test(c.TestsDir, "firefox", firefoxMajorMinorVersion)
if err != nil {
return fmt.Errorf("test image: %v", err)
}
Expand Down

0 comments on commit 04b7380

Please sign in to comment.