I have Test case starts with Groovy Test step and followed with Property and 4 SOAP request test steps. In groovy Test step I performing execution of those SOAP requests, accessing data from property Test step.
Here I just want to execute those SOAP request from groovy test step alone. When I ran it as Test Case in SOAPUI after Executing groovy Test step, those 4 SOAP requests also get executed and my Test case got failed.
I use testRunner.cancel("Skip the Teststep") it could skip those test step, But it results as failure in Execution report and I cant find any method to skip test step using groovy.
Please help me somebody on this.
Regards,
Madhan
Try this in the Groovy Script step.
testRunner.testCase.testSteps.each{k, v ->
if(k in ['step1', 'step2'])
v.cancel()
}
where step1 and step2 are the steps you want to skip.
If you want to cancel all the test steps then use
testRunner.testCase.testSteps.each{k, v ->
testRunner.cancel(k)
if want to disable test steps
def testSuite = context.testCase.testSuite;
def totalTestCases = testSuite.getTestCases().size();
for(n in (0..totalTestCases-1))
{
testSuite.getTestCaseAt(n).setDisabled(true)
}
Related
When a script is created in a TestCase in SoapUI, you get access to the following variables:
log, context, and testRunner
From testRunner I grab the TestCase Step of interest with:
def testStep = testRunner.getTestCase().getTestStepByName('TestCase Step 1')
After the test case is run with testRunner.runTestStep(testStep), you get a response. I would like to modify that response, but when I try:
testStep.setPropertyValue('Response', "Sample response content: Lorem Ipsum")
I get: Trying to set read-only property [Response]
testStep is of type RestTestRequestStep. I know that one can use MockRequests and set MockResponses, but for this one, I need data from an actual server with different queries, combine the data, and then give it as a response.
Is there a way to modify the response returned to a TestStep?
Based on the info, I can suggest that you can take the output in a property( Global Property, Project level property) and pass/get the property in the following steps to combine it.
I am working with Cucumber & Groovy in Katalon Studio.
I have ten feature file lines in Cucumber and corresponding step definitions.
In my cucumber feature file first step has the indicator where if the first line is passed with the parameter with "NO RUN", the test case should not run and it should be moved to the next test case.
So, I thought, I will use the Global variable indicator where I can handle in the test and assign the values. I see that and could create the Global Variable (RUN INDICATOR) under the Execution profile. But, not sure how I need to use that variable in the test script or refer.
Can someone please provide the inputs on this to proceed further ?
Step Definition
#Given("running indicator flag (.*)")
def run_indicator_flag(String ind1) {
println "Passing Indicator " + ind1
assert ((ind1!='') || (ind1!='N'))
WebUI.openBrowser('', FailureHandling.STOP_ON_FAILURE)
}
You can use test listeners to do that.
Create a Global Variable with the empty string value (You need to do this before actually running the test case/suite):
GlobalVariable.RUN_INDICATOR = ''
You will update its value either manually or preceding test will update it to whatever value you wish.
Create a test listener with the following code
#BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
if(GlobalVariable.RUN_INDICATOR=='NO RUN'){
testCaseContext.skipThisTestCase()
println "Test Case skipped"
}
}
If the GlobalVariable.RUN_INDICATOR is set to 'NO RUN', this test case will be skipped and the test suite will continue with the next one.
I have some SoapUI test cases, where I need to enable specific test steps.
I decided to wrote a simple Groovy script which enables required test steps.
At first I disable all test steps in the test case:
//Get the names of all test steps
def oNameList = testRunner.testCase.getTestStepList().name
for(iNameCounter in (0..oNameList.size-1))
{
testRunner.testCase.getTestStepByName(oNameList[iNameCounter]).setDisabled(true)
}
Then I have list with test steps to enable:
def list = ['Login', 'Get Messages', 'Logout']
for (i = 0; i <list.size; i++) {
testRunner.testCase.getTestStepByName(list[i]).setDisabled(false)
}
It works If 'list' elements exist as test steps in that test case. But not If one of them is missing. Is it possible to make it skip missing test steps? I need to make this groovy work on every test case (in 'list' there will be all preferred test steps from every test case in test suite).
For example:
I have Test case with these test steps: 'Login', 'See bill history', 'Logout'.
I will run this groovy script which disable all test steps.
Then it starts to enable test steps specified in the 'list'.
But it fails because in that test case there doesn't exist test step 'Get messages'.
I want to make it to skip enabling test steps from 'list' which doesn't exist in the actual test case.
Output on this test case should be - enabled: 'Login', 'Logout'; disabled: 'See bill history'
My use case is that I want to do a bulk update of request bodies in multiple SoapUI projects.
Example of request body.
{
"name": "${#TestSuite#NameProperty}"
"id": "${#TestSuite#IdProperty}"
}
I want to expand the property ${#TestSuite#NameProperty} through Groovy, and get the value stored at TestSuite level then modify it as necessary.
Suppose I have 50 test steps in my test case and I want to expand the request for each one from Groovy script. To expand a specific test steps, I would pass the test Steps's name. For example:
expandedProperty = context.expand('${testStep1#Request}')
But, how can I achieve the same, if I wanted to iterate over all 50 test steps? I tried to used a nested parameter inside the context.expand expression, but it did not work. For Example:
currentTestStepName = "TestStep1"
expandedProperty = context.expand('${${currentTestStepName}#Request}')
This only returned me the expanded request from the test step right above it (where I am running the groovy script from) rather than the "TestStep1" step. ( Which is madness!)
Also, context.expand only seems to work while executing via Groovy script from the SoapUI workspace project. Is there and other way, or method similar to context.expand which can expand the properties like "${#TestSuite#NameProperty}" during headless execution? Eg: A groovy compiled jar file imported in SoapUI.
Thanks for any help in advance!
You can use context.expand('${${currentTestStepName}#Request}') way to get it.
There are other approaches as well, which does not use context.expand.
In order to get single test step request of any given test step:
Here user passes step name to the variable stepName.
log.info context.testCase.testSteps[stepName].getPropertyValue('Request')
If you want to get all the requests of the test case, here is the simple way using the below script.
/**
* This script loops thru the tests steps of SOAP Request steps,
* Adds the step name, and request to a map.
* So, that one can query the map to get the request using step name any time later.
*/
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
def requestsMap = [:]
context.testCase.testStepList.each { step ->
log.info "Looking into soap request step: ${step.name}"
if (step instanceof WsdlTestRequestStep) {
log.info "Found a request step of required type "
requestsMap[step.name] = context.expand(step.getPropertyValue('Request'))
}
}
log.info requestsMap['TestStep1']
Update :
If the step that you are interested is REST step, use below condition instead of WsdlTestRequestStep in the above.
if (step instanceof com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep) { //do the stuff }
How to capture a test result details for test steps other than test request(Say Groovy script step) using groovy for soap ui?
For test request we can capture the result based on assertion result but for other test steps how can i get the result?
You must create assertions in the test than you want export the date. You must parse your json, xml, ... and later save the field than you want in a property of this test suite, also you can save in the properties of your project. Example of assertions:
**import groovy.json.JsonSlurper
def ResponseMessage = messageExchange.response.responseContent
def jsonSlurper = new JsonSlurper().parseText(ResponseMessage)
testRunner.testCase.setPropertyValue("correlationID", jsonSlurper.uuid)**
Also you can use:
**testRunner.testCase.setPropertyValue( "correlationID", jsonSlurper.uuid)
testRunner.testCase.testSuite.setPropertyValue("correlationID", jsonSlurper.uuid)**
**testRunner.testCase.testSuite.project.setPropertyValue("correlationID", jsonSlurper.uuid)**
Then you have correlationID in the properties, the properties in this case name properties, of your test case, suite, project, ...
Finally only have than write in the header
Name Value
**correlationID '${Properties#correlationID}'**