GO-vatar series: Android and Golang alliance to form an automation

Ferawati Hartanti Pratiwi
2 min readFeb 3, 2021
https://hsto.org/files/31c/b52/87b/31cb5287bccd4013b9e8ed2b4b448edd.png

Golang mutant?! :D

Do you read my GO-vatar series: Recipe To Boil Web Automation With Go Language or GO-vatar series: Early Battle to Become The Master of All Automation Platform article? This article is a continuation of those 2 articles. But this time, we will only focus on Android.

I don’t wanna waste your time let’s just get on with it.

This time we have to define page object.

We’re using struct pointer here to direct us to another page object. From the example above, if we waiting for Mulai button it will direct us to the onboarding page. Then if we click Mulai button, it will direct to new page (home page). We need 1 element for this page, but if we want then we can add many elements as we want.

var (  btnMasuk      = "Masuk"  btnMengerti   = "//*[contains(text(), 'Mengerti')]"  btnNantiSaja  = ".qa-nanti-saja-button")

That element variable example has 3 different types of element. Using the text/label, the Xpath and the CSS.

How we handle it?

First, we need to modify this code first.

Before, we’re not define the Device variable. Just change above code to be this one.

if Device, err := Driver.NewDevice(); err != nil {
log.Fatalln(aurora.Bold(aurora.Red(err))) }

Method action

What is method action? Method that do something like click or input text.

After we define the Device variable we just need to call the action like this.

We could use struct or just a normal function to call the action in page object.

appsaction.ClickByXPath(btnMengerti)

The Mengerti button will be clicked by the XPath selector.

Method validation

There is action, there is validation. I want to validate the the button I clicked, can direct me to the correct page (Let’s say the home page).

Step definitions

After we create action/validation method and page object, the next step is set the step definitions.

You can check my golang-automation repository for the complete code. I’m totally using struct pointer to create action/validation method, page object and also step definitions. With use struct pointer, we need to define the method in page object very well because if not it seems to confirm that we have wrongly defined the step definition and also the page object itself.

--

--

Ferawati Hartanti Pratiwi

QA (Quality Ambassador) | mpermperpisang official Medium account