No votes yet.
Please wait...

Karate framework is quite a new product on the market of specialized web tools for virtual service testing. Even though it was created on the base of Java programming language, its main value lies in the fact that a tester doesn’t have to be familiar with peculiarities of the testing process on this language or test automation.

This article is a kind of practical guidance on how to use this tool in QA engineers’ daily life, who perform automated software testing.

System Environment for Karate Usage

Since this product is developed on Java, it can be launched almost everywhere (there are no special technical or system restrictions set by developers).

Specialists create a new project with the help of various samples that are widespread on the Internet. For example, one can use personal Maven samples.

Also, note that this product has a classic directory for projects on Java + CucumberJVM.

After a thorough reading of the technical documentation of the product, you can notice some recommendations from developers. They recommend uploading all the feature files in a special directory: scr/test/java.

Karate Framework

Karate Framework

IDE usage

It is said in the technical documentation to use Eclipse and IntelliJ-IDEA for test case creation. It’s a good thing that both IDE completely supports Junit and Cucumber. Hence, Karate can be used while performing tests and editing scenarios that are being tested.

On the Internet, there is a lot of information about Karate and VisualStudio performance. People who use this combination point out at the following:

  • Quick and simple technical support;
  • Great interaction with Gherkin and Java;
  • Ability to use a personal file manager with a built-in terminal.

On the screenshot below, you can see an example of Karate usage in the VisualStudio system on a real project.

Karate usage in VisualStudio

Karate usage in VisualStudio

Examples of Project Templates in Karate (+ Code)

So, you can conduct a classical (template) test in the users.feature file by checking the way how to get users from JSONPlaceholder REST API

Feature: sample karate test script
Background:
* url ‘https://jsonplaceholder.typicode.com
Scenario: get all users and then get the first user by id
Given path ‘users’
When method get
Then status 200
* def first = response[0]
Given path ‘users’, first.id
When method get
Then status 200

On the example, you can see the traditional If-When-Then format. But, in comparison with the widely used Gherkin, the Karate’s classic test stages make testing more powerful and more productive from the technical side. Namely:

  1. Given-steps develop the necessary queries;
  2. When-steps send requests;
  3. Then-steps validate requests;
  4. Catch-all help with additional conditions (for example, they can create space for the necessary variables).

Test steps are very simple. Using Java is visually hidden from the tester’s eyes, but he/she can always search for it in the levels of the framework. Moreover, such a test scenario clearly shows how to correctly apply the data from the received answer as a special input for a subsequent request (and so forth and so on).

Rules for Conducting Test Cases

Since we chose Maven (as a template) and VisualStudio for testing, the simplest and most effective way to perform checks without additional settings is to use the command line with a special mvmtest command.

Test results are uploaded in the form of an exampletest java document. Such a file can hold all feature documents in a test suite.

By the way, the Karate framework supports jUnit4 by default. Nevertheless, one can also use jUnit5 on specific projects.

Test execution is based on using a large number of lines inside the console. Any request will be displayed there.

Features of the Autonomous Test Run

Creating tests based on Karate domain-specific language does not make a Java programmer or tester to fully understand the Java language. But setting up a complete project configuration still needs some knowledge. It’s very good that Karate provides a fully autonomous JAR that requires running files without any dependencies or configuration.

The system just takes the necessary files, makes correct paths to them, and run them making detailed Cucumber-reports. This JAR is a great option for testers who don’t have extensive experience in programming.

 

A report, generated with JAR

A report, generated with JAR

In the picture above, you can see a detailed report generated with JAR.

Other Peculiarities

Karate has a lot of peculiarities that are worth to try, namely:

  • Parallel activation of several test suits;
  • Imitation of servlet;
  • Graphical interface for visual debugging of the test scenarios;
  • Exploring different types of files to create variables;
  • Using one feature files from another feature file structure;
  • Using (invoking) the Java program code;
  • Test scenario usage (for example, Gatting performance test).

Conclusion

In general, this is a very practical and convenient tool for various web service testing. It can work with program deployment specifications. Hence, a tester can focus on necessary test performance.

To use this tool for 100%, one should have at least a basic knowledge of programming. Tests can be run only on the base of Java commands, and all the feature files are simply the usual test steps. Also, a project under test can have its API, program code by default.

Leave A Comment

WP Facebook Auto Publish Powered By : XYZScripts.com