Spring Boot , Kotlin, Cucumber, Gherkin , Selenium

Spice Up Your ‘CI/CD Process’ With Automation using Cucumber, Selenium, and Kotlin

Ashok Gudise
5 min readSep 20, 2022

Continuous Integration & Continuous Deployment

Imagine you are working on a two weeks sprint, and your agile teams have different assignments that can be only tested through Integration Tests, which may take numerous builds in shorter periods. I still remember that I have been yelled at by a Build Engineer for asking three builds within an hour. Now with the power of CI/CD, 60% of this problem is solved with Rapid releases with just a click of the mouse or build-hooks.

Problem Statement

Your PL/SQL Developer has optimized an SQL Query which works like a charm, now he wanted to tweak the Stored Procedure furthermore and he wanted a Quality Engineer to do the regression testing.

App Developer has fixed one issue that has something to do with user-login sessions or some complex logic that renders a huge list of items. It worked just fine in his local machine but he wanted a Quality Engineer to do the regression testing.

Also, the Web Analytics team wanted to add tags and test the trends in a repeated manner, and they wanted a Quality Engineer to do the regression testing.

Hope you got my point now! All of these teams wants do these changes repeatedly (needless to mention the number of the builds) and they all wanted to perform regression tests on a Dev or SIT environment. Well, I see this as almost a Six Months Project based on the team’s availability and other dependencies.

And, adding Browser Automation to your CI/CD is obviously the best complementing solution, but how you do that is something that really matters!

Technical Stack

I choose Cucumber, Gherkin, Kotlin, Selenium, JUnit 5, and Spring Boot framework. And IntelliJ Idea & Selenium IDE (Chrome Browser Add-On), and Chrome Webdriver (if you are running in local) or Selenium Grid.

Gherkin 🤝 Cucumber

We do not go into detailed discussion about these topics as there are many blogs available to explain what they are, I have added a couple of them at the end of this blog. On a high level, Gherkin is a plain English test, a well-known standard representation of Behavior Driven Development (BDD in short form) scripts. A cucumber is a testing tool that supports BDD frameworks to run your test cases written in Java, Ruby, Node, and many other languages. That association is represented as Glue in Cucumber.

You will bridge the “.feature” files written in Gherkin language and associate them to the steps with the choice of your favorite programming language.

Cucumber 🤝 Selenium IDE

Browser Automation is often a tedious process if you do not use the correct tools. In the preliminary step to capture browser elements, if you right-click on your web browser and then select the web component by ‘inspect element’, it takes forever to capture these elements in a complex flow. And the quickest possible way to capture these is by using Selenium IDE ( A Chrome Browser Add-On). Just add the plugin, click the ‘REC’ord button, and navigate to your complete flow. When you are done with the flow, Selenium will provide you with a wide variety of options for every single component that you interact with in your flow (CSS Selector, XPath, Relative XPath, Id and Name, XPath is always my safe bet if you ask me).

Kotlin 🤝 Cucumber

As I mentioned in my previous blog post, Kotlin eliminates most of the boilerplate code and gives you many powerful features like Null Safety, Safe Calls, Lazy Properties, Scope Functions, and last but not least Coroutines.

If you are familiar with writing Cucumber test scripts, we often write these using the Page Object Model. It makes it much easier when using Kotlin to do this.

Please explore my other blog post mentioned below to learn how to avoid unintended profile activation in the realm of automation.

Enough of the Talk!

Now let’s Write some code (in just four steps).

1. Write a Cucumber feature file as shown below.
Remember, Gherkin is just plain English!

search-my-name.feature

2. Write a Page Object file with web elements that you have captured with Selenium IDE.

SearchPage.kt

3. Glue Your search-my-name.feature” file with “SearchSteps.kt” using “SearchPage.kt” elements.

SearchSteps.kt

4. You are All Set!,
Now you can do either of these to run this test.

Right click on Test Class and Run As JUnit Class
or
Right Click on search_my_name.feature and run
or
Run “mvn clean test” command

Execution Logs
{project-root}/target/cucumber-reports/cucumber.html

5. Now the Bonus part!
If you are using Jenkinsfile (groovy script) to deploy your app, add below snippet in your post build stage. You can check more about
this here.

// Cucumber report plugin
cucumber fileIncludePattern: ‘**/java-calculator/target/cucumber-report.json’, sortingMethod: ‘ALPHABETICAL’

//publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: true, reportDir: ‘/home/reports’, reportFiles: ‘reports.html’, reportName: ‘Performance Test Report’, reportTitles: ‘’])

You should see something like this report in your Jenkins Pipeline page.

Jenkins build report in pipeline

If you found my blog posts enjoyable and gained new insights, I kindly ask you to think about sharing them and joining me here for future updates. You can find the source code on my GitHub. You can reach out to me on LinkedIn for any questions or suggestions.

References: Thanks to Onur Baskirt for his detailed blog on this topic.

That’s all for now, Happy Learning!

--

--

Ashok Gudise

I am an enthusiastic learner who is curious to learn new market trends and new technologies that make software engineering much more robust and easy to learn.