Calling and Validating gRPC Methods

We are switching from RESTful API to gRPC calls at my company. Anyone used Robot Framework to invoke services coded as gRPC methods?

Well I knew nothing about gRPC, so I did a little research and it seems I have good and bad news.

The good news gRPC - Wikipedia seems to be basically a fancy way of saying REST over HTTP/2 so once there is a library that supports HTTP/2 calls you should be good to go.

Now for the bad news, the most commonly used library for testing web API’s is the robotframework-requests | Robot Framework keyword library wrapper for requests which I believe wraps the python requests library, from what I can find there is no support for HTTP/2 in the python requests library yet, it seem people are being advised to migrate to python httpx library but I couldn’t find a robot framework library for httpx yet (Probably because it’s still in beta)

Another option that might work is to use the Http keyword in https://marketsquare.github.io/robotframework-browser/Browser.html?tag=HTTP#Http as the Browser library will then use a real browser to send the http request for you, I know Chrome and probably Firefox will support HTTP/2, this will have more overhead than the requests library as you are opening a browser, but it may be a workable solution.

All the above is the result of my searching around and may not be 100% correct, but hopefully it’s at least helpful,

Dave.

1 Like

grpc works in a way that you define a protocol, and then use the provided tools to generate client and server implementation - for Python specific stuff, grpc provides this quick tutorial: Basics tutorial | Python | gRPC

Now, once there’s a python client, getting that to work with robot as keyword library is pretty much the business are normal…

so, answer to OP:

Possible, will require you to make some bit of glue code to make the python code <-> robotframework work. Biggest hurdle is probably if your grpc endpoints require some form of streams, in those cases, one probably needs some state handling on the python layer …

1 Like

Thanks, Dave. Good observations. Looking back, my original post is open-ended, vague - or, at least, a big topic covering basics of the Session-layer. It’s like asking: How do you test HTTP using RF? Or - “how do you test network calls using RF?” Very far removed, in my opinion, from Application Testing. I will update here as my journey continues. I am also looking at other testing tools, a survey of the field. There are scores of them.

1 Like

Thanks, Jani, for the Python-specifics. Robot is, of course, Python-friendly. A great feature of RF is the way a Python function def can be invoked as Keyword, just by replacing the underscores with spaces. I love that feature. As I learn more about gRPC API, I will post here with my findings. Right now, I am using grpcurl and grpcui to ad-hoc test some services and that’s all I am comfortable with.

I am having some success using Library Process and invoking grpcurl with parameters, such as: ${result}= Run Process /usr/local/bin/grpcurl -plaintext ${service_address} grpc.health.v1.Health/${method}

Hi @steve

did you execute grpc with Robot? Do you have some snippets?

Regards,
Markus

Yes, using Process Library to invoke grpcurl

${result}=   Run Process    grpcurl   -d   { "tenant_id":"${NEW_TENANT_ID}"}   -plaintext    ${TENANT_URL}  tenant.TenantService.Get   stdout=stdout.txt   stderr=stderr.txt

Note, when creating objects, you must send the data -d before the -plaintext and host info

2 Likes