ruby - Get current Step form Scenario outline -
i trying access current step name in scenario outline test. code below works regular scenarios fails scenario outlines.
afterstep |scenario| #step = scenario.steps.find { |s| s.status == :skipped } #puts step.keyword + step.name case scenario when cucumber::ast::scenario step = scenario.steps.find { |s| s.status == :skipped } puts step.keyword + ' ' + step.name #works correctly when cucumber::ast::outlinetable::examplerow # **!!!!exception below!!!** step = scenario.scenario_outline.steps.find { |s| s.status == :skipped } puts step.keyword + ' ' + step.name end end exception:
nomethoderror: undefined method `steps' #<cucumber::ast::outlinetable::examplerow:0x007fe0b8214bc0> does know how resolve this? or if possible?
try following way:
before |scenario| ... # step counter @step_count = 0 end afterstep |step| current_feature = if scenario.respond_to?('scenario_outline') # execute following code scenarios outline (starting second example) scenario.scenario_outline.feature else # execute following code scenario , scenario outline (the first example only) scenario.feature end # call method 'steps' , select current step # use .send because method 'steps' private scenario outline step_title = current_feature.feature_elements[0].send(:steps).to_a[@step_count].name p step_title # increase step counter @step_count += 1 end it has work fine both 'scenario' , 'scenario outline'
Comments
Post a Comment