i have to run the testStep multiple time with different data loading from external file(using file object looping to run the testSteps for each record) and validate the data from response for each value.
i'm able to do that and its executing and works fine. but when ever assert fails execution is not stoping and it will continue and shows testStep is passed.
i can see the failed in "script log" windows whenever it fails because i'm using log.info with run.status
and i check checkbox for "abort if test if any error occurs" and "failed tes cases if testStep fails" on test case options.
still it continue executing the test cases
Important Note: above scenario happens when assert fails in middle of the records, if it is fails for last record then its stopping the execution.
Code which i used
This Groovy script code: file iterates the testStep as per the no of rows in file
// Get tha path to an input file from a custom property
def inputFilePath = testRunner.testCase.testSuite.getPropertyValue( "inputFile" )
// Get the test case we want to Run
def tc=testRunner.testCase.testSuite.testCases["DetectRules"].testSteps["Rules_DENF_224"]
// Iterate through the input file
File file = new File(inputFilePath.toString()).eachLine{
// Set Test Suite custom properties
testRunner.testCase.testSuite.setPropertyValue( "InValue", it.split(",")[0] )
testRunner.testCase.testSuite.setPropertyValue( "OutValue", it.split(",")[1] )
testRunner.testCase.testSuite.setPropertyValue( "outDesc", it.split(",")[2] )
def runner = tc.run(testRunner,context)
//Get the Json response from execution
def FraudReq = testRunner.testCase.testSuite.testCases["DetectRules"].testSteps["Rules_DENF_224"].testRequest.response.responseContent
// Log info to a output
log.info "Execution of test case with Input value: ${it.split(",")[0]} and expected returned value: ${it.split(",")[1]} and Expected Description is: ${it.split(",")[2]} ${runner.status}"
// Sleep for a second since were using public service
sleep 500
}
this is testStep --> Script Assertion: section
import groovy.json.JsonSlurper
def response= messageExchange.response.responseContent
def jsonsl= new JsonSlurper().parseText(response)
def expected=context.getTestCase().getPropertyValue(“rule number”)
assert expected==jsonsl.results[4].id
if above assert fails then testStep should stop ,but testStep failing but execution is not stopped.
any help appreciated
Related
I have one groovy script named Check in testcase 1, which contains the follow code:
log.info "Running from different test case script"
I am trying to get this message in a script written in testcase 2:
package com.eviware.soapui.impl.wsdl.testcase;
Test_script= testRunner.testCase.testSuite.project.testSuites["TestSuite"].testCases["TestCase"].testSteps["Check"]
def myCont= new WsdlTestRunContext(Test_script)
log.info Test_script.run(testRunner,myCont)
It gives me output as:
Wed May 18 17:39:57 IST 2016:INFO:com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStepResult#131bc813
What to do here to see proper message in output
TestStep.run method doesn't return directly a desired object from other testStep or so, It returns a generic WsdlTestStepResult object to see the status, possible errors etc.. of the testStep execution, due this log.info Test_script.run(testRunner,myCont) it's printing the result of toString() method on WsdlTestStepResult object.
If you want to pass objects from one groovy script testStep to another, you've to use the context variable which is available in each groovy script testStep.
For your case since you're running the first groovy script using TestStep.run(TestCaseRunner testRunner,TestCaseRunContext testRunContext) from the second one script, you can get back all objects added in the context of your first script in the second one with testRunContext object passed to run method. Let me show it with an example:
In the first groovy script add your text as a property of the context:
// instead of log put the text in a context property
context.setProperty('somePropToGetBack','Running from different test case script')
// you can put all the properties you want...
context.setProperty('anotherOne','more props')
Then in your second script you only have to get back these properties:
package com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
def Test_script= testRunner.testCase.testSuite.project.testSuites["TestSuite"].testCases["TestCase"].testSteps["Check"]
def myCont= new WsdlTestRunContext(Test_script)
def result = Test_script.run(testRunner,myCont)
// after execution in myCont variable you've all properties you set
// in context variable of first script
log.info myCont.getProperty('somePropToGetBack') // prints Wed May 18 14:56:36 CEST 2016:INFO:Running from different test case script
log.info myCont.getProperty('anotherOne') // prints Wed May 18 14:56:36 CEST 2016:INFO:more props
Hope it helps,
I have 5 test steps in a test case and i want to write a script assertion for a test step
Like
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def httpResponseHeaders = context.testCase.testSteps["Step1"].testRequest.response.responseHeaders
def httpStatus = httpResponseHeaders["#status#"]
def httpStatusCode = (httpStatus =~ "[1-5]\\d\\d")[0]
if (httpscode == "500")
I want to re-run the test step named as step 1
I know that testRunner class is not present in Script assertion is there a way to do it with messageExchange variable class
I saw an answer on stack overflow
`messageExchange.modelItem.testStep.testCase.getTestStepByName("Step1").run(context.getTestRunner(),context)`
I tried the code but as soon as i click run SOAP UI hangs and I have to force close the SOAP UI application
To run a test step from script assertion you may use this
import com.eviware.soapui.support.types.StringToObjectMap
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner
def Runner = new WsdlTestCaseRunner(messageExchange.modelItem.testStep.testCase, new StringToObjectMap())
yourTestStep= messageExchange.modelItem.testStep.testCase.testSuite.project.testSuites["ScriptLibrary"].testCases["Library"].testSteps["Lib"]
yourTestStep.run(Runner,context)
Your code is fine, except your logic is flawed, because you encounter the error 500 for the first time and then you call the same step again and it fails again with 500 and so on. You would need to get different status, before your Java runs out of memory.
So if you want to do something like that, you have to implement some kind of counter (using TestCase, TestSuite, Project or Global property) to perform this loop only several times and then fail.
Anyway this worked for me:
def utilitiesSuite = messageExchange.modelItem.testStep.testCase
.testSuite.project.getPropertyValue('utilitiesTestSuiteName');
messageExchange.modelItem.testStep.testCase.testSuite.project
.testSuites[utilitiesSuite].testCases["Test Case utility name"]
.run(null, true);
In this case we have all "utilities" = test cases with some often needed functionality in a dedicated test suite and I wanted its name to be possible to set up on Project level, of coures the Test Suite name can be put there directly as for example "Utilities'.
Also i have tried with this:
context.getTestRunner()
As the first parameter in the methor run instead of the null, but it worked only when testing the one requirement, not when running whole test case or test suite.
I let here another example that worked for me.
It's an assertion script, which runs a testStep basing on a response node value.
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context );
def holder = groovyUtils.getXmlHolder( "yourTestStep#response" );
def myValue = holder.getNodeValue( "//theNameSpace:yourNode" );
if(myValue == 'whateverYouWant'){
//com.eviware.soapui.support.UISupport.showInfoMessage(myValue);
def Runner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(
messageExchange.modelItem.testStep.testCase, new com.eviware.soapui.support.types.StringToObjectMap());
def mySteps= messageExchange.modelItem.testStep.testCase.testSuite.project.testSuites["yourTestSuite"].testCases["yourTestCase"].testSteps["yourTestStep"];
mySteps.run(Runner,context);
}
In SoapUI I’m running a test case from a groovy script with this code:
def contextMap = new StringToObjectMap(context)
def myTestCase_1 = myTestSuite.getTestCaseByName("TestcaseName")
myTestCase_1.run(contextMap, false)
In the called test case I set some context properties in a groovy script in this way: context.setProperty(“ProperyName”,”Value”)
After the called test case has finished the created property values are missing in the context of the groovy script that has called this test case.
How can I pass back property values to a test case that called another test case?
Instead of using context if you want to share properties through different testCases in the same testSuite try to set the properties on the testSuite level which will be shared for all testCases in this testSuite. For example if you have a testSuite with two testCases: testCase 1 and testCase 2, on a groovy script from testCase 1 do:
testRunner.testCase.testSuite.setPropertyValue( "sharedVar", "someValue" )
Then to use this property from another groovy script in testCase 2 use:
def shared = testRunner.testCase.testSuite.getPropertyValue("sharedVar")
log.info shared
You can also use this testSuite property saved in the testCase 1 in the testCase 2 for example in testStep SOAP Request using: ${#TestSuite#sharedVar}
EDIT BASED ON OP COMMENT:
Since seems that the OP problem is how to get the properties from a testCase which is called from another testCase using groovy script; here is a possible work around, which consists in through the run result get the invoked testCase and then get his properties:
The first testCase which invokes the other testCase using groovy looks like:
import com.eviware.soapui.support.types.StringToObjectMap
def contextMap = new StringToObjectMap(context)
def testCase2 = testRunner.testCase.testSuite.getTestCaseByName("TestCase 2")
// get the result since is running sync
def result = testCase2.run(contextMap, false)
// from the result access the testCase and then the properties setted there
log.info result.getTestCase().getPropertyValue("varSettedOnTestCase2")
In the second testCase simply perform your logic and set the properties which will be get back from the first testCase:
testRunner.testCase.setPropertyValue("varSettedOnTestCase2","test")
Hope this helps,
I have a groovy script as the first test step inside a test case, part of it looks like:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder("SampleTestt#Request").getXml()
log.info holder
When SampleTest test step has all element values hardcoded, the request xml can be printed fine.
However if some of the request values is read from a test case property, like the following for example
${#TestCase#Id}
The the above groovy script through error as:
org.apache.xmlbeans.XMLException: error: Unexpected character encountered : '$'
Can you please help?
Thanks.
You can use context.expand() to evaluate the properties inside your request and then parse the result to xmlHolder, your code could looks like:
// get your request replacing the properties inside by their values
def xmlRequest = context.expand('${SampleTestt#Request}')
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(xmlRequest)
log.info holder.getXml()
Note that I use SampleTestt as your test step request name, but I think that the last t could be a typo... check if it's the correct request name before use the code.
Hope this helps,
I am having 2 test cases in my suite.
First test case contains 1 test step with xml request.
Second test case contains 1 test step with groovy script. I want to run the 1st test case from this groovy script a number of times. Every time I want to change the input XML. I am unable to update the input XML in TestCase 1.
I have the following the code for the groovy script:
import com.eviware.soapui.support.XmlHolder
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def tsuite = testRunner.testCase.testSuite
def acctInq_tstepName = tsuite.getTestCaseAt(1).getTestStepAt(0).getName()
def acctInq_requestHolder = tsuite.getTestCaseAt(1).testSteps[acctInq_tstepName].testRequest.getRequestContent()
def acctInq_req = groovyUtils.getXmlHolder("$acctInq_requestHolder")
acctInq_req["//soapenv:Envelope[1]/soapenv:Body[1]/v2:AcctInqRq[1]/ifx:DepAcctId[1]/ifx:AcctId[1]"] = "0009917812344"
acctInq_req.updateProperty()
I also tried using
tstep.setPropertyValue("request",cStr(acctInq_req))
In either case the XML is not getting updated. Please help.
Try set node value like below and check if it fixed the issue:
acctInq_req.setNodeValue("//*:ifx:AcctId[1]", "0009917812344")