GO-vatar series: Recipe To Boil Web Automation With Go Language

Ferawati Hartanti Pratiwi
Inside Bukalapak
Published in
4 min readJul 17, 2019
https://ui-ex.com/images/boiling-clipart-hot-water-1.jpg

Wait. What? Boil?

EXACTLY.

Let me tell you why I choose that word for my article this time.

This start with the keyword “golang cucumber”. The first line of the search result in Google is direct to this link.

In Javanese (which is one part of a regional language of Indonesia), godog (or godok) is means “rebus” which is in English it means “boil”. This is just a play on words. Good enough to make people curious, right?

Let’s cook!

https://cdn.eventfinda.co.nz/uploads/events/transformed/1098802-494523-34.png?v=2

Setup GO

sudo nano ~/.bash_profile
  • Add this line.
export GOROOT=/usr/local/goexport GOPATH=$HOME/project/goexport PATH=$PATH:$GOROOT/bin:$GOPATH/bin
  • Save file.
CTRL + OPress enter
  • Quit nano editor.
CTRL + X
  • Reload file.
source ~/.bash_profile
  • Test GO.
cd $GOPATHmkdir src/github.com/go-cucumbercd src/github.com/go-cucumbercreate hello.go

You can use your file editor or use the same editor like me (https://code.visualstudio.com/docs/?dv=osx) and then write this code inside the hello.go file.

Then try the first run.

go run hello.go

Is it success? I hope so. If failed, please comment.

Setup Framework

go get github.com/DATA-DOG/godog/cmd/godoggo get -t -d github.com/tebeka/seleniumgo get github.com/joho/godotenvgo get -u github.com/logrusorgru/aurora

Setup Docker

docker run -d -p 4444:4444 --name selenium-hub selenium/hubdocker run -d --link selenium-hub:hub selenium/node-chromedocker run -d --link selenium-hub:hub selenium/node-firefox

To check if docker is successfully running. Try this.

docker ps -a

For docker, it’s optional. We can download Selenium server instead and run it manually by this command.

java -jar <selenium.jar file>

Instructions

https://cdn.shopify.com/s/files/1/0653/8213/files/Instructions_4_large.jpg?v=1506370202
  • cd $GOPATH/project/go/src/github.com/go-cucumber.
  • mkdir features/scenarios.
  • cd features/scenarios.
  • Create and write file demo.feature like this.
Scenario for demo in Medium
  • Create and write file godogs.go like this.
  • Create and write file demo_test.go like this. We have to rename the file with *_test.go because godog can not read the file if file format isn’t like that.
  • Run this in terminal.
godog --tags=@demo or godog --tags=@all-2
  • The scenario run result must be like this.

As seen in the screenshot above, the scenario is PASSED but there is error message printed that URL DOESN’T MATCH. if we want the results as shown below, we should use log instead of fmt (which is used only for printing purposes).

Use this to get the results as shown above

For a newbie (like me), I really recommend to not use panic as a error handling. We can see from the screenshot below. Panic doesn’t only show the actual error but others error that even I don’t understand it myself.

This is when we use panic to handling an error

But the choice depends on each person.

So proceed from the results of running before, from the demo code we already use :

  • Golang — For programming language.
  • Godog — Cucumber BDD framework for Go.
  • Tebeka — WebDriver client for Go.
  • Godotenv — To loads env variables from a .env file.
  • Aurora — Ultimate ANSI colors for Go.
  • Sayems — ?

What’s the use of Sayems then?

That’s for a page object like this.

We can use the page object like this.

FindElementByCss is a base method that I created on purpose for another scenario (not for demo scenario but still including part of my research about Go and automation testing). I took the method from the example in Sayems.

So why I don’t use Sayems in the demo? First of all, the demo is just an easy example. Secondly, I think you must try to create your own scenario using Sayems.

Let’s cook together and tell me about your experience.

--

--

Ferawati Hartanti Pratiwi
Inside Bukalapak

QA (Quality Ambassador) | mpermperpisang official Medium account