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

Value not being passed to reusable feature file #1322

Closed
theathlete3141 opened this issue Oct 12, 2020 · 8 comments
Closed

Value not being passed to reusable feature file #1322

theathlete3141 opened this issue Oct 12, 2020 · 8 comments
Assignees

Comments

@theathlete3141
Copy link

Using karate version 0.9.6, there is a strange issue related to the simultaneous use of reusable feature files, callonce, scenarios, scenario outlines.

The following (test1.feature) will fail

Feature:
  Background:
    * callonce read('this:doSomething.feature')

  Scenario: Basic scenario
    * print 'Basic scenario'

  Scenario Outline: Basic scenario with value <value>
    * print 'Basic scenario with value ' + value
    * call read('this:doSomethingWithValue.feature') { value: #(value) }

    Examples:
      | value |
      | 1     |

Where doSomething.feature

@ignore
Feature:
  Scenario:
    * print 'Do something'

And doSomethingWithValue.feature

@ignore
Feature:
  Scenario:
    * print 'Do something with value ' + value
    * match value != '#(value)'

Although value is 1 (as expected) within the scenario outline, in doSomethingWithValue.feature it is instead equal to #(value). I.e. it prints Basic scenario with value 1 and Do something with value #(value).

By making minor changes, this can test be made to not fail:

  • remove the callonce line (test2.feature)
  • remove the scenario (test3.feature)
  • replace callonce with call (test4.feature)

Downgrading to karate version 0.9.5 will also fix this issue.

This can be demonstrated in the attached example project which is run using

mvn clean install

myproject.zip

@ptrthomas
Copy link
Member

@theathlete3141 tagging as help wanted. not considering a priority as you are using global variable scope. note that any feature call argument JSON will be auto-added to the scope of the called feature and 0.9.5 behavior could have been a bug. feel free to challenge based on what the documentation says (e.g. shared / isolated scope)

@theathlete3141
Copy link
Author

Thanks @ptrthomas. I'll go back to the documentation so that I can better understand scopes

@theathlete3141
Copy link
Author

I assume you are referring to the scope of the variable value? Within doSomethingWithValue.feature I have verified that __arg.value is also #value rather than 1 as expected in the case of the failing test (test1.framework).

If I update doSomethingWithValue.feature to

@ignore
Feature:
  Scenario:
    * print value
    * print __arg.value
    * match value == __arg.value

Then although each print statement appears to print the same output, the match statement fails for test1.framework. This may not be related to the issue, but is in itself strange that a comparison between #value and #value appears to fail.

I believe that 0.9.5 works as intended and that the behaviour of 0.9.6 is a bug. The failing step is seen in doSomethingWithValue.feature which is only called from the Scenario Outline. This failure is related to the variable value which is only used in these two places. This failure only happens when we have also have both a callonce from Background and a Scenario (in the above example each of these just executes a simple print statement, but the same outcome is seen if they are empty). As described in the original issue, minor changes to things not related to the Scenario Outline appear to affect the Scenario Outline execution.

@ptrthomas
Copy link
Member

@theathlete3141 great, now please help debug the code also :)

@ptrthomas ptrthomas self-assigned this Oct 13, 2020
@ptrthomas ptrthomas added this to the 1.0.0 milestone Oct 13, 2020
ptrthomas added a commit that referenced this issue Oct 13, 2020
@ptrthomas
Copy link
Member

@theathlete3141 thank you for raising this and I have fixed it - it was indeed introduced in 0.9.6
please keep up the good work and ignore my previous comments - which is me over-reacting to people finding bugs in my code >_<

I've made sure this fix is in the new version / re-writing - so this helps a lot. it would be good if you can build from source and confirm that it works (the developer guide can be found in the wiki)

also the new matching / xml / schema matching code is a lot more maintainable than before - let me know if you want pointers in case you would be interested in trying to improve the XML part where you have found some gaps

@theathlete3141
Copy link
Author

I think all devs are a little protective of their code ;)

For completeness, I also want to add that (when not using your fix) using def with callonce would also fix the original issue (test5.feature)

Feature:
  Background:
    * def unused = callonce read('this:doSomething.feature')

  Scenario: Basic scenario
    * print 'Basic scenario'

  Scenario Outline: Basic scenario with value <value>
    * print 'Basic scenario with value ' + value
    * call read('this:doSomethingWithValue.feature') { value: #(value) }

    Examples:
      | value |
      | 1     |

However using def with the call does not fix the issue i.e. the following would still fail (test6.feature)

Feature:
  Background:
    * callonce read('this:doSomething.feature')

  Scenario: Basic scenario
    * print 'Basic scenario'

  Scenario Outline: Basic scenario with value <value>
    * print 'Basic scenario with value ' + value
    * def unused = call read('this:doSomethingWithValue.feature') { value: #(value) }

    Examples:
      | value |
      | 1     |

@theathlete3141
Copy link
Author

I have checked out the develop branch (commit 2b7be93) and ran

mvn clean install -P pre-release

in the root directory.
I can see that the callonce-bg.feature test in is run and passes which verifies the fix
(karate-gatling fails

@ptrthomas
Copy link
Member

1.0 released

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