cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to overload default environment propgrammatically ?

SOLVED
Frequent Contributor

Is it possible to overload default environment propgrammatically ?

Hello,

My project contain tests that can be executed in several environments. So far I've defined three environments pointing to different equipments that have different endpoints and credentials. These are the only difference between them.

I want to extend the use of my tests to other users that have their own equipment with a new endpoint and their own credentials. As I don't know how many of them will need to use my tests, I think of passing endpoint and credentials to the testRunner in order to configure the default environment via a groovy script before executing the tests.

Is it possible to do so ?

 

thanks for any help

 

Alexandre

1 ACCEPTED SOLUTION

Accepted Solutions
Frequent Contributor

Re: Is it possible to overload default environment propgrammatically ?

Well,

I did not manage to understand it enough to apply it to my case, so I ended up with a dynamic setting.

I removed the use of Enviroment parameter in testRunner (now it uses default) and I provide as additional parameters the endpoint and credentials for my new environment.

Then I parse my requests and when I hit the first one, if data is provided and the endpoint is different from the default one, I update values with the parameters provided.

I noticed that changing it on one API impacts all the other APIs so I do it only once. As it is done with testRunner, modification is not persistent which perfectly suits my needs.

 

Here's the procedure :

in all my setup scripts I call configuration test case that I provide with the parameters and then I set the properties to the step

def endpoint = context.expand( '${#TestCase#endpoint}' )
def username = context.expand( '${#TestCase#username}' )
def password = context.expand( '${#TestCase#password}' )

... <checking the completness of data>

	endpoint = "http://"+endpoint
	
	// updating endpoint and credentials require to modify only once
	found = false 
	project.testSuites.find(){
		ts ->
		ts.getValue().getTestCaseList().find(){
			tc ->
			
			tc.getTestStepList().find(){
				step ->
				//log.info step.config.type

				if ((tc.name.contains("/m2m/fim/items"))&&( step.config.type == "restrequest"))
				{
					current_endpoint = step.getPropertyValue("endpoint")
	
					// update environment if it is not the one expected 
					if (current_endpoint != endpoint)
					{
						step.setPropertyValue("endpoint", endpoint)
	
						if( (username == "")||(password == ""))
						{
							msg = "the current Username and/or Password have not been set for environment $endpoint"
							testRunner.fail(msg)
							log.error msg
						}
						else
						{
							step.setPropertyValue("Username", username)
							step.setPropertyValue("Password", password)
							log.info "updated environment to $endpoint"
						}
					}
					found = true
				}
			}
		}
	}

Thanks for the help @nmrao

 

 

 

4 REPLIES 4
Highlighted
Community Hero

Re: Is it possible to overload default environment propgrammatically ?

Moderator

Re: Is it possible to overload default environment propgrammatically ?

Thanks for the link, @nmrao .

 

@krogold, did this help?


Olga Terentieva
SmartBear Assistant Community Manager

Frequent Contributor

Re: Is it possible to overload default environment propgrammatically ?

Well,

I did not manage to understand it enough to apply it to my case, so I ended up with a dynamic setting.

I removed the use of Enviroment parameter in testRunner (now it uses default) and I provide as additional parameters the endpoint and credentials for my new environment.

Then I parse my requests and when I hit the first one, if data is provided and the endpoint is different from the default one, I update values with the parameters provided.

I noticed that changing it on one API impacts all the other APIs so I do it only once. As it is done with testRunner, modification is not persistent which perfectly suits my needs.

 

Here's the procedure :

in all my setup scripts I call configuration test case that I provide with the parameters and then I set the properties to the step

def endpoint = context.expand( '${#TestCase#endpoint}' )
def username = context.expand( '${#TestCase#username}' )
def password = context.expand( '${#TestCase#password}' )

... <checking the completness of data>

	endpoint = "http://"+endpoint
	
	// updating endpoint and credentials require to modify only once
	found = false 
	project.testSuites.find(){
		ts ->
		ts.getValue().getTestCaseList().find(){
			tc ->
			
			tc.getTestStepList().find(){
				step ->
				//log.info step.config.type

				if ((tc.name.contains("/m2m/fim/items"))&&( step.config.type == "restrequest"))
				{
					current_endpoint = step.getPropertyValue("endpoint")
	
					// update environment if it is not the one expected 
					if (current_endpoint != endpoint)
					{
						step.setPropertyValue("endpoint", endpoint)
	
						if( (username == "")||(password == ""))
						{
							msg = "the current Username and/or Password have not been set for environment $endpoint"
							testRunner.fail(msg)
							log.error msg
						}
						else
						{
							step.setPropertyValue("Username", username)
							step.setPropertyValue("Password", password)
							log.info "updated environment to $endpoint"
						}
					}
					found = true
				}
			}
		}
	}

Thanks for the help @nmrao

 

 

 

Moderator

Re: Is it possible to overload default environment propgrammatically ?

Hi @krogold ,

 

Thanks for sharing the solution and for providing such detailed information.
Great to hear you have found a way to solve this!


Olga Terentieva
SmartBear Assistant Community Manager

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