cancel
Showing results for 
Search instead for 
Did you mean: 

Changing the Endpoints Dynamically using Groovy

SOLVED
Highlighted
Contributor

Changing the Endpoints Dynamically using Groovy

Hi Team,

 

I need to change the endpoint hostname dynamically when I am passing  the environment.

 

For Example:

val1111313:8090/postpage

I have to change the host, When I am passing the INT or Staging. it has to change to va154871:8091

 

Regards,

Karthik

1 ACCEPTED SOLUTION

Accepted Solutions
Super Contributor

Re: Changing the Endpoints Dynamically using Groovy

Please note: It's been a while since I have done this (I switched to using environments a while ago), and I haven't had time to test, but try something like this:

 

log.info(testRunner.getTestCase().getTestStepByName("TestStep Name").getHttpRequest().getEndpoint())

testRunner.getTestCase().getTestStepByName("TestStep Name").getHttpRequest().setEndpoint("New Endpoint")

The getHttpRequest() returns a WsdlTestRequest object, this gets the endpoint methods from the inherited class AbstractHttpRequest

 

I would recommend looking again at the Environment functionality, it applies at all levels, suite, case, etc, you don't have to run at project level to use it. Personally it made my life a lot easier.

 

Edit: The above script is run from a Groovy test step within a test case, you may need to adjust to get the test step if running from a different location.

6 REPLIES 6
Regular Contributor

Re: Changing the Endpoints Dynamically using Groovy

Hi @maddenapally ,

 

Didn't get your question correctly, can you please explain a bit more with any screenshot or UseCase.

 

 


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal
Contributor

Re: Changing the Endpoints Dynamically using Groovy

Hi 

 

Thanks for your quick reply,

 

I have to run my all testcases in the particular environment, when I am passing the environment name from the properties. For Example If I am passing the INT, It has to chage the host name to INT host and execute all the test cases in the INT environment. Same for Staging also.

 

INT : http://va1i122-121.iext.global:8444/mbean

Staging : http://va1s454-178.iext.global:8098/mbean

 

Please find the attached screenshot for more info

 

Regards,

Karthik

Super Contributor

Re: Changing the Endpoints Dynamically using Groovy

Is there a reason you are not using the built in Environments functionality of Ready API? The use case you describe is the exact reason for it's functionality?

 

You can read about it here:

 

https://support.smartbear.com/readyapi/docs/testing/environments/index.html

Contributor

Re: Changing the Endpoints Dynamically using Groovy

I am not running from project level, need to run from Test Suite level.

 

Regards,

Karthik

Super Contributor

Re: Changing the Endpoints Dynamically using Groovy

Please note: It's been a while since I have done this (I switched to using environments a while ago), and I haven't had time to test, but try something like this:

 

log.info(testRunner.getTestCase().getTestStepByName("TestStep Name").getHttpRequest().getEndpoint())

testRunner.getTestCase().getTestStepByName("TestStep Name").getHttpRequest().setEndpoint("New Endpoint")

The getHttpRequest() returns a WsdlTestRequest object, this gets the endpoint methods from the inherited class AbstractHttpRequest

 

I would recommend looking again at the Environment functionality, it applies at all levels, suite, case, etc, you don't have to run at project level to use it. Personally it made my life a lot easier.

 

Edit: The above script is run from a Groovy test step within a test case, you may need to adjust to get the test step if running from a different location.

Contributor

Re: Changing the Endpoints Dynamically using Groovy

Thanks it's working for me

 

Regards,

Karthik

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