question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Karate-Netty: Variables defined in calling feature are not present in the called features.

See original GitHub issue

karate-sample-persistent-state-dynamic-scope.zip

Hello! I don’t know if is intended or not, but the dynamic scope in MockServer features doesn’t work, the test fails in the last line of the second proxy.feature Scenario.

proxy.feature

    * def outer_scope_variable = "hello"
    * call common_outer_scope  ERROR: org.graalvm.polyglot.PolyglotException: ReferenceError: "outer_scope_variable" is not defined

The call to common_outer_scope fails because it can’t find the outer_scope_variable defined anywhere. Also the built-in objects, like request\response are not accessible. This is only for karate-netty, in client features everything works as expected:

first-case.feature:

  * def outer_scope_variable = "hello"

  # Here the feature just logs the value of the `outer_scope_variable`, to demostrate
  # that the problem is only in karate-netty feature files
  * call common

I found another bug while investigating this, as you can see in proxy.feature, to the first call to common_request is specified an argument.

Scenario: pathMatches('resource')

    * match request == body_req

    * call common_request ({ test: 1, default_argument: "not default anymore" })
    ...

In the second call btw, (the second Scenario), the argument is not passed, but the called feature continues to see the old value.

Scenario: pathMatches('resource/bad')
    
    * match request == body_req_2

    * call common_request ({ test: 10 })
common-request.feature

    * def default_argument = karate.get('default_argument', "default value")
    * karate.log("Default Argument: ", default_argument)

EveryTimes it prints:

Default Argument: 'not default anymore'

This can endanger behaviours of feature files which relies upon defaults, making them not trustworthy.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ivangsacommented, Dec 14, 2021

hi, I had a look yesterday and this project is overly complex

the problem seems to be, on a server side feature, when calling another scenario with no arguments, the called scenario can not see the global variables from calling scenario

Attached is a minimun project that shows this error… karate-mocks-server-calling-other-scenario-error.zip

0reactions
ptrthomascommented, Nov 2, 2022

1.3.0 released

Read more comments on GitHub >

github_iconTop Results From Across the Web

unable to update variables in a called feature - karate
When you call with "shared scope" you typically don't need to pass arguments. Because all variables are visible anyway.
Read more >
Karate | Test Automation Made Simple.
Karate is the only open-source tool to combine API test-automation, mocks, performance-testing and even UI automation into a single, unified framework.
Read more >
High Fidelity Stateful Mocks (Consumer Contracts ... - Medium
Scenario Body: can hold any KarateDSL expression: defining variables, calling functions, other features, matching and asserting… and any ...
Read more >
call_user_func - Manual - PHP
However I found that at some times, the use of this function is needed in situtations where variable function calls can not be...
Read more >
do.call: Execute a Function Call - Rdrr.io
If quote is FALSE , the default, then the arguments are evaluated (in the calling environment, not in envir ). If quote is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found