If you want to do automatic API testing, but have no programming background, then you must give Karate a chance!
Karate
Unlike other automated API testing tools that require a lot of coding, Karate does even the basics right out of the box. You can build the most complex request-response operations without knowing any programming language. All you have to do is write factor files in plain text Gherkin style.
Because Karate is a full DSL and sits on top of Cucumber-JVM, you can run tests and generate reports just like any standard Java project, but instead of writing Java code, you write tests in a language that handles HTTP, JSON. Or XML is easy to use.
While there are no prerequisites for using Karate, it helps if you have a basic understanding of HTTP, JSON, XML, JsonPath, as well as XPath and JavaScript.
Below, we’ll cover some typical actions you typically perform in automated API testing, but first a quick guide to setting up the environment for Karate.
Maven
If you are using Maven, you need the following two dependencies
< the dependency > < groupId > com. Intuit. Help < / groupId > < artifactId > help - apache < / artifactId > < version > 0.6.0 < / version > <scope>test</scope> </dependency> <dependency> <groupId>com.intuit.karate</groupId> <artifactId>karate-junit4</artifactId> < version > 0.6.0 < / version > < scope >test</scope>
</dependency>
Copy the code
Gradle
Or, if you are using Gradle, yes
testCompile 'com. Intuit. Help: to help - junit 4:0.6.0'
testCompile 'com. Intuit. Help: to help - apache: 0.6.0'
Copy the code
Folder structure
Karate test scripts have a.feature file extension followed by Cucumber standards. You can organize files freely using regular Java package conventions.
Maven’s tradition is to place non-Java source files in a separate SRC /test/ Resources folder structure – but the creators of the Karate tool recommend that you place them side by side with *.java files.
Karate Api test tool – Folder structure like Cucumber, you need a “Runner” class to run feature files. However, unlike Cucumber, there is no step definition! This is the magic of Karate.
To use the Testrunner.java class to execute the element file, you need to include the build section in the pom.xml file.
<? xml version="1.0" encoding="UTF-8"? > <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> < modelVersion > 4.0.0 < / modelVersion > < groupId > Tutorials < / groupId > < artifactId > help < / artifactId > 1.0 the SNAPSHOT < version > < / version > < dependencies > < the dependency > < groupId > com. Intuit. To help < / groupId > If the software testing, interface testing, automation testing, performance testing, LR script development, <artifactId>karate-apache</artifactId> interview experience exchange. If you are interested in </dependency>, you can contact 175317069. There will be free <version>0.6.0.4</version> information links in the group from time to time. These information are collected and sorted out from various technical websites. I will quote the source and share it with you. < the dependency > < groupId > com. Intuit. Help < / groupId > < artifactId > help - takeup < / artifactId > < version > 0.6.0.4 < / version > </dependency> </dependencies> <build> <testResources>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
</build>
</project>
Copy the code
Your Testrunner.java class looks like
package com.tutorials.karate;
import com.intuit.karate.junit4.Karate;
import org.junit.runner.RunWith;
@RunWith(Karate.class)
public class TestRunner {
}
Copy the code
Use Karate for simple automated API tests
Suppose you are testing the API (some-api.com/api/users),…
[{"id": 1,
"name": "FirstUser"."password": "User1Pass"
},
{
"id": 2."name": "SecondUser"."password": "User2Pass"}]Copy the code
Your Karate feature file looks like this:
Feature: Test User API
Scenario: Fetch all users
Given url 'https://some-api.com/api/users'
When method GET
Then status 200
And assert response.length == 2
And match response[0].name == 'FirstUser'
Copy the code
That’s it – very concise and, importantly, no code!
Karate has a wealth of utility features that make it easy and fast to perform automated API testing. Later, we’ll delve into this amazing tool and give examples of how to do anything you need when testing your API!