Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Support headless testing in features
Browse files Browse the repository at this point in the history
Co-authored-by: Pete Wall <[email protected]>
[#166909577]
  • Loading branch information
Rasheed Abdul-Aziz committed Jul 9, 2019
1 parent 3208d5c commit d7c2d99
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 27 deletions.
62 changes: 50 additions & 12 deletions features/features_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"net/http/httptest"
"os"
"testing"

. "github.com/onsi/ginkgo"
Expand All @@ -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)
Expand All @@ -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())
}

})
15 changes: 0 additions & 15 deletions features/generate_html_log_report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit d7c2d99

Please sign in to comment.