How to test multiple endpoints using REST?

I want to test multiple endpoints and how can i do that any idea?

Can you clarify what your problem is? What are you trying to do? What have you tried so far?

When you’re writing JS tests, you have total control over the URLs/paths you’re testing against.

Hi @kboers Usually we use to provide the endpoint in the rest config similarly if we want to provide multiple urls in config file and use that in our test how can we do it?? Any idea??

I’m not sure if this is what you’re asking, but I control the endpoint URLs separately from the config. I have a default fallback value in the config that won’t work in most cases. I created an environments.js file with getters for various urls I might need. Along the lines of getQaUrl or getProductionUrl. Or for specific other apps I’m testing in the same suite: getDirectoryUrl or somesuch. At test time, the environments.js file reads the target test environment from the shell’s environment variables (TEST_ENV=QA) and then uses that to construct the proper environment/app-specific URL. Then I use that right in the tests and bypass the config file entirely.

Yep, I got your point @kboers so you cant control multiple endpoints in config file itself right?

 helpers: {
    REST: {
      endpoint: 'http://site.com/api',

As far as I know, that is correct. I have a dummy endpoint in my config. The tests or page objects or whatever request the appropriate URL for whatever it needs from my environments.js file.

Is there any particular reason why it is not handled in the config file ?

You’d have to ask the author of the REST helper. My guess is because it follows the pattern of, say, the Webdriver helper, where it has one config field for a single URL:

{
   helpers: {
     WebDriver : {
       url: "http://localhost",
     }
   }
}

Thanks for the information and clarity @kboers. Happy Learning :slight_smile:

I have the same problem as the intial question – I need to overwrite the REST helper endpoint value, but from a test this.helpers[‘REST’]…no, this.config.helpers[‘REST’]…no, so what is the syntax for replacing the endpoint value?

Got it - one way anyway - from a fellow post called 'Accessing config in Scenario"

let config = require(‘codeceptjs’).config.get();

then in the test you can
config.helpers[‘REST’].endpoint=…