From 9eac0bd32b14194cd7a6ccffcaa837f37c7858cc Mon Sep 17 00:00:00 2001 From: Eric Garrido Date: Thu, 1 Aug 2019 16:38:19 -0400 Subject: [PATCH 1/3] Use headless browsers by default --- .travis.yml | 9 ++------- README.md | 4 ++++ remote_test.go | 16 ++++++++++++++-- testing/travis-ci-test.sh | 3 +-- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index fc15546..c36e335 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,15 +3,10 @@ go: - 1.12.x jdk: - # The Java 8 SDK is a requirement for Selenium. - - openjdk8 + # The Java JRE is a requirement for Selenium and HTMLUnit. + - openjdk11 before_script: - # Start an X frame buffer in which to run the web browsers. - - "export DISPLAY=:99.0" - - "sh -e /etc/init.d/xvfb start" - # give xvfb some time to start - - sleep 3 # Download all of the binary dependencies needed to run the tests. - cd vendor && go run init.go --alsologtostderr --download_browsers --download_latest && cd .. diff --git a/README.md b/README.md index 50eee11..a4287c0 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,10 @@ to only be several days to a small number of weeks. Using Geckodriver without Selenium usually has the above known issues as well. +### Chromedriver + +1. [Headless Chrome does not support running extensions](https://crbug.com/706008). + ## Breaking Changes There are a number of upcoming changes that break backward compatibility in an diff --git a/remote_test.go b/remote_test.go index 49c5b42..27acdfc 100644 --- a/remote_test.go +++ b/remote_test.go @@ -20,7 +20,7 @@ import ( "testing" "time" - "github.com/armon/go-socks5" + socks5 "github.com/armon/go-socks5" "github.com/blang/semver" "github.com/golang/glog" "github.com/google/go-cmp/cmp" @@ -44,7 +44,8 @@ var ( useDocker = flag.Bool("docker", false, "If set, run the tests in a Docker container.") runningUnderDocker = flag.Bool("running_under_docker", false, "This is set by the Docker test harness and should not be needed otherwise.") - startFrameBuffer = flag.Bool("start_frame_buffer", true, "If true, start an Xvfb subprocess and run the browsers in that X server.") + startFrameBuffer = flag.Bool("start_frame_buffer", false, "If true, start an Xvfb subprocess and run the browsers in that X server.") + headless = flag.Bool("headless", true, "If true, run Chrome and Firefox in headless mode, not requiring a frame buffer.") serverURL string ) @@ -195,6 +196,11 @@ func testChromeExtension(t *testing.T, c config) { } defer wd.Quit() + if *headless { + // https://crbug.com/706008 + t.Skip("Chrome does not support extensions in headless mode.") + } + if err := wd.Get(serverURL); err != nil { t.Fatalf("wd.Get(%q) returned error: %v", serverURL, err) } @@ -470,6 +476,9 @@ func newTestCapabilities(t *testing.T, c config) Capabilities { }, W3C: true, } + if *headless { + chrCaps.Args = append(chrCaps.Args, "--headless") + } caps.AddChrome(chrCaps) case "firefox": f := firefox.Capabilities{} @@ -487,6 +496,9 @@ func newTestCapabilities(t *testing.T, c config) Capabilities { Level: firefox.Trace, } } + if *headless { + f.Args = append(f.Args, "-headless") + } caps.AddFirefox(f) case "htmlunit": caps["javascriptEnabled"] = true diff --git a/testing/travis-ci-test.sh b/testing/travis-ci-test.sh index cb4fd25..75e7af9 100755 --- a/testing/travis-ci-test.sh +++ b/testing/travis-ci-test.sh @@ -1,5 +1,4 @@ #!/bin/bash # Run tests under Travis for continuous integration. -go test -coverprofile=coverage.txt -covermode=atomic -test.v -timeout=20m \ - --start_frame_buffer=false ./... +go test -coverprofile=coverage.txt -covermode=atomic -test.v -timeout=20m ./... From 95eccfa48956e121ded0a0d98a5382491f17d428 Mon Sep 17 00:00:00 2001 From: Eric Garrido Date: Fri, 2 Aug 2019 01:24:27 +0000 Subject: [PATCH 2/3] Bump Sauce Connect version --- vendor/init.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/init.go b/vendor/init.go index 84aca53..e68540e 100644 --- a/vendor/init.go +++ b/vendor/init.go @@ -66,9 +66,9 @@ var files = []file{ // hash: "acf71b77d1b66b55db6fb0bed6d8bae2bbd481311bcbedfeff472c0d15e8f3cb", }, { - url: "https://saucelabs.com/downloads/sc-4.5.3-linux.tar.gz", + url: "https://saucelabs.com/downloads/sc-4.5.4-linux.tar.gz", name: "sauce-connect.tar.gz", - rename: []string{"sc-4.5.3-linux", "sauce-connect"}, + rename: []string{"sc-4.5.4-linux", "sauce-connect"}, }, } From 620f2630f03de5b55704fa3f7b21e4b438b41238 Mon Sep 17 00:00:00 2001 From: Eric Garrido Date: Fri, 2 Aug 2019 01:51:44 +0000 Subject: [PATCH 3/3] Test Chrome through Selenium as well --- remote_test.go | 90 ++++++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/remote_test.go b/remote_test.go index 27acdfc..c5e29b7 100644 --- a/remote_test.go +++ b/remote_test.go @@ -147,6 +147,23 @@ func TestChrome(t *testing.T) { t.Skipf("Skipping Chrome tests because ChromeDriver not found at path %q", *chromeDriverPath) } + t.Run("Chromedriver", func(t *testing.T) { + runChromeTests(t, config{ + path: *chromeBinary, + }) + }) + + t.Run("Selenium3", func(t *testing.T) { + runChromeTests(t, config{ + path: *chromeBinary, + seleniumVersion: semver.MustParse("3.0.0"), + }) + }) +} + +func runChromeTests(t *testing.T, c config) { + c.browser = "chrome" + var opts []ServiceOption if *startFrameBuffer { opts = append(opts, StartFrameBuffer()) @@ -160,15 +177,17 @@ func TestChrome(t *testing.T) { if err != nil { t.Fatalf("pickUnusedPort() returned error: %v", err) } + c.addr = fmt.Sprintf("http://127.0.0.1:%d/wd/hub", port) - s, err := NewChromeDriverService(*chromeDriverPath, port, opts...) - if err != nil { - t.Fatalf("Error starting the ChromeDriver server: %v", err) + var s *Service + if c.seleniumVersion.Major == 3 { + c.serviceOptions = append(c.serviceOptions, ChromeDriver(*chromeDriverPath)) + s, err = NewSeleniumService(*selenium3Path, port, c.serviceOptions...) + } else { + s, err = NewChromeDriverService(*chromeDriverPath, port, c.serviceOptions...) } - c := config{ - addr: fmt.Sprintf("http://127.0.0.1:%d/wd/hub", port), - browser: "chrome", - path: *chromeBinary, + if err != nil { + t.Fatalf("Error starting the server: %v", err) } runTests(t, c) @@ -221,34 +240,33 @@ func testChromeExtension(t *testing.T, c config) { } } -func TestFirefoxSelenium3(t *testing.T) { +func TestFirefox(t *testing.T) { if *useDocker { t.Skip("Skipping tests because they will be run under a Docker container") } - if _, err := os.Stat(*selenium3Path); err != nil { - t.Skipf("Skipping Firefox tests using Selenium 3 because Selenium WebDriver JAR not found at path %q", *selenium3Path) - } if _, err := os.Stat(*geckoDriverPath); err != nil { t.Skipf("Skipping Firefox tests on Selenium 3 because geckodriver binary %q not found", *geckoDriverPath) } - runFirefoxTests(t, *selenium3Path, config{ - seleniumVersion: semver.MustParse("3.0.0"), - serviceOptions: []ServiceOption{GeckoDriver(*geckoDriverPath)}, - path: *firefoxBinarySelenium3, - }) -} - -func TestFirefoxGeckoDriver(t *testing.T) { - if *useDocker { - t.Skip("Skipping tests because they will be run under a Docker container") - } - if _, err := os.Stat(*geckoDriverPath); err != nil { - t.Skipf("Skipping Firefox tests on Selenium 3 because geckodriver binary %q not found", *geckoDriverPath) + if s, err := os.Stat(*firefoxBinarySelenium3); err != nil || !s.Mode().IsRegular() { + if p, err := exec.LookPath(*firefoxBinarySelenium3); err == nil { + *firefoxBinarySelenium3 = p + } else { + t.Skipf("Skipping Firefox tests because binary %q not found", *firefoxBinarySelenium3) + } } - runFirefoxTests(t, *geckoDriverPath, config{ - path: *firefoxBinarySelenium3, + t.Run("Selenium3", func(t *testing.T) { + runFirefoxTests(t, *selenium3Path, config{ + seleniumVersion: semver.MustParse("3.0.0"), + serviceOptions: []ServiceOption{GeckoDriver(*geckoDriverPath)}, + path: *firefoxBinarySelenium3, + }) + }) + t.Run("Geckodriver", func(t *testing.T) { + runFirefoxTests(t, *geckoDriverPath, config{ + path: *firefoxBinarySelenium3, + }) }) } @@ -293,14 +311,6 @@ func TestHTMLUnit(t *testing.T) { func runFirefoxTests(t *testing.T, webDriverPath string, c config) { c.browser = "firefox" - if s, err := os.Stat(c.path); err != nil || !s.Mode().IsRegular() { - if path, err := exec.LookPath(c.path); err == nil { - c.path = path - } else { - t.Skipf("Skipping Firefox tests because binary %q not found", c.path) - } - } - if *startFrameBuffer { c.serviceOptions = append(c.serviceOptions, StartFrameBuffer()) } @@ -319,20 +329,20 @@ func runFirefoxTests(t *testing.T, webDriverPath string, c config) { var s *Service if c.seleniumVersion.Major == 0 { + c.addr = fmt.Sprintf("http://127.0.0.1:%d", port) s, err = NewGeckoDriverService(webDriverPath, port, c.serviceOptions...) } else { + c.addr = fmt.Sprintf("http://127.0.0.1:%d/wd/hub", port) + if _, err := os.Stat(*selenium3Path); err != nil { + t.Skipf("Skipping Firefox tests using Selenium 3 because Selenium WebDriver JAR not found at path %q", *selenium3Path) + } + s, err = NewSeleniumService(webDriverPath, port, c.serviceOptions...) } if err != nil { t.Fatalf("Error starting the WebDriver server with binary %q: %v", webDriverPath, err) } - if c.seleniumVersion.Major == 0 { - c.addr = fmt.Sprintf("http://127.0.0.1:%d", port) - } else { - c.addr = fmt.Sprintf("http://127.0.0.1:%d/wd/hub", port) - } - runFirefoxSubTests(t, c) if err := s.Stop(); err != nil {