Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Text Files as Data Sources
3.
Import the Virtual API
4.
Create a Test Case
5.
Adding Data Source
6.
Configure the Data Source
7.
Configure the Request
8.
Run and Validate Test
8.1.
Run Test
8.2.
Add an Assertion
9.
Frequently Asked Questions
9.1.
Is ReadyAPI and SoapUI the same?
9.2.
Is ReadyAPI open source?
9.3.
Why is ReadyAPI used?
10.
Conclusion
Last Updated: Mar 27, 2024

Text Files as Data Sources in Ready API

Introduction

Hey Ninja! Do you know that Amazon, Facebook, Google, and  Microsoft,  store at least 1,200 petabytes of information? Every day more than 18 billion text data gets created around the world. In this article, we will read about how we can use text files as data sources in Ready API.

Text Files as Data Sources in Ready API

Text Files as Data Sources

Data sources are designed to assist users and programmes in connecting to and moving data to where it is needed. They collect and hide key technical information so that data users can work on processing and determining how to use their data in the best way.

In today's article, we will find out how to use text files as data sources in Ready API.

Import the Virtual API

Before we get started, we have to do a few things. First, we have to import and run a virtual API. It will be the API where the requests will be sent. Let us see the steps to do that.

1. As the first step, we have to download the Packed ReadyAPI project. This is a project that holds or contains the virtualAPI. We can find the same in the following link: Packed Virtual API project.

2. Now, we have to go to ReadyAPI and click on "File". Followed by this, we go to the "ImportPacked Project" option. Doing this will cause a dialog box to appear. There we will choose the ReadyAPI project that we just downloaded.

Import Packed Project

3. Once done with selecting the project to import, we have to select the path where it will get unpacked and saved.

4. This is an optional step. We should know that the default port where the Virtual API runs is 8092. It is suggested that if port 8902 is occupied on the system, we should change the virtual API port.

Select and Run Virtual API

5. Now, we have to select the virtual API in the Navigator. After this, we have to click the "run button". It looks like a green triangle.

Create a Test Case

Now that we have imported the virtual API, it is time to Create a Test Case. As we know, to start working, we need to have a project with a minimum of one test Case.

1. For step one, we have to select "File" and then the "New Functional Test" option. This will make a new functional test.

 Create new functional test

2. Now we have to select endpoint and press "Start". This will take us to the Endpoint Setup page.

Start Endpoint

3. When we reach the Endpoint setup, we will be asked to enter the URL. There we can add up the following.

http://localhost:8092/user?email=
Enter URL

4. Now, we click "Next" at the bottom of the setup prompt. After pressing "Next," we will be taken to the next page of the Endpoint Setup wizard.

5. When we reach the next page of the wizard, we will get the choice to create a new Project. We can click to create a new project for the URL that we have added in the previous steps, or we can add it to an existing project. Now we click next again to proceed.

Specify Project

6. After reaching the next page, we can add assertions to new requests. If we are not using the assertions that are suggested to us, we can unselect them and then click "Next" again.

Add Assertions

7. After we click next, we will find a dialogue box. It will let us add a data source. Here we are going to create the data source manually. So now we close the dialog box to go forward to the next step. Where we will modify the test case that we created, and we will add the File data source.

Add Data

Adding Data Source

For going forward with data-driven testing, we have to employ the Data Source test step. We will add it to the test case here.

1. To start, we have to click on the Generate Values option in the request editor.

Generate Values

2. After clicking on the Generate Values button, the Create Data-Driven Loop dialog box will pop up. There we have to select the request parameters, which will get automatically configured.

Data Driven Loop Dialog Box

After we make our selections, ReadyAPI will automatically make a data source loop. It will also add a property expansion referring to the "email" property. This "email" property is the same one we had in the Data Source test step.

Data Source Test Step 1

3. Now, we will open the Data Source test step. There we can expect ReadyAPI to configure the data source already. This configuration would be to generate random email addresses as email property values.

Data Source Test Step 2

Configure the Data Source

In this step, we will see how to configure the Data Source test step. The configuring will be to use a text file as a data source. Let us go forward with the configuring process step by step.

1. In step one, we will select the File data source.

 Select File Data Source

2. Now, we have to download the sample.txt file. This is for using it as a data source.

3. Now, we will click on Browse and then we will specify the file we downloaded.

4. After this, ReadyAPI will give a popup which will give us the option to import properties. Here, we will add the files manually; we will click on "No".

Option to import Properties

5. Already, the data source has the "email" property. We will click on the "+" button to add the "Expected name" property.

Adding Email Properties

6. Because the colon symbol is used as a separator in the sample file, insert ":" in the Separator field.

Inserting Symbol as separator field

7. To see if the data source is properly configured, we will click on the green triangle/run button and enter the number of rows to get.

We will see that ReadyAPI shows the values that have been obtained in the Data Log.

Interesting the first 10 rows of data Source

After ensuring that the data source is functioning, we may set up the test step to use that data.

Configure the Request

For using the data from a data source, we must change the request test step. Let us get going with the steps to Configure the Request.

 

1. We will switch to the Request tab after opening the Request 1 step editor. If we have already constructed the Data Source loop, the request will include the "${Data Source#email}" value.

Configuring request 1

If the email parameter has a different value, we will type "${Data Source#email}" into it. We can also use the Get Data command to employ a custom wizard to choose the "email" attribute.

 

2. Now, following this, we have to click on the green "send" button. We can find it on the editor toolbar. This is for running the request. On the right, we will see the response data: 

Configuring Request 2

To validate response data, we may now add assertions to the request test phase.

Run and Validate Test

Now, finally, we have to run and validate the test. Let us look at it in steps. We will see the steps in two parts. First, "Run test", and second, "Adding an assertion".

Run Test

We now have a test case with a data source, a test step that uses it, and a data source loop which runs during the test run.

Our test case is ready. To run the test, we have to click on the "run" button in the test case toolbar. It looks like a green triangle.

Running test case

We have to go through the Transaction Log to examine the specifics of the test run. To view the log, we will have to select Transaction Log from the test case toolbar.

Transaction Log option

The Transaction Log give us our test run details.

Transaction Log

If we want to view or check the response to a specific request performed during the run, we have to click on Open in the corresponding row.

Test Step result

Add an Assertion

Now we have to verify the server response. To do this, we have to click on Smart Assertion. We will add up an assertion to confirm the server response.

1. We will open the Request 1 test step. Then we have to click on Smart Assertion.

2. ReadyAPI will display the Smart Assertion dialog box.

Now here, we will select the "name row". Then in the Valid Value cell, we will click on the ellipsis button.

3. Now, we will have the Get Data Dialog. Here we have to select the four parts given to us. They are the test suite, test case, the Data Source test step and the Expected name property. 

Following this, we will click on the "Add" button.

4. Now, we just have to click on Save to create an assertion.

5. We can also find the added assertion in the Assertion panel.

6. Open the test case and press the "run" button once more. It looks like a green triangle. Examine the assertion statuses in the Transaction Log after the test run gets completed. 

Frequently Asked Questions

Is ReadyAPI and SoapUI the same?

SmartBear's SoapUI is an open-source solution for automated web service testing. It can be used to automate functional and security API tests. ReadyAPI is an API-ready platform that contains a test module for the coming generation of SoapUI.

Is ReadyAPI open source?

ReadyAPI Virtualization is a component of the ReadyAPI family that is not included in SoapUI Open Source. As a result, any ReadyAPI Virtualisation or virtual service functions will not work with SoapUI Open Source.

Why is ReadyAPI used?

ReadyAPI enables teams to build, organise, and execute automated security, functional,  and performance tests in a single centralised interface, hence speeding up API performance for Agile and DevOps software teams.

Conclusion

This article taught us how to write a data-driven test that uses a text file as a data source. We broke down the whole step into different parts and explained them in simple steps. Refer to our courses and explore Coding Ninjas Studio to find more exciting stuff. You can also look into the interview experiences and solve different problems. Look into our Guided paths, test series, libraries and resources to know more.

Thank You

Happy Coding!

Live masterclass