How to drive web browser in Golang using Agouti
This article is about driving web browser in Golang.
Agouti is an acceptance and testing framework. It could be used together with Ginkgo which is a BDD testing framework and Gomega matcher/assertion library if you are looking for a complete testing solution for your Go project.
The following example only make use of Agouti to drive a browser.
Create the project inside $GOPATH
Create the main.go under $GOPATH/src/gitlab.com/ykyuen/driving-web-browser-in-go-example.
Download the Go dependency
[ykyuen@camus driving-web-browser-in-go-example]$ dep init
Using ^2.0.0 as constraint for direct dep github.com/sclevine/agouti
Locking in v2.0 (b920a9c) for direct dep github.com/sclevine/agouti
Then run dep ensure to update the Agouti version.
Run the code
[ykyuen@camus driving-web-browser-in-go-example]$ go run main.go
2018/01/21 19:02:42 Getting Agouti
If you are using ChromeDriver, you should be able to see the Chrome browser will be started automatically and execute the tasks as stated in main.go.
Running in headless browser
- This example is not about writing test case but just showing how to drive a web browser.
- For testing, we probably need Ginkgo and Gomega.
- I also tried another Go package called chromedp but it doesn’t work well.
- chromedp used as a functional test tool?
- Saving screenshot with headless chrome throws “invalid image size” error
- Click does not work in a specific environment
- Complete example is available at gitlab.com
— Originally posted on Boatswain Blog.