Code Monkey home page Code Monkey logo

robotframework-grpc-library's Introduction

robotframework-grpc-library

GrpcLibrary is a Robot Framework library aimed to provide gRPC api testing functionalities by wrapping the well known Python gRPC Library.

How to use

In this early stage it's necessary download the script and his template

1 - Download the files above and place to root of project

  • grpcLibrary.py
  • grpcKeywodTemplate

2 - Install dependencies listed in requirements.txt

  • grpcio-tools
  • grpcio
  • protobuf
  • types-protobuf
  • googleapis-common-protos

3 - Create a folder for your service with /protos folder inside with respective proto files

4 - Run the script

python grpcLibrary.py {service_name}

As result Libraries/Grpc/{service_name}Library/ folder will be created with respective files

To use just add import

*** Settings ***
Library  /Libraries/Grpc/{service_name}Library/{proto_file_name}.py

Keywords

The generated library provides the keyword

Grpc Call {Service Name} {Endpoint Name}

So there is a Grpc Call keyword for each endpoint on proto file. Wich returns a GrpcResponse object

*** Settings ***
Library  /Libraries/Grpc/GrpcDemoLibrary/demoGrpc.py

*** Variables ***
${DEMO_URL}  localhost:8080

*** Keywords ***

Call Send Endpoint
    ${METADATA}=  Create Dictionary                correlation-id=1234
    ${BODY}=      Set Variable                     { "name" : 'Luke' }
    ${RESPONSE}=  Grpc Call DemoGrpcService Send   ${DEMO_URL}          ${BODY}  ${METADATA}
    [return]  ${RESPONSE}

Arguments

Argument Type Required Description
host str yes url of gRPC service
data str, dict no request body in JSON String or Dictionary
metadata dict no Dicitonary with metadata

GrpcResponse Object

Como retorno você receberá um objeto GrpcReponse que incluí os atributos abaixo

Property Description Avaiable
response Object of response, as defined on proto file OK Responses
json_str Json String of response, as defined on proto file OK Responses
json_dict Dict of response, as defined on proto file OK Responses
status_code String representation of gRPC status. Eg. OK, INVALID_ARGUMENT Always
metadata Trailing Metadata of response Always
error RpcError trew by gRPC non-OK Responses
call Object call of gRPC OK Responses
is_success() True if response was OK Always
is_error() True if response was non-OK Always

Test examples

You can find a few test examples in grpc_resource.robot file.

Inside a GrpcDemo folder you can find the proto used in these examples

TODO

Stream calls

Just tested with Unary calls. Stream calls need to be tested and features created if necessary

Create installable package

In this first version we need download files, put on the root of project e run command. Would be so much better if we can install through pip

robotframework-grpc-library's People

Watchers

Vinicius Cunha avatar

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.