Simple Automation Testing on GoFood Website with Robot Framework

daniel yoga
4 min readAug 28, 2024

--

In this article, we’ll explore how to use Robot Framework to automate testing of the GoFood website. We’ll cover the test case structure, keywords, and element selectors used in our automation script.

Gherkin Syntax Overview

Our test case uses Gherkin syntax, a simple, readable format for describing test scenarios. Gherkin uses keywords like Given, When, Then, and And to structure test steps. This approach improves readability, supports Behavior-Driven Development (BDD), and facilitates collaboration between technical and non-technical team members.

Test Case: Exploring GoFood by Location and Filtering Restaurants

Our main test case is structured using Gherkin syntax:

*** Test Cases ***
Scenario: Explore GoFood by location and filter restaurants by proximity and rating
[Documentation] Go To gofood.co.id -> select location : use your current location
Given I open GoFood website
When I enter location and confirm selection
Then I should see different food categories
And I filter by restaurants near me
And I filter by best-selling restaurants
And I search for a specific restaurant

Let’s break down this test case:

  1. Scenario: This describes the high-level behavior we’re testing — exploring GoFood, filtering restaurants, and searching.
  2. [Documentation]: This provides a brief description of the test case’s purpose and main steps.
  3. Given I open GoFood website: This step sets up the initial context by opening the GoFood website.
  4. When I enter location and confirm selection: This is the main action that triggers the behavior we want to test.
  5. Then I should see different food categories: This is our first assertion, verifying that the expected food categories are displayed after selecting a location.
  6. And I filter by restaurants near me: This step tests the proximity filter functionality.
  7. And I filter by best-selling restaurants: This step tests the rating filter functionality.
  8. And I search for a specific restaurant: This final step tests the search functionality.Let’s break down each of these steps and examine the keywords and selectors used to implement them.

Keywords and Element Selectors

1. Opening the GoFood Website

I open GoFood website
New Browser chromium headless=No
New Page ${GO_FOOD_URL}

This keyword uses the Browser library to open a new Chromium browser in non-headless mode and navigate to the GoFood URL (https://gofood.co.id/).

2. Entering Location and Confirming Selection

I enter location and confirm selection
Type Text ${LOCATION_SELECTOR} ${LOCATION}
Sleep 2s
Wait For Elements State ${FULL_LOCATION_SELECTOR} visible timeout=10s
Click ${FULL_LOCATION_SELECTOR}
Click ${EXPLORE_BUTTON}

This keyword performs the following actions:

  • Types the location (“Ashta”) into the location input field
  • Waits for the full location suggestion to appear
  • Clicks on the full location suggestion
  • Clicks the “Explore” button

Element selectors used:

  • ${LOCATION_SELECTOR}: //input[@placeholder="Enter your location"]
  • ${FULL_LOCATION_SELECTOR}: //p[text()='${FULL_LOCATION_NAME}']
  • ${EXPLORE_BUTTON}: //span[text()='Explore']

3. Verifying Food Categories

I should see different food categories
Wait For Elements State ${NEAR_ME_SECTION} visible
Wait For Elements State ${BEST_SELLERS_SECTION} visible
Wait For Elements State ${BUDGET_MEAL_SELECTOR} visible
Wait For Elements State ${MOST_LOVED_SELECTOR} visible
Wait For Elements State ${HOURS_24_SELECTOR} visible
Wait For Elements State ${HEALTHY_FOOD_SELECTOR} visible
Wait For Elements State ${PASTI_ADA_PROMO_SELECTOR} visible

This keyword checks for the visibility of various food category sections on the page.

Element selectors used:

  • ${NEAR_ME_SECTION}: //h3[@title='Near me']
  • ${BEST_SELLERS_SECTION}: //h3[@title='Best sellers']
  • ${BUDGET_MEAL_SELECTOR}: //h3[@title='Budget meal']
  • ${MOST_LOVED_SELECTOR}: //h3[@title='Most loved']
  • ${HOURS_24_SELECTOR}: //h3[@title='24 hours']
  • ${HEALTHY_FOOD_SELECTOR}: //h3[@title='Healthy food']
  • ${PASTI_ADA_PROMO_SELECTOR}: //h3[@title='Pasti Ada Promo']

4. Filtering Restaurants by Proximity

I filter by restaurants near me
Click ${NEAR_ME_SECTION}
@{RESTO_CARDS} Get Elements ${DISTANCE_TEXT_ON_RESTAURANT_CARDS}
FOR ${RESTO} IN @{RESTO_CARDS}
${RESTO_DISTANCE} Get Text ${RESTO}
${DISTANCE_STR} Fetch From Left ${RESTO_DISTANCE} km
${DISTANCE_STR} Strip String ${DISTANCE_STR}
${DISTANCE} Convert To Number ${DISTANCE_STR}
Should Be True ${DISTANCE} <= 0.5 Distance ${DISTANCE} km exceeds maximum 0.5 km
END

This keyword clicks on the “Near me” section and verifies that all displayed restaurants are within 0.5 km of the selected location.

Element selector used:

  • ${DISTANCE_TEXT_ON_RESTAURANT_CARDS}: //*[@id="__next"]/div/div[3]/div[1]/a/div/div[2]/div[2]

5. Filtering Restaurants by Ratings

I filter by best-selling restaurants
Go Back
Click ${BEST_SELLERS_SECTION}
@{RESTO_CARDS} Get Elements ${RESTO_RATING_TEXT_ON_RESTO_CARDS}
FOR ${RESTO} IN @{RESTO_CARDS}
${RESTO_RATING} Get Text ${RESTO}
Should Be True ${RESTO_RATING} >= 4.3 Rating ${RESTO_RATING} below minimum 4.6
END

This keyword navigates back to the main page, clicks on the “Best sellers” section, and verifies that all displayed restaurants have a rating of at least 4.3.

Element selector used:

  • ${RESTO_RATING_TEXT_ON_RESTO_CARDS}: //*[@id="__next"]/div/div[3]/div[1]/a/div/div[1]/div[2]/div

6. Searching for a Specific Restaurant

I search for a specific restaurant
Go Back
Wait For Elements State ${SEARCH_BUTTON} visible
Click ${SEARCH_BUTTON}
Type Text ${SEARCH_INPUT} Secbowl
Click ${SEARCH_RESULT}

This keyword performs a search for a specific restaurant (“Secbowl”) and clicks on the search result.

Element selectors used:

  • ${SEARCH_BUTTON}: //a[@href="/en/search"]
  • ${SEARCH_INPUT}: //input[@id="search-query"]
  • ${SEARCH_RESULT}: //p[text()='Sec Bowl, Cikajang']

Conclusion

This Robot Framework script provides a comprehensive test for the GoFood website, covering key functionalities such as location selection, category browsing, restaurant filtering, and search. By using descriptive keywords and clear element selectors, the script is easy to read and maintain.

To run this test, ensure you have Robot Framework and the Browser library installed, then execute the script using the robot [filepath]command. This automation can be integrated into a continuous integration pipeline to ensure the GoFood website functions correctly across different environments and code changes.

Access full code here : https://github.com/danielyoga/mini_tutorial_robot_framework/blob/main/MINI_GOFOOD_Website_robot_framework.robot

--

--