I’ve learned a little bit about frontend testing with chromium web drivers using Agouti and It has proven to be a really good option to write test in Go. Also we are in quarantine so I let you here a WebGL interactive animation to entertain you.
Enjoy
Agouti
Agouti is an universal WebDriver client for Go. I decided to use it because I’m already familiar with Ginkgo and Gomega and I think that it covers my use case, Which is testing simple web applications and APIs from the same code.
You can get started with the Ginkgo cli by running the bootstrap command with the –agouti flag
|
|
This generates a bootstrap file with the following structure
|
|
If you are familiar with Ginkgo, you will recognise everything in this file. It’s self explanatory. You have to pay attention to the selected web driver. From my experience, ChromeDriver works well. I do not recommend PhantomJS as it is deprecated.
Now you are ready to start writing your own browser tests. Following the example in the official page, you can create the structure using ginkgo cli.
|
|
|
|
I’m not going to copy an paste everything from that page here. Just go to Agouti webpage and read the tutorial.
Genereate a portable binary test
This is the main reason why I’ve chosen Go for writing test. I need to be able to write test and share them with other developers to execute it in their local environment. If you’ve tried to share applications in Python, Java or other programming languages that require heavy environment setup, it’s always annoying. With go, just give execution permissions and you are ready to Go.
To generate a binary from the current tests, you have to run the following command
|
|
This will generate a binary file, in my case Agouti.test, that you can run to have the same effect as running go test.
|
|
There is one missing feature for being able to really use this approach. Flags! You can easily add your own flags using the init()
function. Here is an example of a flag to select the driver. You can easily extend this to add your own flags. The trick is to define all the flags in the init()
section. Note that we are not calling flag.Parse
because it is internally called.
|
|
Now you can run ginkgo with flags or the binary generated
|
|
If you start the Agouti.test
with –help. you will find that all the ginkgo/test flags are still there. Therefore you can do interesting things such as focus specs by pattern, enable verbose output or enabling fail fast.
Conclusion
Go + Ginkgo + Gomega + Agouti are perfect to write portable test suites that can be executed in any system. The next steps will be to add some API testing directly with Go http library and to try Agouti inside a docker container. I think that the docker container will just work inside this image https://hub.docker.com/r/robcherry/docker-chromedriver/