Create Your First API/Web Service Test Using Katalon Studio – DZone Integration | xxxCreate Your First API/Web Service Test Using Katalon Studio – DZone Integration – xxx
菜单

Create Your First API/Web Service Test Using Katalon Studio – DZone Integration

九月 26, 2018 - MorningStar

Over a million developers have joined DZone.
Create Your First API/Web Service Test Using Katalon Studio - DZone Integration

{{announcement.body}}

{{announcement.title}}

Let’s be friends:

Create Your First API/Web Service Test Using Katalon Studio

DZone’s Guide to

Create Your First API/Web Service Test Using Katalon Studio

Learn how Katalon Studio can help you easily set up automation testing for your API and web services.

Oct. 15, 18 · Integration Zone ·

Free Resource

Join the DZone community and get the full member experience.

Join For Free

SnapLogic is the leading self-service enterprise-grade integration platform. Download the 2018 GartnerMagic Quadrant for Enterprise iPaaS or play around on the platform, risk free, for 30 days.

API testing has become increasingly crucial in software testing. Testing APIs is no longer performed solely by the original developers. Instead, this is currently a common practice among outsourced teams that independently verify and validate their products. A solid skill set in API testing will set you apart from other developers. Also, this practice will continue to be in high demand for the future to come.

This tutorial is designed to provide you with step-by-step instructions on how to create your first API/web service test using Katalon Studio.

Install and set up Katalon Studio

For detailed instructions of installing and setting up Katalon Studio, please refer to this guide.

Create a New Project and Set Up an API Automation Test

Step 1: Create a New Project

Go to File → New → Project. Enter a project name and its location to start a new project.

Create Your First API/Web Service Test Using Katalon Studio - DZone Integration

Once the project is confirmed to be created, you will see a folder structure in the Test Explorer panel. This folder system serves to keep all test resources. It is also where you start your first API test.

Step 2: Create a New API Test

Before creating your first API test, let’s have a look at the format used to set up a testing project.

Object Repository

An Object Repository is a place that stores all Web service endpoints along with all the information about request methods, URL, header, content, and authentication.

Web service test objects in an Object Repository are integrated by a folder system for better management.

Test Cases

Test Cases store all test scenarios and are categorized by a folder system. Each test case includes a few steps that illustrates a test scenario.

You can execute a test case individually with a specified execution profile.

Test Suites

Test Suites are where all test suites are stored. A test suite is a collection of test cases that verify a specific target.

Test cases at the ‘test suite’ level can be executed with a data-driven approach.

Test reports are also generated at the ‘test suite’ level.

Test Suite Collection

A Test Suite Collection is a collection of Test Suites that verifies a larger target.

Test Suites at the ‘Test Suite Collection’ level have specific Test environments specified.

Create Your First API/Web Service Test Using Katalon Studio - DZone Integration

Step 3: Create a new RESTful Endpoint at the Object Repository

Object Repository → New → Web Service Request

Create Your First API/Web Service Test Using Katalon Studio - DZone Integration

Katalon Studio stores Web service endpoints for testing at Object Repository, which is similar to Test Object in UI Test. At the “Create New Web Service Request” dialog, you can either choose to create a RESTful or a SOAP request.

“Request type” is a required field. You need to specify it at this step. In contrast, “URL” is not required. You can set this value later in the next step.

Create Your First API/Web Service Test Using Katalon Studio - DZone Integration

Click “OK.” Then we are ready to input more details to the first RESTful test.

Create Your First API/Web Service Test Using Katalon Studio - DZone Integration

There are some important concepts we need to specify when testing a RESTful request:

(1) Request method

You can choose one of the following methods for your first request test: GET, POST, PUT, or DELETE. The method needs to match with the URL to have a valid request. For instance, let’s assume that your first test is a public API from Jira Cloud. In this case, you should select the GET method to receive information of an existing ticket using its ID.

(2) Request URL

Along with the request method, “request URL” tells the web server which API is utilized under the test. Any mismatch between method and URL will lead to an invalid request exception at runtime or an incorrect data response.

(3) Authorization

Authorization is an essential part of an API. It is used to get the correct data under permission (unless the data is public). Katalon Studio supports common authentication methods:

Basic:

The basic method requires username and password. Don’t forget to click ‘Update to HTTP Header’ so that the authentication can be applied to ‘HTTP Header’.

Create Your First API/Web Service Test Using Katalon Studio - DZone Integration

Create Your First API/Web Service Test Using Katalon Studio - DZone Integration

(4) Verification

Verification is where you define assertions to ensure the response will contain the expected information.

Create Your First API/Web Service Test Using Katalon Studio - DZone Integration

The verification tab of a request is similar to the Script tab of a test case. In other words, you can write custom scripts with built-in keywords or Groovy/Java scripts to verify the response data. Besides built-in keywords, Katalon Studio also supports built-in snippets, which help you generate assertions with a single click. This feature is useful for testers who might find it difficult to deal with parsing or to assert with JSON.

The right panel of the request consists of the responses automatically displayed in a nice format, and the verification results in the Verification Log. To include verification scripts when sending the request, you need to choose the ‘Test Request and Verify’ option from the execution button.

The verification script gives you quick feedback of the request status rather than an actual test. You can add more assertions at the ‘test case’ level in the next step.

(5) Variables

Variables make API testing more robust and dynamic with the data-driven approach. In Katalon Studio, every part of the request can be parameterized. In other words, dynamic data can be used for: URL, authentication, HTTP Header, and HTTP Body to maximize the capability of data-driven testing. Let’s have a look at this example:

Create Your First API/Web Service Test Using Katalon Studio - DZone Integration

(6) Formatter

The response will be automatically displayed in a neat format: JSON, XML, HTML, and JavaScript. This gives you a quick view of the response status.

Step 4: Create a New Test Case With an Existing Request 

While the request at the Object Repository is helpful for fast testing, you can add the request verification at the test case level for better managing and reporting.

Step 5: Add an Existing Request to a Test Case

A request can be inserted to a test case with Web service built-in keywords. There are many keywords that can be used to send the request, to verify the response, and to make the request as part of a bigger testing flow.

Create Your First API/Web Service Test Using Katalon Studio - DZone Integration

The following test case illustrates how we can call the request with verification steps from a test case:

Create Your First API/Web Service Test Using Katalon Studio - DZone Integration

The test case can be executed as a normal test case in Katalon Studio. Each verification step can be viewed from the log.

Create Your First API/Web Service Test Using Katalon Studio - DZone Integration

Step 6: Add a Test Case to a Test Suite

A test case can be added to a test suite via either the drag-and-drop feature or the “Add test case” tool. Once the test case is added to the test suite, we can execute the entire test suite with the Run button (without selecting the browser as in UI testing)

Create Your First API/Web Service Test Using Katalon Studio - DZone Integration

Next Steps

Now you have finished creating your first test. To create tests for a real project with practical solutions, we will need to create more tests with more techniques:

  • Parameterize your tests
  • Apply data-driven approach
  • Create custom keywords/packages
  • Call tests and reuse code
  • Include error handling
  • View test reports after test suite execution

Katalon New Features

Katalon Studio has recently had a new monthly release to support BDD Cucumber, which is a testing approach in which test cases are written in natural languages to improve communication between technical staff and business stakeholders. BDD Cucumber also helps create test scenarios for the acceptance test phase.

@Issue_Tests Feature: Verify issue information  Background: Given The Jira System is available  @Get_By_Id Scenario: Verify issue information by Id When I get information of an issue with Id "KD-1" Then I get response code "200" And The issue information as below: |project_key |issue_type |priority |summary | |KD |Bug |Low |REST - Createnew issue using API|  @Get_By_Id Scenario Outline: Verify issue information byId When I get information of an issue withId"<issue_key>" Then I get response code "200" And The issue information as below: |project_key |issue_type |priority |summary | |<project_key> |<issue_type> |<priority> |<summary> |  Examples: |issue_key|project_key |issue_type |priority |summary | |KD-1 |KD |Bug |Low |REST - Createnew issue using API| |KD-2 |KD |Bug |Low |Update summary from API example |

With SnapLogic’s integration platform you can save millions of dollars, increase integrator productivity by 5X, and reduce integration time to value by 90%. Sign up for our risk-free 30-day trial!

Topics:
katalon studio ,api testing ,integration ,automation testing ,tutorial

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.linkDescription }}

{{ parent.urlSource.name }}

· {{ parent.articleDate | date:’MMM. dd, yyyy’ }} {{ parent.linkDate | date:’MMM. dd, yyyy’ }}


Notice: Undefined variable: canUpdate in /var/www/html/wordpress/wp-content/plugins/wp-autopost-pro/wp-autopost-function.php on line 51