Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.1.0.RC5] for the chained feature calls payload variable gets unitialized if attempting to update it with set #1699

Closed
hlemmur opened this issue Aug 2, 2021 · 4 comments

Comments

@hlemmur
Copy link

hlemmur commented Aug 2, 2021

hi, the following issue popped up with v1.1.0.RC5 - in case of several chained feature calls the payload variable defined in one of the intermediate levels gets uninitialized (or gone from the scope?) when attempting to update the payload with set. Looks like it's related to #1685 .

Here comes an example.

Given:
scenario.feature from where we call the first nested feature passing the test data examples:

Feature:
  Scenario Outline: Create user name: <userName>, job : <userJob>
    * call read('feature1.feature')

    Examples:
      | userName  | userJob   |
      | hell      | bell      |

an intermediate feature where we initialize jsonRequest payload variable and call another feature:

  Feature:
    Scenario:
      * def jsonRequest = read('user.json')
      * def result = call read('feature2.feature')
      * print 'Result: ', result

a functional feature that actually sends the request, where we update the payload according to the test data examples:

  Feature:
    Scenario:
      Given header Content-Type = 'application/json'
      And url 'https://reqres.in/api/users'
      And request jsonRequest
      And set jsonRequest.name = userName
      And set jsonRequest.job = userJob
      When method post
      Then status 201
      And match response.name == userName
      And match response.job == userJob

Actual result:

13:43:13.114 [main] ERROR com.intuit.karate
And set jsonRequest.name = userName
variable is null or not set 'jsonRequest'

Some notes: it works perfectly fine if not update the payload with set - i.e. jsonRequest variable remains initialized until that line.

Of course there are workarounds to overcome it - for ex., passing the jsonRequest explicitly as a parameter from feature1 to feature2 solves the issue, - however for the huge and complex projects like ours it would require a lot of refactoring efforts.

My intention of reporting it is rather to pay your attention on it as it's something that worked in RC4, but got changed in RC5. If you think it's an inevitable behavior in the light of #1685 refactoring benefits - I understand, otherwise I'm happy to help with testing.

@ptrthomas
Copy link
Member

@hlemmur can you do a quick test against the develop branch because I think I fixed this as reported in #1687

@ptrthomas
Copy link
Member

@hlemmur and one more thing, best practice is to avoid the set keyword for JSON like this:

      And jsonRequest.name = userName
      And jsonRequest.job = userJob
      And request jsonRequest
      When method post

that should anyway work, do confirm.

@hlemmur
Copy link
Author

hlemmur commented Aug 2, 2021

@ptrthomas verified on develop build and confirm it works, thanks! 👌

yup, I agree about the best practices :) I put it as a simplified example, in real we have a complex logic for manipulating with the soap payloads for external integrations.

@ptrthomas
Copy link
Member

@hlemmur great, thanks, will close as duplicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants