Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Hey Ninja!!🥷In this journey of functional testing, you have come to the position where you will run these tests. You have worked with creating, managing, debugging, writing scripts, etc., but you will run your tests at this step. In this blog, you will learn how to run your tests and tests on demand and automate these tests. ⭐⭐⭐⭐
Multiple Test Items
In ReadyAPI, we can run multiple test items at project, suites, and case levels. Sometimes it's as easy as pressing a button, and sometimes we must write scripts to perform these actions simultaneously. Let's learn how to run multiple tests at once.
Projects
ReadyAPI does not allow running more than one project at a time. But we have a loophole; we must use test runners from scripts or command lines. Let's go through sequential and parallel ways of running projects.
Running Projects in Sequence
To run multiple in a sequence that is next project in the queue should automatically run after the prior finfishes; we can write scripts and execute them from the command line.
It's better to run your projects in parallel if they are not resource-heavy. Asynchronous behaviour saves time and makes full use of available resources. To run multiple parallel projects, we need to use Groovy Test Step in our project and write scripts that run other projects.
The same script will work on windows if you change '.sh' with '.bat'.
The logic here is that execute() function does not wait for the process to get over. Thus we exploit this behaviour to run multiple projects in parallel.
Test Suites
Running Several test suites is relatively easy. Run the project the suites belong to, and all of them will run simultaneously.
To run suites in sequence, press the button as indicated in the image below.
To run suites in parallel, press the button, as shown in the image below.
Note that these do not affect your test cases in any way. Only test suites are executed in sequential or parallel mode.
Test Cases
It is almost similar to the running suites you learned in the above section. Here also, we can run test cases sequentially or parallel as needed.
To test cases sequentially, press the button, as shown in the image below.
To test cases in parallel, press the button, as shown in the image below.
Running a Test Case
Knowing in-depth what happens when tests run is crucial for developing robust tests, logs, and triggered events. Running a test case mainly involves three steps: starting up, running test steps, and finishing. Let us explore them one by one.
Starting Up
The following steps are taken sequentially to start running a test case:
All the resources related to the test case are available, so context initialisation occurs. These are then passed to the objects, scripts, and properties for proper functioning.
Setting up script.
Setting a time beyond which the test fails.
Applying event handlers that act like TestRunListeners from the beforeRun event.
Running any WS-RM or AMF-related sessions.
Running Test Steps
Now all the important tasks are executed inside the steps. Therefore, running these steps is critical. Execution starts from the first enabled step and then goes sequentially. The following events happen for each test step:
Triggering beforeTestStep event
The test is run, and its result is saved in testRunner.result collection
If other steps are triggered from this step, they are also executed.
The afterTestStep is triggered.
The log is then saved with TestStepResult.
After this step, the result is analysed, and further step is taken as mentioned in the test case.
Finishing Up
After all the steps are executed, the process reaches the end of its lifecycle. The following events are then triggered to wrap up the entire test case execution:
All the resources are deallocated, marking that all steps are internally ‘finished’.
The TearDown script is called, which frees up any held resource or performs final validation.
The TestRunListener.afterRun event is triggered for all applicable listeners.
The test case will be set to FAIL if any one of the following is true:
The test case was stopped due to an error
Any step failed
Any script-based event or handlers failed
We can find the final state of the test from the log files generated.
Tests on Demand
We often do not have access to the server where we want to run tests. In these cases, we opt for remote testing. It can be done using the Tests on Demand feature of ReadyAPI. We can upload our test cases to the remote server, run them, and get detailed performance metrics and logs reports.
Prerequisites
Since we will run our tests on remote machines, our project should not contain any local dependency, and all the endpoints should be reachable from the remote server. The test case should not have any external dependencies such as JDBC connections, excel data sources or similar stuff.
The project is validated before pushing it to the remote server, and the process is halted if there is any error.
The Ip address is shown beside the server location.
Automating Functional Tests
We can automate most functional testing with the test runner utility provided by ReadyAPI. In this section, we will explore the test runner utility in detail.
Test Runner
The test runner is a utility feature that allows running functional tests and exporting results. We have two methods to use test runners running from the command line or GUI. Before automating the functional tests, it is better to optimise and automate security and performance tests.
Location
The runner's location is <ReadyAPI>/bin directory, and the file name is testrunner.bat (for windows) and testrunner.sh (for Linux).
Get Generated Command Line
We can generate command line commands from the ReadyAPI software itself. We have two ways to do it.
Via Get Command Line Option
Select any functional test node from the panel and follow project → LaunchTestRunner.
Configure the above dialogue box according to your needs, and click the Get Command Line option. You will get the generated commands as shown in the image below.
Via Runner Launch
We can also get the commands by launching the runner. The commands are generated at the beginning of the log files, as shown below.
Test Runner GUI
It is the graphical UI way of automating the running of tests. To launch the runner from the ReadyAPI UI, follow the Project → Launch TestRunner option.
The first method is by right-clicking on any test case and selecting the Launch TestRunner option. A sample is shown below for your reference.
Another option is to select any project or test case from the panel, then click on Project → Launch TestRunner.
After this step, a dialogue box will appear, showing all the settings. Command line options are also available in the dialogue box.
Using Command Line
We can get the commands from the GUI dialogue box. Still, we have a sample syntax below if you wish to write your commands from scratch.
General Syntax: testrunner.bat [optional-arguments] <test-project>
From the above syntax, you can observe that we have two types of syntax. There are several optional arguments available that we can use as per the requirement. Let's now learn about the test project, which is a necessary argument.
Test-project: It is the complete file path of the project in which the functional tests are stored. If the path contains spaces, enclose it in double quotes.
Many programs or services end with some output as codes for future courses of action. The test runner also exits with some exit codes. Let's learn about them.
Frequently Asked Questions
What is a Script?
Scripts are commands written in sequential order. They help automate tasks by defining the order of execution of specific methods and functions.
What is GUI?
It extends to Graphical User Interface. These visual components allow interaction based on objects present on the screen, such as buttons, text boxes, etc.
Why automate tests?
If all the testing is done by developers/testers, it wastes human resources. We can optimise these tests and automate them for similar tests. It is more efficient and saves a lot of resources.
Conclusion
In this blog, you learned about running tests in ReadyAPI. All the important topics related to Running Tests in ReadyAPI were covered in detail.
Also, do refer to other API testing-related articles: