Search code examples
rubycucumberbdd

Use Return On Cucumber


  1. There are various ways to skip a Scenario in Cucumber. Fail a scenario, @Ignore etc. But I am looking for an elegant but Consolidated way. I do not want to scan hundreds or thousands of lines of scenarios/step definitions to tag them or Modify them.

    I want to create a listing like a Array/hashmap and do just a Skip. Can we not use something like a Return statement to gracefully exit a Scenario. Also I want to ensure the Logs don't reflect as the Step actually started - ie if we skip a test in 100, result should only count for 99 pass or fail...

    My Idea is to have a common method invocation in a Given step where the return / skip can happen. I can also read off an excel and do same.

  2. Why do people consider not using an Excel in BDD Cucumber automation. Nobody is explaining me right reason. They say everything can be kept in a script file. But thats not the reason why they should Avoid it.


Solution

  • If you don't want to use tags to ignore a particular scenario, then add a Given step that pends it ex:

    In your feature file in the first step of a scenario:

    Given PENDING: The reason why you dont want to run the test
    ...
    

    Your step def file:

    Given(/^PENDING: (?:.*)$/) do
      pending
    end
    

    or

    Your feature file:

    @pend
    Given yada yada yada
    Then yada yada yada
    

    Your hook file:

    Before('@pend') do
      pending
    end
    

    Which will give you a count of pended/todo scenarios along with the ones that are run... Which is a good metric and better to have than not...

    Or just use the tag which IMO has nothing wrong with it, and I don't understand why wouldn't want to you use it...

    In your feature file:

    @ignore
    Given yada yada yada
    Then yada yada yada
    

    In your profile or execution:

    cucumber --tag ~@ignore
    

    Regarding your second question, it belongs to a second thread... But Excel with Cucumber just sounds wrong, and if you have a decent IQ you shouldn't have to question why it sounds wrong...