Call test suite property within the request in SoapUi - groovy

all
I am using free version of SoapUI.
What I have is a test suite with many test cases. In each test case there is a request where I need to specify a date. So I want to create a general script for all cases and just call the result of it in each request I need.
What I do:
1. I have test suite SaveOperation where in SetupScript window at the bottom I write script:
def sdf = new java.text.SimpleDateFormat("yyyy-MM-dd")
def windowClosed = sdf.format(new Date()-20)
log.info(windowClosed)
2. In this test suite I have many test cases as I wrote. So when for example in test case named SaveValid I need to specify Date parameter I write the following right in the xml request (in date parameter):
${#SaveOperation#windowClosed}
But it doesn't work. Could anyone suggest what is wrong with this way?
thank you in advance

You have the correct approach. log.info() will only write the information to a log.
change
log.info(windowClosed)
to
testSuite.setPropertyValue("windowClosed", windowClosed.toString())
and then refer to it as:
${#TestSuite#windowClosed}

Related

How to run cucumber scenario's based on Test Case ID that is appended with the Scenario name?

I wanted to run Cucumber Feature file based on the Test case ID that scanerio name contains.
I know we can use #CucumberOptions 'features' tag and specify the line number to execute e.g "src/test/resources/Folder/myfile.feature:7:12"
This will run scenarios at line 7 and 12. But i wanted to run based on the TC ID.
Below is the feature file code
#Run
Feature: Login Functionality
Scenario: First Test Case(TC.No:1)
Given I perform action 1
Scenario: Second Test Case(TC.No:2)
Given I perform action 2
Scenario: Third Test Case(TC.No:3)
Given I perform action 3
Scenario: Fourth Test Case(TC.No:4)
Given I perform action 4
Scenario: Fifth Test Case(TC.No:5)
Given I perform action 5
All the scenario's are in a single feature.
For the feature file code above i wanted some way through which i can execute based on TC Id. E.g I only want to execute TC1,TC2 and TC5( TC id's picked up from scenario names).
There is a property file that contains the TC Id's to be executed. My code should read the file and then execute only those TC id's.
This can help me in reducing the number of automation TC's to be run.
Is it possible?
You can use the name property of #CucumberOptions or use the '-n' option if you are using the cli option. It also supports regular expressions.
To run TC.No:1 and TC.No:4 use something like this
#CucumberOptions(name = { "TC.No:1|TC.No:4" })
or
#CucumberOptions(name = { "TC.No:1","TC.No:4" })
You can get more details at this link.
As you are reading the ids from a file, the second option is the best. Use the cucumber.api.cli.Main class main() method to execute the features. You can create the options dynamically. Refer to this post.
CLI reference docs.
Not familiar with cucumber-jvm.
But, here is the general logic which should work (based on my ruby Cucumber knowledge)
In the hook, you can write the logic to under before method to get the scenario name scenario.name and then extract the TC.No. Compare the TC.No and skip if it's not part of your list.
Here is the link which will give information how to skip the scenario (use this class in the before method)
https://junit.org/junit4/javadoc/4.12/org/junit/AssumptionViolatedException.html
However, the best practice is to use the tags, it would have been easy if you had #TCId-xx tag. Still you can write a simple program that will scan all the feature files and update the scenarios with the tag based on the TC.No in the scenario name.

SoapUI: Transfer groovy script results using Property Transfer

I am an absolute noob in SoapUI. I am looking out for answer on this but somehow could not really find it.
I am in a situation where I would like to transfer two of the groovy scripts's results to another Groovyscript. Unfortunately, while using Property Transfer, the destined groovy script gets fully overriden by the return value by the source script. How shall I approach this?
Please find below the example for the same:
As you may see, I would like to pass the value of the transferred result of generateCreated and generateNonce to the generatePassword script in testRunner.testCase.getPropertyValue("Nonce") and testRunner.testCase.getPropertyValue("Created")
But this just doesnt seem to work for me.
You don't need a Property Transfer teststep for that.
You just let your first two scripts run - as you already are doing.
Then in your third Groovy Script, you just pull the results into variables.
This can be done using something like
def result = context.expand( '${Groovy Script#result}' )
In your case above, I suspect you would adjust that to something like
def created = context.expand( '${generateCreated#result}' )
def nonce = context.expand( '${generateNonce#result}' )
Insert those lines in your script whereever you need those variables, and then you have the variables "created" and "nonce" holding the results.

Getting values of properties in SoapUI's groovy

I'm pretty new to testing and SoapUI and I've just faced a problem:
I have 2 soap requests from which I transfer data (using PropertyTransfer) to Properties - I can do that and it works fine for me.
But now I would like to take those values in my groovy script (which is next step of my testcase). How to do that? So far, I have found following:
testRunner.testCase.getPropertyValue("SomeProp")
But it doesn't work for me. I guess it's not that Properties. Any tips?
In the Groovy script panel you can right-click and select Get Data, to help you out. You will end up with something like this:
context.expand( '${Properties step#SomeProp}' )
Same thing can also be written as:
testRunner.testCase.testSteps['Properties step'].getPropertyValue("SomeProp")
Few cents:
if we are loading properties file through external file via -Dsoapui.properties=\tmp.properties
Contents of tmp.properties
serialNumber=908664374
ideal way to load the property 'serialNumber' in groovy file would be,
def serialnumber = context.expand('${#serialNumber}')
But if you have a property at any level [test suites, test cases or project] inside your SOAPUI project, say you have it at project level, then it would be
def serialnumber1 = context.expand('${#Project#serialNumber}')
The first expression works with:
context.expand( '${Properties_step#SomeProp}' )
To read property from Project level properties
testRunner.testCase.testSuite.project.getPropertyValue( "PropertyName")
To read property from Test Case level properties
testRunner.testCase.getPropertyValue("PropertyName")
Two answers are possible for this type of scenarios ,
Setting and Getting the Property values,
Message Exchange
Test Runner
Message Exchange :
def testCase=messageExchange.modelItem.testCase.getPropertyValue("Propertyname")
Test Runner:
testRunner.testCase.getPropertyValue("PropertyName")
Note : context also helps to retrieve the same .

getting name of previous test step in SoapUI groovy script

I'm new to groovy scripting in SoapUI and a bit confused regarding the amount of information available, so I may just have overlooked the answer to this.
There is a method context.getCurrentStep() available in scripts which loaded the GroovyUtils. But in a script step this, of course, returns the name of the script step itself.
Now I want to access the name (more precisely the response) of the previous step without using it's name explicitly. Is there an easy method to acchieve this?
You could do something like:
def currentStepInd = context.currentStepIndex
def previousStep = testRunner.testCase.getTestStepAt(currentStepInd - 1)
log.info previousStep.name
More information is available in the API JavaDocs.
You would want to do the following in your script:
def response = context.expand( '${previous_step_name#Response#}' )

getXmlHolder and context.expand - What does the arguments description mean

I am trying to insert values into the Request and Capture the response from the soapui pro Testsuite/testcase/testStep, using groovy script, without creating any property or assertions using soapui pro wizard. Everything i am trying to do using groovy script file in Soapui pro. But after 11 days of my self learning process I am forced to ask the in the forum:
I went thru almost 100 sites talking about how to capture request/response value.
But none explains the following:
getXmlHolder ("DeliverStatus#Request")
what does "deliveryStatus" & "Request" means and what does it contains. Which part of xml file is it. What does it signify
context.expand
For all my attempts i have got Null exception.
But i have been able to successfull script using groovy in the "Script tab in the Response section". But unable to do in using testsuite Groovy Script.
Please help.. Thanking all in advance
Regards
Am
DeliverStatus is basically meaningless - it is the name of your test step.
Request means that you look at the XML request that will be sent by SoapUI.
You can replace Request with Response and get the result of the API call.
context.expend allows you to get the value of the request or the response as well as specific XPaths within them. I'm not familiar with the getXmlHolder method - but it looks like it gets an XML string as input (can be a fragment) and turns it into an object you can work with.
My recommendation - if you are not using it already, is to right click on the Groovy editing area and choose Get Data --> Test Suite --> Test Case --> Test Step --> Response --> and navigate to the path in the response to which you want to access.
This will set the value of that XML fragment into a string variable of your choosing.
Afterwards you can use the getXmlHolder to convert that string into an object.
I also recommend using the XmlSlurper for parsing an XML string into an object.

Resources