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
Highlighted
Super Contributor

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.

View solution in original post

6 REPLIES 6
Highlighted
Community Leader

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,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
Contributor

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

Highlighted
Super Contributor

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

Highlighted
Contributor

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

 

Regards,

Karthik

Highlighted
Super Contributor

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.

View solution in original post

Highlighted
Contributor

Thanks it's working for me

 

Regards,

Karthik

New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Want a fun and easy way to learn ReadyAPI and show off your skills? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Get a full Raw JMS request

Participate!

Compare an expected JSON value and actual response in Events

Participate!

Fetch value/data from JSON response using Groovy Script

See replies!

Get data from Petstore and add it to Excel sheets

Participate!
Top Kudoed Authors