Karate DSL is a great framework for performing API automation with ease. Good news is that now it supports UI automation as well which is making it more powerful. In this post I am going to explain how we can do both API and UI automation in a single script using Karate DSL. If you are not aware of Karate DSL or have not used it before I would recommend you to visit the link https://github.com/intuit/karate before trying the example below. 

Prerequisite: 
1) Java and Maven installed in your system 
2) I have used visual Studio code IDE with Karate Extension. If you want to use any other IDE (Eclipse or IntelliJ IDEA ) feel free to do so. 

Creating a project: This is very simple process, the following maven command should create a example working project for you instantly. mvn archetype:generate -DarchetypeGroupId=com.intuit.karate -DarchetypeArtifactId=karate-archetype -DarchetypeVersion=0.9.5 -DgroupId=com.karate-demo -DartifactId= 

Scenario under test: I have identified the following scenario for this demo: 
1) Open the link https://galaxy.ansible.com/ 
2) Click on the System category 
3) Search for collection or category with keyword 'docker' 
4) Capture the search result count 
5) Send a GET request to URL https://galaxy.ansible.com/api/internal/ui/search/?tags=system&keywords=docker&order_by=-relevance&page=1 
6) Validate that the search result count from the response is same as captured in step four. 

Now we need to create the feature file using Karate DSL keywords. Please follow the below steps: 

1) Create a new feature file or modify the one created by default while creation of the project. 
2) Add scenario specific steps using the Karate keywords in the feature file (use this link for reference https://github.com/intuit/karate/tree/master/karate-core ). I added the feature file created by me at https://github.com/dimpyad/karate-dsl-demo/blob/master/src/test/java/examples/features/search.feature 3) You can use common.feature for any common steps 
4) You can use json file for keeping your locators. 
5) Anything related to test configuration like urls, timeout value etc can be added to karate-config.js 
6) You can run all the tests using mvn test command 

What is the advantage of using Karate DSL here instead of using selenium/rest assured directly? As per me I could see the following benefits: 
1) I have not added any single line of code for automating this scenario except just one feature file . 
2) No need for separate page object classes, locators captured in file can be very well used using keywords. 
3) I could combined easily UI and API tests in a single file.
4) All other needs for making the automation process smooth like web and mobile browser support, docker execution support, creating reports, logs and many more are available for use within the framework. 

 I have added the sample project created by me at https://github.com/dimpyad/karate-dsl-demo . Feel free to clone and use the same and let me know your comments.