0

I have two REST requests in the same TestCase.

  • login request
  • getAllParameters request

I am currently using ReadyAPI 2.6.0.

I need to log in the first request in order to access the second one.

Otherwise it does not work.

Do you know how to keep the same session between these two requests?

Félix
  • 1
  • 1
  • 1
    Without knowing for certain, I assume the first request returns a value, that somehow must be used in the second request. My guess is that it must be set as a HTTP Header value. If that is so, you can create a Property Transfer TestStep between the two, that reads the session key from response 1, and transfers the value to the request of request 2. Please add some more info. It's hard to give you a specific answer without more info. – Steen Feb 06 '19 at 20:12
  • I do understand what you mean. But the first request here does not return any value. I only use it to log in. This is an example of my URIs, I cannot show you the real ones. Login request = http://request.net getAllParameters request = http://request.net/getAllParameters I cannot directly log into the second request, I have to go through the first one before. I just need to keep the same session for both of these request. – Félix Feb 07 '19 at 09:16
  • Have you taken a look at the HTTP headers in the response? – Steen Feb 07 '19 at 09:29
  • How do you do it manually. If you can share that we can tell how the tool can help to automate it.Rest is generally stateless – Gaurav Khurana Feb 07 '19 at 11:29

1 Answers1

0

I'm guessing that the key you need to use is set in the HTTP headers.

Given that is true, and that you also need to set this particular value in the HTTP header in the following requests, you may solve it like this:

  • In your first REST Request, you add a Script Assertion with the following code:

    def value = messageExchange.responseHeaders["session-id"];
    assert value != null
    assert value.size() == 1
    context.setProperty("sessionID", value)
    

You will need to substitute "session-id" in the first line with whatever name your correct HTTP header has. You should NOT change the "sessionID" in the last line. This is a separate variable name we use for ourselves. This will assert that a value has been set, and will then save it as a context variable, which we can reuse in later steps.

  • Add a Groovy Script teststep after your first REST Request Teststep. Rename it to "Extract Context Variable" (that name will be reused in the next step) Then add this code in it:

    def value = context.getProperty("request-id")
    return value
    

Context values are not available from anywhere. By extracting it here, and returning the value, it will be easier to make use of it in the rest of your REST Request teststeps.

  • Open your second REST Request Teststep (and third, and fourth etc. if you have more) Open the Headers pane at the bottom Create a new key named the same as the header your received in your first REST Request In the value, you enter

    ${Extract Context Variable#result}
    

When running the entire testcase, you should now automatically retrieve the header returned in the first response, and then transfer and reuse it in the following requests.

Steen
  • 853
  • 5
  • 12