Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Story BDD with Behat

Story BDD with Behat

Saša Stamenković

November 12, 2015
Tweet

More Decks by Saša Stamenković

Other Decks in Programming

Transcript

  1. BDD

  2. ...with the focus on the behavior of the feature Developer

    Project manager Product owner Business analyst Tester
  3. StoryBDD helps ensuring that development team has understanding of business

    on the same level that client does. And even leveling up clients knowledge of his own business.
  4. Feature: News admin panel In order to maintain a list

    of news As a site administrator I need to be able to edit news
  5. Feature: News admin panel In order to maintain a list

    of news As a site administrator I need to be able to edit news custom title
  6. Feature: News admin panel In order to maintain a list

    of news As a site administrator I need to be able to edit news business value
  7. Feature: News admin panel In order to maintain a list

    of news As a site administrator I need to be able to edit news who benefits
  8. Feature: News admin panel In order to maintain a list

    of news As a site administrator I need to be able to edit news feature desc.
  9. Scenario: Add new article Given I am on the "/admin/news"

    page When I click "New Article" And I fill in "Title" with "Learn BDD" And I press "Save" Then I should see "A new article was added"
  10. Scenario: Add new article Given I am on the "/admin/news"

    page When I click "New Article" And I fill in "Title" with "Learn BDD" And I press "Save" Then I should see "A new article was added" scenario title
  11. Scenario: Add new article Given I am on the "/admin/news"

    page When I click "New Article" And I fill in "Title" with "Learn BDD" And I press "Save" Then I should see "A new article was added" initial state
  12. Scenario: Add new article Given I am on the "/admin/news"

    page When I click "New Article" And I fill in "Title" with "Learn BDD" And I press "Save" Then I should see "A new article was added" taking action
  13. Scenario: Add new article Given I am on the "/admin/news"

    page When I click "New Article" And I fill in "Title" with "Learn BDD" And I press "Save" Then I should see "A new article was added" can be added to create multiple...
  14. Scenario: Add new article Given I am on the "/admin/news"

    page When I click "New Article" And I fill in "Title" with "Learn BDD" And I press "Save" Then I should see "A new article was added" ...Given/When/Then
  15. Scenario: Add new article Given I am on the "/admin/news"

    page When I click "New Article" And I fill in "Title" with "Learn BDD" And I press "Save" Then I should see "A new article was added" asserting state of the system
  16. $ php bin/behat --init +d features - place your *.feature

    files here +d features/bootstrap - place your context classes here +f features/bootstrap/FeatureContext.php - place your definitions, transformations and hooks here Initialization
  17. Feature: ls In order to see the directory structure As

    a UNIX user I need to be able to list directory's contents features/ls.feature
  18. Scenario: List 2 files in a directory Given I have

    a file named "foo" And I have a file named "bar" When I run "ls" Then I should see "foo" in the output And I should see "bar" in the output features/ls.feature
  19. Using Mink use Behat\Mink\Session; use Behat\Mink\Driver\GoutteDriver; $session = new Session(new

    GoutteDriver()); $session->visit($startUrl); $session->getPage()->findLink('Downloads')->click(); echo 'Status: '.$session->getPage()->getStatusCode(); echo 'Content: '.$session->getPage()->getContent();
  20. Mink inside FeatureContext use Behat\MinkExtension\Context\RawMinkContext; class FeatureContext extends RawMinkContext {

    public function doSomething() { $this->getSession() ->visit('https://github.com/') ; } }
  21. FeatureContext extends MinkContext use Behat\MinkExtension\Context\MinkContext; class FeatureContext extends MinkContext {

    public function doSomething() { $this->visit('/foo'); $this->selectOption('Country', 'Germany'); $this->pressButton('Save'); $this->assertPageContainsText('Country changed.'); } }
  22. After adding MinkContext $ ./bin/behat -dl default | Given /^(?:|I

    )am on "(?P<page>[^"]+)"$/ default | When /^(?:|I )reload the page$/ default | When /^(?:|I )move backward one page$/ default | When /^(?:|I )move forward one page$/ default | When /^(?:|I )press "(?P<button>(?:[^"]|\\")*)"$/ default | When /^(?:|I )follow "(?P<link>(?:[^"]|\\")*)"$/ default | Then /^(?:|I )should be on "(?P<page>[^"]+)"$/ default | Then /^(?:|I )should see "(?P<text>(?:[^"]|\\")*)"$/ ...
  23. Feature: Search In order to find articles As a website

    visitor I need to be able to search for articles features/search.feature
  24. Scenario: Searching for an article that exists Given I am

    on the homepage When I fill in "search" with "BDD" And I press "go" And I follow "Behavior-driven development" Then I should see "History" And I should see "Principles of BDD" And I should see "Story versus specification" features/search.feature
  25. Scenario: Finishing my talk Given I am done with talking

    When I ask "Are there any questions?" Then I should see your hands in the air