Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Writing effective tests in Behat

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →

Writing effective tests in Behat

Avatar for Iain Cambridge

Iain Cambridge

November 17, 2014

More Decks by Iain Cambridge

Other Decks in Technology

Transcript

  1. Given I have a product called “Nokia Phone” with url

    slug “nokia-phone” for the price of “10” Given I have a phone called “Samsung Phone” which is recommend for “Nokia Phone” When I open “/products” When I click link “.product:contains(‘Nokia Phone’)” Then I should see “Nokia Phone” in h2 class “product- title” Then I should see price of £12 Then I should see “Samsung Phone”
  2. Given I have a product called “Nokia Phone” with url

    slug “nokia-phone” for the price of “10”
  3. Given I have a product called “Nokia Phone” with url

    slug “nokia-phone” for the price of “10” Given the following products exist: | Title | Price | Url Slug | | Nokia Phone | 10 | nokia-phone |
  4. Given I have a phone called “Samsung Phone” which is

    recommend for “Nokia Phone” Given the following products exist: | Title | Price | Url Slug | | Nokia Phone | 10 | nokia-phone | | Samsung Phone | 10 | samsung-phone | And “Samsung Phone” is recommended for “Nokia Phone”
  5. Then I should see “Nokia Phone” in h2 class “product-title”

    Then I should see the product title as “Nokia Phone”
  6. Then I should see price of £12 Then I should

    see a price that includes VAT of £12
  7. Given I have a product called “Nokia Phone” with url

    slug “nokia-phone” for the price of “10” Given I have a phone called “Samsung Phone” which is recommend for “Nokia Phone” When I open “/products” When I click link “.product:contains(‘Nokia Phone’)” Then I should see “Nokia Phone” in h2 class “product- title” Then I should see price of £12 Then I should see “Samsung Phone”
  8. Given the following products exist: | Title | Price |

    Url Slug | | Nokia Phone | 10 | nokia-phone | | Samsung Phone | 10 | samsung-phone | And “Samsung Phone” is recommended for “Nokia Phone” When I open the product listing page And I go to the product page for “Nokia Phone” Then I should see the product title as “Nokia Phone” And I should see a price that includes VAT of £12 And I should be recommended “Samsung Phone”
  9. Given the following products exist: | Title | Price |

    Url Slug | | Nokia Phone | 10 | nokia-phone | | Samsung Phone | 10 | samsung-phone | And “Samsung Phone” is recommended for “Nokia Phone” When I open the product listing page And I go to the product page for “Nokia Phone” Then I should see the product title as “Nokia Phone” And I should see a price that includes VAT of £12 And I should be recommended “Samsung Phone”
  10. Given the following products exist: | Title | Price |

    Url Slug | | Nokia Phone | 10 | nokia-phone | When I open the product listing page And I go to the product page for “Nokia Phone” Then I should see the product title as “Nokia Phone” And I should see a price that includes VAT of £12
  11. Given the following products exist: | Title | Price |

    Url Slug | | Nokia Phone | 10 | nokia-phone | When I open the product listing page And I go to the product page for “Nokia Phone” Then I should see the product title as “Nokia Phone” And I should see a price that includes VAT of £12
  12. Given the following products exist: | Title | Price |

    Url Slug | | Nokia Phone | 10 | nokia-phone | When I go to the product page for “Nokia Phone” Then I should see the product title as “Nokia Phone” And I should see a price that includes VAT of £12
  13. Given the following products exist: | Title | Price |

    Url Slug | | Nokia Phone | 10 | nokia-phone | When I go to the product page for “Nokia Phone” Then I should see the product title as “Nokia Phone” And I should see a price that includes VAT of £12
  14. Given the following products exist: | Title | Price |

    Url Slug | | Nokia Phone | 10 | nokia-phone | When I go to the product page for “Nokia Phone” Then I should see the product title as “Nokia Phone”
  15. Given the following products exist: | Title | Price |

    Url Slug | | Nokia Phone | 10 | nokia-phone | When I go to the product page for “Nokia Phone” Then I should see the product title as “Nokia Phone”
  16. Given the following products exist: | Title | Price |

    Url Slug | | Nokia Phone | 10 | nokia-phone | When I go to the product page for “Nokia Phone” Then I should see the product information for “Nokia Phone”
  17. <?php namespace Page; use SensioLabs\Behat\PageObjectExtension \PageObject\Page; class Login extends Page

    { public function enterUsername($username) { $this->fillField(‘username’, $username); } }
  18. <?php // … class Login extends Page { protected $elements

    = [ ‘Login Button’ => [ ‘css’ => ‘.submit’], ]; }
  19. <?php // … class Login extends Page { //… public

    function pressButton() { $field = $this->getElement(‘Login Button’); $field->click(); } }
  20. <?php // … class LoginContext extends PageObjectContext { /** *

    @Given I am on the login page */ public function iAmOnTheLoginPage() { $loginPage = $this->getPage(‘login’); $loginPage->open(); } }