Forum Discussion

khurlburt's avatar
khurlburt
Occasional Contributor
10 years ago

[Res] Help with setting variable endpoint based on environm

Hi,

I need to be able to run a SoapUI Pro Test Suite based on two different variables:

1. Environment
2. Endpoint for the environment: To be clear: the same environment can use different endpoints for the same service.

In addition, I would like to be able to execute the same Test Suite both from the command line AND from within SoapUI ideally without any manual manipulation of the test itself. (I am OK with disabling a test case for the purpose of the test being available for the command line.) I have accomplished the above goal for the command line only using the following command:

testrunner.bat -r -EQA -PCPServiceEndpoint=https://mck-cs-customer-profile-qa.cloudapp.net "C:\Users\ehda1tq\Desktop\SoapUI projects\CustomerProfile.xml"

(where "QA" is the environment and "CPServiceEndpoint" is a project-level property). This works. I can execute the above command using whatever environment and endpoint I like.

The problem is trying to execute the exact same Test Suite from within SoapUI itself (versus the command line). I cannot populate the CPServiceEndpoint project property with the desired endpoint at the time that I am trying to run the test. I have tried using a a property transfer step and this doesn't work. Example:

Preconditions:
- CPServiceEndpoint is a custom project-level property
- My service endpoint is set to ${#Project#CPServiceEndpoint} also at the project level.
- Using the CPServiceEndpoint property (as the value for my service endpoint) allows me to successfully pass in the endpoint from the command line (to be used by my Test Suite) as shown above.

To allow the same exact Test Suite to be run from within SoapUI I did the following:
1. Created a new project property "X"
2. At the project level, for each (of my 4) environments - assigned "X" the hardcoded value for the endpoint
3. Switched my active environment to Default
4. In my Test Suite - created a brand new property transfer step to assign the value of "X" (based on the active environment) to CPServiceEndpoint
5. When I run the Test Suite, it doesn't work because the source value "X" is missing.
6. I determined that the issue in step 5 (value of "X" missing) is because I created the property transfer while the active environment was "Default" SO onto step 7
7. Switched my active environment to Stage & repeated step 4
8. It did work for Stage (because I created the property transfer step while Stage was the active environment) BUT the 3 other environments do NOT work since the value of "X" being transferred to CPServiceEndpoint is for Stage only

I also tried writing a Groovy script to circumvent this property transfer issue (described above). However - I am new to SoapUI and was not able to successfully do this. Nor am I sure that this is the best approach. What is the best way to set CPServiceEndpoint project property to a specific (hardcoded) value BASED ON ENVIRONMENT to be used every time the Test Suite is run manually?

As I said - I am new to this - any tips/advice would be greatly appreciated.

Thanks,
Kelli

4 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi Kelli,

    A few things to keep in mind when working with environments. When you create a project property before any environment is created, when you get to create the first environment, you will have the option to "Copy endpoints & credentials from the project". Then your created environment will inherit the property and its value as you had set it up (that would be in the "Default" environment which exists before any actual environment is added to the project.)
    Then if you are adding a project property after environments have been created, you should go to the Overview tab of your project and add the property there. Your environments will inherit it, but the value won't be set. You need to go to the Environments tab, and set the value of the property in each environment.
    So your endpoint ${#Project#CPServiceEndpoint} will work in all the environments.

    Regards,

    Giscard
    SmartBear Support
  • khurlburt's avatar
    khurlburt
    Occasional Contributor
    Hi Giscard,

    Thank you for your reply.

    I had already done all that you suggest. This is not the problem.

    Before I was trying to run from the command line, I did not need to use any custom project properties to successfully run my test suite from each of the environments. I created the default environment (as you say) with NO custom properties. I then went to the Environments tab and created 4 environments (using the "Copy endpoints & credentials from the project") and then changed the endpoint for my service for each of the 4 environments. Again, no custom properties were in play here and the test suite ran from each of the 4 environments using the proper endpoint (defined at the project level for each of the 4 environments). I understand how to do this when not using a custom project property for the endpoint.

    Later - I needed to be able to run my test from the command line. So I then added the custom project property CPServiceEndpoint (on the Overview tab). I then went to each of the 4 environments and entered ${#Project#CPServiceEndpoint} as the value for the CPServiceEndpoint. Then I tested passing the value for CPServiceEndpoint via the command line and this works fine for each of my 4 environments.

    The problem came in after adding the CPServiceEndpoint custom project property and NOT executing the test suite from the command line. I have a different value that I need to pass to the CPServiceEndpoint for each of the 4 environments. Easy to do with command line. I am stuck with how to do it from within SoapUI. (I have tried creating a 2nd custom project property to hold the value I want for each of the 4 environments and then transferring this 2nd project property into CPServiceEndpoint, but this doesn't work.)

    Does my question make sense?

    Thanks,
    Kelli
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    When you are using the TestRunner you are overriding the the endpoint project property.
    To do this when you run your test from the SoapUI Pro interface, you would have to change the value that is currently set for that project property in the environment you are using.
    The concept of overriding a property doesn't quite work the same way in the graphical user interface, as the environment choice itself is meant to be able to override some set project properties, and you pre-define that in the environment.
    Instead of having a second property "X" that you transfer to CPServiceEndpoint, why not have an environment for each such endpoints "X"? From your perspective they would be sub-environments of "QA", for instance, QA_1, QA_2 each with it's CPServiceEndpoint that refers to the correct X endpoint value needed for your QA tests. Could this work for you?

    Regards,

    Giscard