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

Token is unable to fetch correct value if steps based on it is executed twice in same scenario. #1755

Open
prashantsssh opened this issue May 13, 2024 · 3 comments
Labels
🍼 incomplete Blocked until more information is provided

Comments

@prashantsssh
Copy link

prashantsssh commented May 13, 2024

👓 What did you see?

Expected token value for the same step that is getting executed for the second time in the same scenario is different from the expected value. Basically the token value stored during the execution of first step is displayed while execution of same step for the second time.

✅ What did you expect to see?

During execution, for each step fresh token value should be fetched whether the step or token value is same or not.

📦 Which tool/library version are you using?

Ruby-3.2.1
Cucumber-8.0
watir-7.6

🔬 How could we reproduce it?

  1. File name-Gemfile
source 'https://rubygems.org'
gem 'bundler', '~> 2.0'
gem 'cucumber', '~> 8.0.0'
  1. Create a feature file.
    File name-test.feature
@token
Feature: Testing Token

  Scenario: Testing Token Functionality For The Same Steps In The Same Scenario

    When I should see desired message as 'This goal is scored by PLAYER1.'
    When I should see desired message as 'This goal is scored by PLAYER1.'
  1. Create a step definition class.
    File name-step_def_steps.rb
Then /^I should see desired message as '(.+(?:PLAYER)(?:\d+).+)'$/ do |expected_msg|
 actual_msg = 'This goal is scored by JACK REACHER.'
 /^#{expected_msg}$/.match? actual_msg
end
  1. Create a parametertype class where we have to put the required token.
    File name-parameter_types.rb
ParameterType(
 name:        'token',
 regexp:      /.+(?:PLAYER)(?:\d+).+/,
 type:        String,
 transformer: -> (msg) do

   puts 'Message fetched by step-> ' + msg # This statement is placed here to check the value of message that msg variable is fetching from the step in feature file.

   test_data = {
     :player1 => 'JACK REACHER',
     :player2 => 'JOHN WICK',
   }
   case msg
   when /\PLAYER(?:\d+)/
     msg.gsub!(/PLAYER(?:\d+)/, test_data[:player1])
   else
     raise 'This token is not supported'
   end
 end
)

#You can execute the feature with the command--> bundle exec cucumber -t @token,

📚 Any additional context?

As per my opinion, the value of token is stored every time when the operation is performed and if the value of the passed token is same in the second step also then it will display the same value. However if the value of token is different in both steps, then it will work properly.
Console outupt-

@token
Feature: Testing Token

  Scenario: Testing Token Functionality For The Same Steps In The Same Scenario # features/test_token.feature:4
Message fetched by step-> This goal is scored by PLAYER1.
    When I should see desired message as 'This goal is scored by JACK REACHER.      # features/step_definitions.rb:1
Message fetched by step-> This goal is scored by JACK REACHER.
    When I should see desired message as 'This goal is scored by JACK REACHER.      # features/step_definitions.rb:1
      This token is not supported (RuntimeError)

When the step When I should see desired message as 'This goal is scored by PLAYER1.' is called again, then the parameter_types transformer (msg), should have This goal is scored by PLAYER1. But the actual message is fetched from the previous step.

QUESTION- Is that how supposed to work or is it a bug??

@luke-hill
Copy link
Contributor

Hi @prashantsssh - It's hard to glean information off of images. Could you please upload in the form of a git repo or a failing test to a repository

@prashantsssh
Copy link
Author

Hi @prashantsssh - It's hard to glean information off of images. Could you please upload in the form of a git repo or a failing test to a repository

@luke-hill I have updated my question with sample code so that you can reproduce it. Please have a look.

@luke-hill
Copy link
Contributor

I don't see anything failing in your code execution. Again if you could ideally show us in the form of a failing test or a git repo? It sounds like you are seeing something you're not expecting.

Could you also strip down as much redundant information as possible. see SSCCE.org for information

@luke-hill luke-hill added the 🍼 incomplete Blocked until more information is provided label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍼 incomplete Blocked until more information is provided
Projects
None yet
Development

No branches or pull requests

2 participants