Rest API session persistence

Hi Everyone,
I’m facing one issue while running request library of framework.

I’m trying to GET request to one of our controller and we are saving our SESSION and the same SESSION we are using while doing POST request on the same controller for one Domain tab (there is a tab called a domain in the controller. I’m trying to do POST request on that.)

when I’m trying to do the POST request on the controller. It is again going to the sign-in page.

So to check the system persistence under domain creation, I have called the same SESSION which i created under login controller, which seems to be working as expected because I’m getting SESSION object value same under both the functions.

But while doing POST on Domain it’s going to sign in page.

If anyone knows the solution can please help.

Using BasicAuth authorisation.

Below is the code snippet:

*** Settings ***
Library Requests
Library Collections
Library String
*** Variables ***
${BASE_URL} http://10.49.182.127:3000 ${LOGIN_PATH} /administrators/sign_in ${USERNAME} root@adtran.com
${PASSWORD} blueblue
${SESSION_ALIAS} MySession
${DOMAIN_NAME} AALLEXXA
${DOMAIN_PATH} /platform/domains/ ${SESSION}

*** Test Cases ***
Initialize Session ${SESSION}= Create Session ${SESSION_ALIAS} ${BASE_URL} verify=${False} Set Global Variable ${SESSION} Log Session: ${SESSION}

Login to Controller
Log Session: ${SESSION}
${login_data}= Create Dictionary administrator[email]=${USERNAME} administrator[password]=${PASSWORD} ${response}= POST On Session ${SESSION} ${LOGIN_PATH} json=${login_data}
Should Be Equal As Numbers ${response.status_code} 200
Log Login successful

Create Domain
Log Session: ${SESSION}
Log Session Data: ${SESSION.cookies}
Log Domain started ${headers}= Create Dictionary Content-Type=application/json
${domain_data}= Create Dictionary domain[name]=${DOMAIN_NAME}
${response}= POST On Session ${SESSION} ${DOMAIN_PATH} json=${domain_data} headers=${headers}
Log Domain creation response: ${response.text} Should Be Equal As Numbers ${response.status_code} 200
Log Domain creation successful

Regards,
Shankar

If anyone knows please help on this.

Hi Shanker,

I think what you are after is Suite setup and teardown, specifically use the Suite setup part to initialise your session.

No need to make ${SESSION} global as you only need to session alias to use the session and you’ve already defined that with ${SESSION_ALIAS}.

Hope that helps,

Dave.

In addition to having the Session as a Suite Variable, I suspect that you need to get the CookieJar from the Response of the Login POST and set that as the Session cookies, assuming authentication is done / persisted by use of cookies in your case.