Forum Discussion

heldan's avatar
heldan
New Contributor
14 years ago

[Resolved] Synchronized properties in soapUI and loadUI?

Hi all,

How can I synchronized properties in soapUI and loadUI?

My current setup in soapUI and loadUI works fine when it is executed sequentially but as soon as I start parallel threads using loadUI I get problems since the thread uses each others property values.

Since this is fundamental in load testing I would be surprised if not supported but I can not find anything on this forum about it. In soapUIpro there is DataGen TestStep which might solve my issue but I only want to use the soapUI.

I would really appreciate if anyone have some hints since otherwise loadUI will not be an option for us which would be sad since it have many other nice features that I would like to use.

/Mikael




Bellow follows an example and my Groovy script that might explain my problem better.

------------ Example ----------------

I have a scenario where I will loop through a number of users, e.g. user1 -> user99, and perform a number of requests for each user.
To keep track of the user I have the following properties in soapUI.

Project Property: user_range_start = holds the start number in the range e.g. 1
Project Property: user_range_end = holds the end number in the range e.g. 99
Project Property: user_next = holds the value of the next user
TestCase Property: user = holds the value of the current user


The sequence will then be:
1. Get the next user and store it in Testcase property user
2. Step the Project Property user_next
3. Perform the login for the user.
4. Perform the additional requests.
5. Repeat step 1-4 above until reaching the end of the user range.


I am using a Groovy script for this, see below:

------------ Groovy script ----------------


// Create variables for reading/setting properties
def testcase = testRunner.testCase;
def project = testRunner.testCase.getTestSuite().getProject();

// Get properties for calculation of next user.
def user_prefix = project.getPropertyValue("user_prefix");
def user_range_start = project.getPropertyValue("user_range_start");
def user_range_end = project.getPropertyValue("user_range_end");
def user_next = project.getPropertyValue("user_next");
def user_suffix;


// Check if end of user range reached.
// Yes => start over from the beginning of the range
// No => get next user in range
if ( user_next.toInteger() > user_range_end.toInteger()) {
user_suffix = user_range_start;
project.setPropertyValue("user_next", (user_range_start.toInteger() + 1).toString());
}
else {
user_suffix = user_next;
project.setPropertyValue("user_next", (user_next.toInteger() + 1).toString());
}

// Set the property for the next user which will be used in next request
testcase.setPropertyValue("Username", user_prefix + user_suffix);

6 Replies

  • heldan's avatar
    heldan
    New Contributor
    My problem remains but I have find some hints on the forum which I thought I could summarize. Unfortunately my problem still remains.

    By the forum I have understood:
    1. I should use the Load Script to initiate the properties on the loadTestContext.
    2.In the test case I create a Groovy Test Step that reads the properties from the LoadTestContext within a synchronized code block.

    My problem, if this is the right way to go, is that I can not find how the syntax would like for it and that the loadTestContext is always null.

    In the Load Script I have tried;

    context.setProperty("UserPrefix", "user");
    context.setProperty("UserRangeStart", "23");
    context.setProperty("UserRangeEnd", "30");
    context.setProperty("UserNext", "23");



    And in the Groovy Test step:

    if (context.loadTestContext != null) {
    synchronized (context.LoadTestContext) {


    // Get properties for calculation of next user.
    def user_prefix = context.LoadTestContext.getPropertyValue("UserPrefix");
    }
    else {
    // uses project properties since the context will not be available for single request.
    }


    Right now I execute the Test Case from the Test Suite tab of the Project but I have also tried it as a load test and then got the exception below:
    groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTestContext.getPropertyValue() is applicable for argument
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    The LoadTestContext doesn't have a getPropertyValue method, so that may be why your Groovy Test Step is failing. Instead use something like:


    //Set a property:
    context.LoadTestContext['UserPrefix'] = "Some value"

    //Read a property:
    def user_prefix = context.LoadTestContext['UserPrefix']


    What is the Load Script you mentioned? Are you referring to the TestCase Setup Script?

    Regards,
    Dain
    eviware.com
  • heldan's avatar
    heldan
    New Contributor
    Hi Dain,

    Thanks for the reply, unfortunately I still get problem which I do not now how to solve.
    With Load Script yes I mentioned the Setup Script but on project level.

    What I have done now is that in the Setup Script on project level (these parameters should be used by several different test cases) I use:
    context.LoadTestContext['UserPrefix'] = "Some value"

    And in the Groovy script on Test Case level I use:
    def user_prefix = context.LoadTestContext['UserPrefix']

    The problems now are:
    1. If I try to run only the Setup script by it self to confirm the syntax I get a NullPointerException since LoadTestContext seems to be null. Do I need to initiate it somehow first or is it failing because I run it manually.
    2. I create a load test in soapUI for the test case where I have the Groovy script that reads the parameters but it fails because the user_prefix get null back from the context.LoadTestContext['UserPrefix'].
    3. In the Groovy script I have added a log.info of the context.LoadTestContext so I can see it is empty. Tried to do the same in the Setup script but nothing is written. Guess it because the Setup script is not executed which I thought it should be everytime I executed the test case?

    It seems as if I have misunderstood something fundamental?

    My plan is that if I can get it to work as a load test in soapUI I will export the test case to loadUI and run it there.

    /Mikael
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    The Project Setup Script will be run once, when the project is loaded. This will never be during part of a LoadTest, and thus will never have a LoadTestContext. If you want to run something at the start of a LoadTest, you would generally put it in the LoadTest Setup Script, but that will only work in soapUI, not in loadUI. If you need initialization for the LoadTestContext which works for both soapUI and loadUI you can use the Groovy TestStep. This will run once in each run of the TestCase, so you will need to add some code so that initialization is only done once, for example:


    //Groovy Test Step:
    if( context.LoadTestContext ) {
    synchronized( context.LoadTestContext ) {
    //Initialize only if not already initialized
    if( !context.LoadTestContext['init'] ) {
    context.LoadTestContext['init'] = true
    context.LoadTestContext['UserPrefix'] = "Some value"
    //Add the rest of the initialization here...
    }

    //And use/modify the context:
    def user_prefix = context.LoadTestContext['UserPrefix']
    // ... and so on
    }
    }


    Basically, the LoadTestContext lives for the duration of a soapUI LoadTest. In loadUI it lives for the lifetime of the Project, so to reset it you currently need to close the project and re-open it. This is an oversight and will be fixed so that the LoadTestContext is reset when the test ends. Hopefully we'll have it fixed pretty soon.

    UPDATE: I've fixed this now so that the LoadTestContext in loadUI is reset as you would expect. The fix will be in the upcoming nightly build of loadUI here as well as in the next upcoming release of loadUI. The LoadTestContext should now reset on start of the test, and when manually pressing the "Reset" button.

    Regards,
    Dain
    eviware.com
  • heldan's avatar
    heldan
    New Contributor
    Hi Dain,

    Just wanted to let you now that your last code example solved my problems.
    I have now been able to run a Load Test both in soapUI as well as in loadUI.
    So a big thanks you for the quick and excellent support.

    May I also suggest that you add the code example to the documentation at for example http://www.soapui.org/Load-Testing/load ... pting.html since I believe it would be of general interest.

    Regards,
    Mikael