ejohalj
ejohalj

Reputation: 37

Robot Framework fetching token

pretty new to Robot Framework. Trying to fetch a token from Azure. I have coded this in pure python code and it works as a charm, but I want to do it in Robot Framework and I am having huge problem with understanding this library.

So my code in Robot Framework looks like this:

*** Settings ***
Library         RequestsLibrary
Library         json

*** Variables ***
${Content-Type}=    application/x-www-form-urlencoded                
${resource}=        xxxxxxxxxx
${grant_type}=      client_credentials
${client_secret}=   xxxxxxxxxx
${client_id}=       xxxxxxxxxx
${headers}=         accept=application/json

*** Test Cases ***
Post Requests
[Tags]  post
Create Session   azure   https://login.microsoftonline.com/xxxxxxxxxx/oauth2/token
&{data}=  Create Dictionary   client_id=${client_id}   client_secret=${client_secret}   grant_type=${grant_type}
&{headers}=  Create Dictionary   Content-Type=application/json
${resp}=  Post Request  azure  ${url}  ${data}  ${headers}
Should Be Equal As Strings  ${resp.status_code}  200

And instead of getting a 200 I get 404.

I have also tried to use ExtendedRequestLibrary, but I get other strange errors, so I guess that I don't know how to actually use this, but that I get a 404. The code in ordinary python is more or less the same, hopefully someone could just point me to the correct answer.

If it would help I can post my python code.

Thanks!

Upvotes: 1

Views: 2982

Answers (1)

Todor Minakov
Todor Minakov

Reputation: 20077

What's the value of ${url}? You've already set the azure oauth2 token endpoint in the session creation, if you add something more you're sending the request to a resource that must probably doesn't exist.

Try like this (only the relevant portions):

Create Session   azure   https://login.microsoftonline.com/xxxxxxxxxx/oauth2
${resp}=  Post Request  azure  /token  ${data}  ${headers}

The Create Session keyword sets the base url for future requests (on this session), e.g. every route you use afterwards on it will be appended to the base.

Upvotes: 1

Related Questions