karate icon indicating copy to clipboard operation
karate copied to clipboard

Feature request: Multiline expressions on call keyword

Open richardmward opened this issue 1 year ago • 4 comments

It would be great if we could have the ability to pass the final parameter of the call keyword (https://karatelabs.github.io/karate/#call) as a multi-line expression (https://karatelabs.github.io/karate/#multi-line-expressions), so that we don't have to define an additional variable in a previous statement. e.g.

Currently we do:

Feature: Some scenarios

    Background:
        * def CreateThing = read('classpath:util/api.feature@name=CreateThing')

    Scenario: First scenario
        * def thingRequest =
          """
          {
            "prop1": "value1"
          } 
          """
        * def thing = call CreateThing thingRequest 

But it would be nice to do:

Feature: Some scenarios

    Background:
        * def CreateThing = read('classpath:util/api.feature@name=CreateThing')

    Scenario: First scenario
        * def thing = call CreateThing
          """
          {
            "prop1": "value1"
          } 
          """

The purpose is to reduce the noise when calling other functions - which when setting up a scenario which requires complex prerequisites, every little helps!

richardmward avatar Nov 22 '22 14:11 richardmward

@richardmward makes sense. call is bending the rules of JS, but for the sake of things like what you are requesting.

placing this as help wanted for now, do consider submitting a PR if you can !

ptrthomas avatar Nov 22 '22 17:11 ptrthomas

I would like to contribute. This is my first time contributing to open source project.

pradeepprabhakar avatar Jun 08 '23 08:06 pradeepprabhakar

@pradeepprabhakar sure. this will require some independent digging from your side into how the code works

ptrthomas avatar Jun 08 '23 08:06 ptrthomas

@ptrthomas I understand.

pradeepprabhakar avatar Jun 08 '23 08:06 pradeepprabhakar