1

Using grpcurl, we can interact with the gRPC services. However, response is not validated automatically. Is there a way using which we can write test cases for gRPC services using grpcurl with any automation framework?

Pratik Patel
  • 115
  • 1
  • 2
  • 8

1 Answers1

1

Automating grpcurl can be done using cypress as below:

spec.js file

it('verify grpc service response', function () {
        let path = './cypress/fixtures/test_data.json';
        let method = 'Service.Method';
        
        //calling custom cypress command
        cy.func(path, method).then((response) => {
            expect(response.val1).to.eq(0)
            expect(JSON.parse(response.stdout).val2).to.equal(1);
        })
    });

common method - cypress/support/commands.js

Cypress.Commands.add("func", (filepath, method) => {
  cy.readFile(filepath).then((str) => {
    str = JSON.stringify(str)
    let response = cy.exec('npx grpcurl --plaintext -d \'' + str + '\' grpc.server.com:80 ' + method)
    return response;
  })
Pratik Patel
  • 115
  • 1
  • 2
  • 8