Question

In the below feature I am checking for the existence of a particular job type (contract) and do something if found otherwise skip the rest of the steps. When skippedm, mark the scenario as passed (technically its not a pass nor a fail or pending) How do I do it in cucumber or cucumber-jvm?

Feature: View job types
  Users can view job type from front page and from side menu

  Scenario Outline: View job type from front page

    Given I login as "<user>"
    And if there are contract jobs
    Then it should have a hourly rate
    And the daily rate in "USD" with "2" decimal places

    Examples:
    | user |
    | hello|
    | world|
Was it helpful?

Solution

The dirty way: In step 'if there are contract jobs'

@jobs = false
@jobs = true If contract_jobs

Then in your following steps, say 'it should have a hourly rate'

if @jobs
 <your other assertions>
else
 true
end

Just setting true in a step definition makes the step pass (in fact any non-assertive statement will work). Though I wouldn't recommend building up a scenario like this (Arguably, Scenarios with conditionals are not useful / cucumber style). Personally, I would split it into 2 - a positive scenario:

Given I login as "<user>"
Then there are contract jobs
And the job has an hourly rate
And the job has a daily rate in "USD" with "2" decimal places

and a negative scenario

Given I login as "<user>" (a profile for which you know there won't be contract jobs)
Then there are no contract jobs

OTHER TIPS

Take a look at cucumber 'hooks' https://github.com/cucumber/cucumber/wiki/Hooks

Also, to skip steps, albeit without conditionals (to my knowledge at least), you can use the @ignore tag in front of the cucumber step

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top