Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Hello ninjas, hope you are well. In this blog, we will understand Excel files as Data sources in Ready API.
You can use the potent instrument of data sources in ReadyAPI to build data-driven tests. By default, data sources only give any test step that requests the data they collect from the source. They are unable to control or alter the data in any manner.
Excel Files as Data sources in Ready API
You might want to test various requests stored in XML or text files. You can leverage data sources connected to files to do this.
This article explains how to do data-driven testing using Excel files.
Some data sources are available for functional tests and virtual services, while others are only accessible during functional testing.
Data Source
Description
Connection to data
uses a JDBC connection to retrieve data from a database. Although it uses preconfigured JDBC database connections, it is comparable to the JDBC data source.
Data Generator
Uses the built-in data generating engine to produce data.
Excel
Obtains information from the Excel tables.
File
Line-by-line material from the provided file is obtained.
JDBC
Uses a JDBC connection to retrieve data from a database. It uses a connection indicated in the data source, unlike the Data Connection data source.
Grid
It gets the data that is supplied in a grid.
Groovy
The data is generated using a Groovy script.
JSON
It uses JSONPath expressions to extract the desired info from the JSON content.
XML
It utilizes XPath expressions to extract the needed data from the XML text.
Install the Virtual API
In Excel files as Data sources in Ready API, a virtual API must be imported and executed for requests to be routed there.
Step 1: Download the virtual API's packed ReadyAPI project here:
Step 2: Choose the downloaded project in the window that appears by choosing file> Import Packed Project:
Step 3: Indicate the location where the project will be saved and unzipped.
Step 4: The project's virtual API typically operates on port 8092 by default. Change the virtual API port if this port is already in use on your computer.
Step 5: Click to launch the virtual API after selecting it in the Navigator(green pause button):
Build a Test Case
In Excel files as Data sources in Ready API, you must have a project with at least one test case to start.
Step 1: To create a fresh, functional test, choose file> New Functional Test.
Step 2: Create a new REST project using ReadyAPI by selecting the Endpoint.
Step 3: Choosing a URL as the test's source in ReadyAPI.
Step 5: Entering a URL for the new project with ReadyAPI.
Step 6: Choose whether you want to add the URL you have added to an existing project or create a new one on the wizard's following page.
Step 7: ReadyAPI: Enter a project name.
Step 8: You can modify new requests by adding assertions on the wizard's subsequent page. The proposed assertions will not be used in this tutorial, so deselect them and click Next.
Step 9: ReadyAPI will create a project, and a confirmation dialogue will appear. Click Add Data in the dialogue box, then choose a data source in the next window.
Step 10: Create a new file or download an example file to use as a data source.
Step 11: In the Add New Data dialogue, enter a name for the data source and the whole path of the file.
Now that the data has been imported, ReadyAPI will generate a test with a data source loop utilizing the attached file. The data source can now be set up.
Characteristics of the Data Import
As mentioned above, when you develop a data-driven test, ReadyAPI tries to automatically create property extensions. To view the imported data, double-click the data source in the Navigator.
ReadyAPI will use the data from the first row of the Excel file to generate data source properties if you import the property names from the file. Then, in the same order as the values of the data source, it will build property expansions for each request parameter.
Create the Data Source
When you use a wizard to create a data source, it will automatically import the data source properties listed at the start of the data source file. Before setting up your test, you must ensure that the data source functions as intended and that the properties have been successfully imported.
Use the Data Log to evaluate the data source:
Step 1: Dispatch the Data Log.
Step 2: Press RUN.
Step 3: Indicate the number of results to be returned.
Step 4: You may see the data you received in the log.
Set up the Test Step
You must put the test step and the data source in the proper order for your test step to be able to use the data source. After that, you should set up the test step to utilize the information in the data source.
A test case with a data source, a REST request, and a data source loop is now available. If you want the request to use the data source, make sure it comes before the request.
The wizard, by default, tries to fill the request's blank fields with information from the data source. The $Data Source#Email value should be present if you are working with the sample file. You may do so right now::
Launch the test step editor for Request 1.
Go to the "Request" tab:
Choose the Email property from the data source if you are using a custom file or if the wizard failed to correctly determine the value:
Step 1: Choosing the Value field.
Step 2: Get Data can be chosen with a right-click in the field.
Step 3: Select the Data Source test step and the Email property in the ensuing Get Data dialogue:
Step 4: Select Add.
Start the Test
In Excel files as Data sources in Ready API, you have a test step that uses a data source, a test case with a data source, and a data source loop that runs while the test is being run.
The test case is prepared. To launch the test, click on the RUN toolbar for the test case.
The Transaction Log shows the following test run details:
Add an assertion
Let's include a statement to confirm the server's response.
1. Click Smart Assertion in the Request 1 test step to begin.
2. ReadyAPI displays the Smart Assertion dialogue.
In the Valid Value box, select the name row and press the ellipsis key:
3. Choose the test case, test suite, data source test step, and expected name property from the Get Data dialogue.
Select Add.
4. To create an assertion, click Save.
5. The supplementary assertion can be found in the Assertion panel:
6. Click once more after opening the test case. Examine the assertion statuses in the Transaction Log after the test run is complete.
data-generating
Frequently Asked Questions
What is the prerequisite for studying Data source types in ReadyAPI?
Before dwelling on Data sources, you must be familiar with Data-driven testing.
What does ReadyAPI's data source mean?
You can use the potent instrument of data sources in ReadyAPI to build data-driven tests. By default, data sources only give any test step that requests the data they collect from the source.
What is a grid data source?
You can store data within ReadyAPI using the Grid data source, eliminating the need for external storage. The grid's columns are organized according to the designated property.
Name some objects used in Groovy Script.
Some objects used in Groovy Script are context, result, test runner, and log.
How can I use a Groovy script to read an Excel file?
The script jar needs to be downloaded and added to the classpath. It can be found here in the maven repository. You should import the ActiveXObject class into your Groovy script.
Conclusion
In this blog, we studied the details of Excel files as Data sources in Ready API. And covered importing the Virtual API, Creating a Test Case, Configuring the Data Source, Configuring the Test Step, and Running the Test.
To know about more articles like Excel files as Data sources in Ready API, check out the following: