cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass values to Custom Properties declared in Environment from command line

Occasional Contributor

How to pass values to Custom Properties declared in Environment from command line

Hi,

 

I am facing this issue. I have few custom properties declared in one Environment. I want to change the values of those custom variable when running it from Command line or via Test Runner. 

 

In test runner, even if I pass different values to the same custom properties in the project properties tab, they do not override, instead the properties gets initiated with the saved values in that environment.

 

What I want to achieve from this:

I want to have environments configured with my project, with some custom variables like baseURL, adminEmail, adminPassword. But I want to override them (when required) from Test Runner or cli.

4 REPLIES 4
Occasional Contributor

Re: How to pass values to Custom Properties declared in Environment from command line

if you try to set custom parameters to values from command line via -P parameter then these will be set always for environment that was saved last time.

 

you have to write testcase which first set new environment and save project and after that you can call your test cases from command line with -P parameter for setting values for the new selected environment

Visitor

Re: How to pass values to Custom Properties declared in Environment from command line

I'm having the same issue.

 

we have Environments configured such as Dev, Staging and Prod that map to load balancers.

 

we have suites of smoke tests that we want to run against individual hosts behind the load-balancer where the api we're testing is addressed at the host level, while the dependencies are tested at the load-balancer level.

 

I'm trying to make this work by setting the endpoints to be Environment parameters, with different values for the api under test and the dependencies.

 

eg: if I'm testing our 'Customer' api, which has a dependency on our 'Auth' API, I have the 'Auth' calls configured with an endpoint of something like ${#Project#loadBalancedHost} and the 'Customer' endpoints as ${#Project#directHost}. Each environment has different values for these, and when I execute from Jenkins, I'd like to override 'directHost' so that I can hit each server behind the loadbalancer with the -P option from the command line.

 

As mentioned earlier in this thread - this is only working for the environement of the project when it was last saved. So if I saved the project with 'Dev' as the active environment, and I run from the command line with -EDev and -PdirectHost=blah

then it the override of directHost works. But if I then run -EStaging -PdirectHost=blah the -P flag is ignored and the value from the Staging environment is used. If I go back into the project, set the environment to Staging and then save and rerun the command, it works as expected.

 

This seems to be a bug - I'm setting the environment on the command line, but it seems to be applying overrides specified with the -P switch to whatever environment was active the last time the project was saved. I've tried saving the project with the Default Environment active, but this doesn't work either.

Community Hero

Re: How to pass values to Custom Properties declared in Environment from command line

Is it possible to show the issue thru some screen shots and steps to reproduce in a simple manner?


Regards,
Rao.
Occasional Contributor

Re: How to pass values to Custom Properties declared in Environment from command line

I didn't trust on -E parameter :-) because it never works properly

I guess the problem is that SoapUI first set parameters (via -P) and after that switch environment (via -E). 

 

I use my own solution to switch environment via running "preparing" test case with groovy script that contains something like this:

context.testCase.testSuite.project.setActiveEnvironment(context.testCase.testSuite.project.getPropertyValue("runEnv"))

Expected environment will be set via project parameter runEnv:  -PrunEnv and save project via -S.

 

After that I start my test suite via second run of testrunner and it works properly.

 

 

 

New Here?
Join us and watch the welcome video:
Watch the new Interview
Top Kudoed Authors