The Relationship of Behavior with Test Automation- BDD and Gauge(Part 2)

Numanhan Duran
4 min readJan 2, 2022

Hello everyone again. In my previous BDD article, I made a little introduction by talking about how to express test automation with behaviors. In this article, I will try to explain with some examples. If our teas are ready, let’s get started. :)

As you know, Gauge, together with Selenium in Web test automation processes, helps us to run our tests and see the results by creating scenarios with the language we use in daily life. In the previous article, we talked about how to install our own environment. I would like to talk about the structure of the Maven project we created after the installations.

Project Structure

In general, we have made it a habit to use the Page Object Model in our sample projects. Thanks to this structure, we define all of the constant structures that we will use within the “@BeforeScenario” and “@AfterScenario” methods before and after all our test scenarios are started, on one page.

I would like to convey my love to my dear friend Serda Ucar, who never spared him help while working on this structure.

As you will see in this class we created, the requirements and properties that we will use throughout the whole process are defined in this class. The benefit of this structure saves us from making these definitions over and over in every test run.

After making all these definitions, we can write all the test methods that we will inherit throughout the project in the new class we will create. Here, the whole subject can develop depending on you and the project. You can use all the methods that Selenium includes, such as finding an element, clicking on an element, sending a value, according to your needs.

We have created the necessary methods as you can see in the code snippet I shared above. There will be a dynamic wait method that will catch your attention. This dynamic wait state is actually a method that we have created to wait for the element you will operate on the page to load on the page. When you want to find every element without creating this method, you can write it over and over again, it’s all about your structure.

We have created our methods by taking extends from BasePage class in the FunctionClass class you see in the picture. These methods allow you to perform the actions you will take on the page by using the methods we created using Selenium on the BasePage page. If we explain with a small example;

In this class, it is now clear which element we will click on and what action we will do with which element. It’s time to write their tests and create these tests one step at a time. In the FunctionPageTest page we created, we call our methods by extending the FunctionClass class. We make it ready for BDD structure by adding a step to the methods we call. It is important that we extend the BaseTest class here, because our tests will run based on it.

When we create a Gauge project, it automatically brings us the .spec file and the folder structure. It’s time to write these steps in .spec. Here you can follow two different paths. First, we can only run our tests under .spec. As a second way, we can create the .cpt file and expand our tests and test it by collecting it under .spec. The second way can generally allow us to do end to end testing or run the test of the whole project and report when a new release is released.

In general, we talked about how to follow the Gauge structure and how to create a test automation project. Do not forget to define the web driver you will use while creating your project. I also used the Log4j library in this project. Do not forget to make your definitions of this library.

To summarize; Gauge allows us to create a test automation project in daily language, to easily organize our tests each time a feature comes, and to report the tests we run. It offers a structure that can understand what you are testing, even if you pull a passerby by the arm one day and read it. :)

In our next article, we will continue the mobile test automation project. When we look at it, it has a structure that does not contain big differences. Then I will try to talk about CI/CD processes and how to integrate an automation project into the CI process. Maybe I’ll talk a little bit about using Jenkins. Then we talk about the structures that we will use for Backend and API tests. I hope it was a useful writing. I wish everyone a year full of goodness and good health. Happy new year :)

--

--