0

I try to find a way to skip scenarios in the FeatureContext.php. I got a test which i only will execute if a Condition is right, else der just will be skipped. My idea was to check the scenario with a tag like "@weeksale"

  @weeksale
  Scenario: test
    Given I go to "/"
    Then I should see "Unsere Leistungen"

And in my FeatureContext I got a Condition and if its false they just Skipped

 /**
 * @beforeScenario
 * @weeksale
 *
 * @param Behat\Behat\Event\ScenarioEvent $event
 */
public function weekSaleInTime($event)
{
    $dateUrl = $this->parameters['weekSaleDatePage'];
    $date = file_get_contents($dateUrl);

    $dateArray = explode("\r\n", $date);

    $result = $this->isCurrentDateBetween($dateArray[0], $dateArray[1]);

if($result == false)
{
  //behat skip this scenario
}

anyone an idea how i can tell behat to skip a Scenario?

(behat v2.5.5)

Fanor
  • 53
  • 2
  • 8

2 Answers2

1

Thats a job for your Continuous Integration tool to do.

Create a new path in your behat.yml file like this:

event:
 filters:
    tags: '~@event'
 paths:
      features:  features
      bootstrap: %behat.paths.features%/bootstrap

 extensions:
    Behat\MinkExtension\Extension:
        base_url: http://<YOUR URL HERE>
        javascript_session: selenium2
        browser_name: <BROWSER>
        selenium2:
           browser: "<BROWSER>"
           wd_host: "http://127.0.0.1:9515/wd/hub"
        goutte: ~
 formatter:
    name:               pretty,html,junit
    parameters:
        output_path:    ,../ci/published/report.html,../ci/published

If you include a script within a continuous integration tool that will choose which one to run, you should be on your way.

If you are running tests within those dates manually, change "events" to "default", and it will run as usual, while removing all scenarios marked with "@event".

KyleFairns
  • 2,947
  • 1
  • 15
  • 35
  • Yes thats a bit like we did it. I got a build.xml for Jenkins CI which there is a php file executed which execute the shell command. With the date condition i just append at the commend --tags ~@weeksale to exclude all behat test with this tag. Thanks for your Answer – Fanor Feb 05 '16 at 16:19
0

Above your Scenario, simply add a tag say @weeksale in your example

when executing your scenario run the command behat --tags '~@weeksale'

The ~ (negate) doesnt run the particular tagged scenario.

Avni
  • 1
  • 2