Code Monkey home page Code Monkey logo

robotframework-requests's Introduction

Build Status PyPi downloads Latest Version

RequestsLibrary is a Robot Framework test library that uses the Requests HTTP client.

Usage

Install robotframework-requests and it's dependencies via pip

pip install -U requests
pip install -U robotframework-requests

Here is a sample test case:

*** Settings ***
Library Collections
Library RequestsLibrary
*** Test Cases ***
Get Requests
Create Session github http://api.github.com
Create Session google http://www.google.com
${resp}= Get Request google /
Should Be Equal As Strings ${resp.status_code} 200
${resp}= Get Request github /users/bulkan
Should Be Equal As Strings ${resp.status_code} 200
Dictionary Should Contain Value ${resp.json()} Bulkan Evcimen

RequestsLibrary tries to follow the same API as requests. In the above example, we load in the RequestsLibrary using the Library keyword. To be able to distinguish HTTP requests to different hosts and for ease of creation of test cases, you need to create a Session. Internally this will create a request.Session object. The Create Session keyword accepts two arguments:

  • alias to identify the session later
  • root url to the server

HTTP verbs are mapped keywords which accept two arguments:

  • alias identifying the Session we created earlier.
  • URI to send the request to.

Above we create two Sessions - one to the github api, and the other to google. Creating sessions doesn't send any requests.

After we create a Session we can send any of the following Get, Post, Put, Patch, Options, Delete, and Head requests. In the above example we send a GET request to the session with the alias google and check the HTTP response code. Then send a another GET request but this time to the session with the alias github and pass in a uri. In this case it is /users/bulkan which will return a JSON string. RequestsLibrary returned object provides a method to get the content as a JSON object format called json().

Here is another test case where an outbound http proxy is used.

*** Settings ***
Library RequestsLibrary
*** Test Cases ***
Proxy Requests
${proxies}= Create Dictionary http=http://acme.com:912 https=http://acme.com:913
Create Session github http://api.github.com proxies=${proxies}
${resp}= Get Request github /
Should Be Equal As Strings ${resp.status_code} 200

Another test case where cookies are sent in the request headers:

*** Settings ***
Library RequestsLibrary
*** Test Cases ***
Cookies in request
${cookies}= Create Dictionary userid=1234567 last_visit=2017-12-22
Create Session github http://api.github.com cookies=${cookies}
${resp}= Get Request github /
Should Be Equal As Strings ${resp.status_code} 200

For more examples see the tests folder which contains testcase files that is used to test the keywords in this library against httpbin.org.

Documentation

For individual keyword documentation see the following:

Keywords documentation

You can update the documentation once checked out by going to the top directory of this repo and issuing the following command: bash python -m robot.libdoc src/RequestsLibrary doc/RequestsLibrary.html

Help

Send your questions to the Robot Framework Users Group

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.