cancel
Showing results for 
Search instead for 
Did you mean: 

Get current TestStep.operation from a DataGen property of type script.

Highlighted
Occasional Contributor

Get current TestStep.operation from a DataGen property of type script.

In a Test Step, my SOAP request contains <context>${DataGen#context}</context>

 

DataGen is ... a DataGen TestStep that defines a property 'context' of type Script (READ).

 

In the script, I tried:

def tstep = testRunner.runContext.currentStep.name;

return tstep


def currentTestStep = context.getCurrentStep().getLabel()

return currentTestStep 

 

But then ${DataGen#context} evaluates to 'DataGen' while I would like it to evaluate to the current TestStep name.

 

Well... Ultimately, I would like to have the current TestStep operation.name and based on this apply some logic to define the context. So the DataGen script is needed.
I just fail to get properties of the TestStep properties from which the DataGen properties is "evaluated".

 

Any help is welcome.

7 REPLIES 7
Highlighted
Community Hero

Re: Get current TestStep.operation from a DataGen property of type script.

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;

 

 

 




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
Highlighted
Occasional Contributor

Re: Get current TestStep.operation from a DataGen property of type script.

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.

Highlighted
Community Hero

Re: Get current TestStep.operation from a DataGen property of type script.

@zorglups: Can you show me a screenshot of what your tests look like? What SHOULD be shown in the <context></context> element?




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
Highlighted
Moderator

Re: Get current TestStep.operation from a DataGen property of type script.

Hi all,

 

@msiadak thank you for your replies!

 

@zorglups have you managed to solve this? 

 


Olga Terentieva
SmartBear Assistant Community Manager

Highlighted
Occasional Contributor

Re: Get current TestStep.operation from a DataGen property of type script.

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 @msiadak 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:

  1. Open ReadyAPI preferences
    1. Go to the ReadyAPI section
    2. 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.
  2. 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").
    1. ReadyAPI Log tab will show you whenever your Groovy script is reloaded and any error if any upon execution of your classes.
    2. The Script Log is displaying output of log.info calls, which may be useful for debugging purposes 😉
  3. 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
  4. 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.
  5. 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!"
       }
    }

  6. 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 @msiadak

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

https://community.smartbear.com/t5/SoapUI-Pro/How-to-run-SoapUI-API-commands-in-an-external-script/t...

https://stackoverflow.com/questions/43254590/how-to-place-the-groovy-in-centralized-groovy-library-a...

http://www.ou-ryperd.net/soapui.html

https://www.soapui.org/extension-plugins/old-style-extensions/developing-old-style-extensions.html

Highlighted
Moderator

Re: Get current TestStep.operation from a DataGen property of type script.

Thank you for the update and feedback, @zorglups ! Have a good time on your vacation Smiley Happy

We will be looking forward to hearing from you.

In the meantime, maybe does anyone in the Community have any suggestions or comments?

 


Olga Terentieva
SmartBear Assistant Community Manager

Occasional Contributor

Re: Get current TestStep.operation from a DataGen property of type script.

@zorglups I'm glad my web page was helpful 🙂

New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
Let's start July with new challenges!

Create a script to change request body before sending it to the server for the TechCorner tag!


Scripts created in June:
- A script to generate a request body based on data from Datasource
- A script to go through all response nodes and check the value of the required field
- A Dispatching script to get responses based on the values in Request Body
- A script to add a new tag and assign it to all TestCases in a TestSuite
Top Kudoed Authors