Forum Discussion
Have you tried this snippet? This is what I have used in the past to get the current test step name.
def teststepName = context.testCase.getTestStepAt(context.getCurrentStepIndex()).getLabel() return teststepName;
Hello msiadak,
Thank you so much for your fast reply.
My DataGen testStep name is "MyDataGen".
My SOAP operation testStep name is "checkAccessControl".
It contains: <context>${MyDataGen#context}</context>
The 'context' property of the MyDataGen DataGen TestStep is of type Script/READ and contains this:
def teststepName = context.testCase.getTestStepAt(context.getCurrentStepIndex()).getLabel()
return teststepName;
Upon execution of the checkAccessControl testStep, the variable evaluates to MyDataGen as seen in the Raw tab:
<context>MyDataGen</context>
I was in a hurry to come to the office this morning to test your suggestion :-(
Unfortunatelly, this does not address my issue.
- groovyguy6 years agoCommunity Hero
zorglups: Can you show me a screenshot of what your tests look like? What SHOULD be shown in the <context></context> element?
- Olga_T6 years agoSmartBear Alumni (Retired)
- zorglups6 years agoOccasional Contributor
Well... Yes and no.
But first : A big thank you to @msiadak for his time spent on trying to understand my case and propose something.
I will try to explain my challenge.
- My TestSuite has a property "dossier" that may be empty or set by the user of my TestSuite.
- The TestCase has:
- One TestStep Soap Operation : operation1
- One TestStep Soap Operation : operation2
- ...
Each soap operation has an xml node <dossier></dossier>
I wanted my user to be able to define somehow a specific dossier for each operation, without modifying the operation itself.
This dossier node should be set to :
- if a specific dossier is somehow declared for this operation
- then set the dossier to this specific dossier in the operation xml
- else
- if the user set a global dossier in the TestSuite "dossier" property
- then set the dossier to this global dossier in the operation xml
- else
- if a specific dossier is specified somehow for that soap operation (by soap.operation, I mean something like testStep.operation.name ???)
- then set the dossier to this operation specific dossier in the operation xml
- else
- if a default dossier exists for that soap operation
- then set the dossier to this default operation dossier in the operation xml
- else set the dossier to this default dossier in the operation xml
Still with me ;-)
Well. The solution proposed by groovyguy did not help me because the Groovy script is executed from the script part of a DataGen Test Step. I always got as "TestStep name" the name of the DataGen test step although the variable substitution was made in my test step "operation1".
I then tried another route, mainly because this project will be used as a template and I can't afford having to correct my future Groovy bugs in plenty DataGen Test Step duplicates.
My current route is to implement this in an external Groovy Library.
Here below is a dump of what I tried so far, hoping this may save some hours to others:
- Open ReadyAPI preferences
- Go to the ReadyAPI section
- Set the Script library path.
eg: C:\Program Files\SmartBear\ReadyAPI-2.7.0\bin\scripts
Note: Be careful that this path will not change when upgrading to ReadyAPI-2.8 (which made me loose some time after the upgrade from 2.6). Best is therefore to store this somewhere else.
- At the really bottom of the main ReadyAPI window, click the "Show Logs" (This took me some time scratching my head trying to understand how to debug my "compilation errors").
- ReadyAPI Log tab will show you whenever your Groovy script is reloaded and any error if any upon execution of your classes.
- The Script Log is displaying output of log.info calls, which may be useful for debugging purposes ;-)
- In the directory specified in the settings, create a directory with your package name.
Example: C:\Program Files\SmartBear\ReadyAPI-2.7.0\bin\scripts\mypackage - In that package directory, create a text file and give it the name of your Class.
Example: C:\Program Files\SmartBear\ReadyAPI-2.7.0\bin\scripts\mypackage\MyClass.groovy
Note: At this moment, the ReadyAPI Log tab will show that the file was detected and loaded. This will happen every time you save changes into the file so changes are taken into account within seconds. - In thi MyClass.groovy file, add some code that will return "hello world!" string.
Note: I'm totally newbie in Java/Groovy so everything here is probably bad. Feedback is welcome.
package mypackage
class MyClass
{
def static hello()
{
return "hello world!"
}
} - In my Soap Test Step request, I can now write
<dossier>${=mypackage.MyClass.hello()}</dossier>
This will be dynamically be changed upon execution to
<dossier>hello world!</dossier>
Now, my next steps will be to implement the logic to access the TestSuite property "dossier".
I plan to have a TestStep of type "Properties" containing:
- dossier for operation1
- dossier for operation2
- ...
This Properties TestStep could be autogenerated by the TestCase setup script amongst other things.
To be able to read the TestCase property related to the current TestStep name (or better based on the real soap operation name), I still had to determine programmatically the Current TestStep name...
I was therefore back to the beginning ;-)
I found that I can access to the current TestStep context by passing the context object when calling my class method. Same goes to be able to log messages, one need to pass the log object.
Here is an example:package mypackage
import com.eviware.soapui.SoapUI
class MyClass
{
def static getCurrentStepName(log, context)
{
String currentStepName = context.getCurrentStep().getLabel()
log.info(currentStepName)
return(currentStepName)
}
}To fill my dossier with the current TestStep name, I can call:
<dossier>${=mypackage.MyClass.getCurrentStepName(log,context)}</dossier>
Well. This is far from finished but I wanted to give some feedback to groovyguy
I will be 2 weeks off starting in a few minutes and it was better to have a dump of what I found before going on holidays anyhow ;-)
Here are a few links that helped me a lot :
https://support.smartbear.com/readyapi/docs/testing/scripts/library.html
https://support.smartbear.com/readyapi/docs/configure/logs.html
http://www.ou-ryperd.net/soapui.html
https://www.soapui.org/extension-plugins/old-style-extensions/developing-old-style-extensions.html
Related Content
- 4 years ago
Recent Discussions
- 6 days ago