Setup and TearDown Scripts in Ready API
The various test items, including projects, test suites, and test cases, all include setup and teardown scripts. The test engine executes the Setup script prior to running each test item. The test engine executes its TearDown script after the complete test item run.
There are available the following scripting objects:
1️⃣ virtRunner: It is the object for managing virtual services.
2️⃣ log: The object for interaction with the log.
3️⃣ context: The object contains various test-related data (e.g., properties).
4️⃣ testRunner: It is the test runner's user interface.
Rerunning Failed Test Cases using Groovy Scripts
In this part of “Running Test Cases in Ready API,” we will use groovy scripts to check failed test cases and rerun them.
The below given example is to check failed test cases and rerun them using groovy scripts:
import com.eviware.soapui.model.testsuite.TestRunner.Status
// RerunCount test suite property states that failed test cases should be run X times, where X is the number
.
def reRunCount = Integer.parseInt(testSuite.getPropertyValue("RerunCount"))
def failTestSuite = false
for ( testCaseResult in runner.results )
{
if ( testCaseResult.getStatus().toString() == 'FAIL' )
{
def tRun
for (i = 0; i < reRunCount; i++)
{
tRun = testCaseResult.testCase.run(null, false)
//The second argument must contain the word "true."
log.info("Run..." + testCaseResult.getTestCase().name)
if(tRun.getStatus().toString() == "PASS")
{
runner.status = Status.FINISHED
///Set the status of the test suite
break;
}
}
if(tRun.getStatus().toString() == "FAILED")
{
failTestSuite = true
//If a test case is still failed after reruns, set the flag to fail the test suite and exit the loop
}
}
}
if(failTestSuite)
{
runner.status = Status.FAILED
//Change the test suite status to failed if the flag is set to fail the test suite
}
Running Test Step from Another Project
In this part of “Running Test Cases in Ready API,” we will use groovy scripts to run the test steps from another project.
Ways to run the script:
💡 Groovy Script Test Step.
💡 In functional tests, as a setup or teardown script at the project, test suite, or test case level.
The below given an example is to run a test step from another project using groovy scripts:
// Replace names of a project, test suite, case, and step with those you need.
// Connect to the test step in another project.
def prj = testRunner.testCase.testSuite.project.workspace.getProjectByName("ProjectName")
tCase = prj.testSuites['Test Suite Name'].testCases['Test Case Name']
tStep = tCase.getTestStepByName("Test Step Name")
// Call the test runner and see if it is capable of performing the required step.
def runner = tStep.run(testRunner, context)
log.info ("runner status ....... : " + runner.hasResponse())
Running Test Case from Another Project
In this part of “Running Test Cases in Ready API,” we will use groovy scripts to run the test case from another project.
Ways to run the script:
⚡ Groovy Script Test Step.
⚡ In functional tests, as a setup or teardown script at the project, test suite, or test case level.
The below given example is to run a test case from another project using groovy scripts:
// Connecting to the test case in another project.
def project = testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName("ProjectName") def testSuite = project.getTestSuiteByName("Test Suite Name")
def testCase = testSuite.getTestCaseByName("Test Case Name")
// Run these test case.
runner = testCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false)
Check out this problem - Smallest Distinct Window.
Frequently Asked Questions
Is ready API and Postman the same thing?
End-to-end testing is extremely difficult to manage and follow over time because Postman is designed around each individual endpoint of an API. Tests can include multiple endpoints, resources, or data pieces because each test case is built into the structure of the Ready API.
What is the ready API update process?
Using our website, we can manually or automatically check for ReadyAPI updates. Follow these steps to configure Version Update options: The ReadyAPI toolbar can be chosen. On the left side of the ReadyAPI Preferences window, click Version Update.
What makes a ready API different from a REST API?
ReadyAPI functions much more natively. But unlike REST-assured, it requires licensing fees. Any REST API will do if we are only testing them.
Conclusion
Congratulations on finishing the blog! We have studied running test cases in Ready API. We further looked at the rerunning failed test case and ran the test step using another project using groovy scripts. We sincerely hope that this blog has improved your understanding of Running test cases in Ready API, and if you want to learn more, then you can check articles on:-
🤖 Ready API
🦾 REST Request in Ready API
🔑 Authentication of Ready API
Please refer to our guided pathways on Code studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. Enroll in our courses, and use the accessible sample exams and questions as a guide. For placement preparations, look at the interview experiences and interview package.
Please do upvote our blogs if you find them helpful and informative!
Happy learning!