diff --git a/features/features_suite_test.go b/features/features_suite_test.go index e554b69..2f8a886 100644 --- a/features/features_suite_test.go +++ b/features/features_suite_test.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "net/http/httptest" + "os" "testing" . "github.com/onsi/ginkgo" @@ -16,18 +17,6 @@ func TestFeatures(t *testing.T) { RunSpecs(t, "Features Suite") } -var agoutiDriver *agouti.WebDriver - -var _ = BeforeSuite(func() { - agoutiDriver = agouti.ChromeDriver() - - Expect(agoutiDriver.Start()).To(Succeed()) -}) - -var _ = AfterSuite(func() { - Expect(agoutiDriver.Stop()).To(Succeed()) -}) - func serveDocument(document string) *httptest.Server { testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { _, err := fmt.Fprint(w, document) @@ -36,3 +25,52 @@ func serveDocument(document string) *httptest.Server { return testServer } + +func configureAgouti(headless bool) error { + agoutiDriver = agouti.ChromeDriver() + Expect(agoutiDriver.Start()).To(Succeed()) + + var err error + if headless { + fmt.Println("Running feature tests in headless mode") + page, err = agouti.NewPage( + agoutiDriver.URL(), + agouti.Desired(agouti.Capabilities{ + "chromeOptions": map[string][]string{ + "args": { + "headless", + "disable-gpu", // There is no GPU on our Ubuntu box! + "no-sandbox", // Sandbox requires namespace permissions that we don't have on a container + }, + }, + }), + ) + } else { + page, err = agoutiDriver.NewPage(agouti.Browser("chrome")) + } + + return err +} + +var ( + page *agouti.Page + agoutiDriver *agouti.WebDriver +) + +var _ = BeforeSuite(func() { + _, ciMode := os.LookupEnv("CI") + + err := configureAgouti(ciMode) + Expect(err).NotTo(HaveOccurred()) +}) + +var _ = AfterSuite(func() { + if page != nil { + Expect(page.Destroy()).To(Succeed()) + } + + if agoutiDriver != nil { + Expect(agoutiDriver.Stop()).To(Succeed()) + } + +}) diff --git a/features/generate_html_log_report_test.go b/features/generate_html_log_report_test.go index a434466..11a7647 100644 --- a/features/generate_html_log_report_test.go +++ b/features/generate_html_log_report_test.go @@ -12,27 +12,12 @@ import ( . "github.com/onsi/gomega" . "github.com/onsi/gomega/gbytes" "github.com/onsi/gomega/gexec" - "github.com/sclevine/agouti" "github.com/sclevine/agouti/matchers" ) var _ = Describe("Generate HTML log", func() { steps := NewSteps() - var ( - page *agouti.Page - ) - - BeforeEach(func() { - var err error - page, err = agoutiDriver.NewPage() - Expect(err).NotTo(HaveOccurred()) - }) - - AfterEach(func() { - Expect(page.Destroy()).To(Succeed()) - }) - Scenario("Log contains simple text", func() { steps.Given("the mrreport command is built") steps.And("a simple log output as a stream")