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

BDD and SauceLabs Integration: PHP and Ruby

BDD and SauceLabs Integration: PHP and Ruby

Originally: "Still Testing Your Software with Computers?" Presented at the DC Selenium and DCAST Meetups. Discusses BDD cross browser testing with integration to SauceLabs.

Jason Fox

May 22, 2013
Tweet

More Decks by Jason Fox

Other Decks in Programming

Transcript

  1. Still Testing Your Software with Computers? Using Sauce Labs to

    Automate Cross Browser Testing. Thursday, July 18, 13
  2. Features: ✓ Web 3.0 Javascript Hotness! ✓ Responsive Lean Super

    Duper! ✓ Ultra Cloud Social Scaling! Thursday, July 18, 13
  3. “Yes, but Kyle is using it.” “It has IE 9

    on it and I need IE 8.” Thursday, July 18, 13
  4. This is expensive. $ c c c c c c

    Å Å Å Thursday, July 18, 13
  5. We forget things. What do we have to do each

    time we test? Thursday, July 18, 13
  6. Given the business writes features in Gherkin, When we build

    the features, Then we can develop automated acceptance tests. Thursday, July 18, 13
  7. Given I’ve implemented automated acceptance tests, When I run them

    with Selenium, Then I should see the expected behavior in my local browser. Thursday, July 18, 13
  8. Universal browser support requires setup. Local in-browser testing is slow.

    Specific configurations are required. Thursday, July 18, 13
  9. Given I have configured my tests to run in a

    PhantomJS browser, Thursday, July 18, 13
  10. Given I have configured my tests to run in a

    PhantomJS browser, When I run the tests, Thursday, July 18, 13
  11. Given I have configured my tests to run in a

    PhantomJS browser, When I run the tests, Then they should execute significantly faster. Thursday, July 18, 13
  12. PhantomJS remains a webkit browser. We are getting there... Not

    all browsers covered! Thursday, July 18, 13
  13. In order to learn about the worlds buildings, As an

    architecture geek, User Story #1: Thursday, July 18, 13
  14. In order to learn about the worlds buildings, As an

    architecture geek, I want to view basic building dimensions. User Story #1: Thursday, July 18, 13
  15. #dimensions.feature Feature:  Show  a  building's  dimensions  to  the  user  

     In  order  to  learn  about  the  worlds  buildings    As  an  architecture  geek    I  want  to  view  basic  building  dimensions    Scenario:  I  can  see  available  buildings        Given  I  am  on  homepage        Then  I  should  see  "Freedom  Tower"        And  I  should  see  "Burj  Khalifa"    Scenario:  I  can  view  a  building's  top  floor        Given  I  am  on  homepage        And  I  follow  "Freedom  Tower"        Then  I  should  see  "Freedom  Tower"        And  I  should  not  see  "Burj  Khalifa"        And  I  should  see  "Top  Floor:  1268  ft" Thursday, July 18, 13
  16. /**  *  Features  context.  */ class  FeatureContext  extends  MinkContext {

           /**          *  Initializes  context.          *  Every  scenario  gets  it's  own  context  object.          *          *  @param  array  $parameters  context  parameters  (set  them  up  through   behat.yml)          */        public  function  __construct(array  $parameters)        {                $this-­‐>parameters  =  $parameters;        } } Thursday, July 18, 13
  17. sauce:    filters:        #This  is  only  running

     specific  features  for  the   purposes  of  the  demo        tags:  "@demo1"    extensions:        Behat\MinkExtension\Extension:            selenium2:                wd_host:  username:[email protected]/ wd/hub                capabilities:  {  "browser":  "googlechrome",   "platform":  "OS  X  10.6",  "name":  "Behat  PHP  Demo"  } Thursday, July 18, 13
  18. In order to understand the dimensions of a building, As

    metric system user, User Story #2: Thursday, July 18, 13
  19. In order to understand the dimensions of a building, As

    metric system user, I want to toggle between dimension systems. User Story #2: Thursday, July 18, 13
  20. #metric.feature Feature:  Toggle  between  standard  and  metric  system    In

     order  to  understand  the  dimensions  of  a  building    As  a  metric  system  user    I  want  to  toggle  between  dimension  systems    @demo2    Scenario:  There  is  a  toggle  button        Given  I  am  on  "/building/freedom-­‐tower"        Then  I  should  see  "Switch  to  Metric"    @demo2  @selenium    Scenario:  Clicking  on  the  toggle  button  will  switch  dimensions        Given  I  am  on  "/building/freedom-­‐tower"        When  I  follow  "Switch  to  Metric"        Then  I  should  see  "Top  Floor:  386.4864  m"        And  I  should  see  "Tip:  541.3248  m" Thursday, July 18, 13
  21. Then(/^I  should  see  "(.*?)"$/)  do  |text|    page.should  have_content(text) end

    Given(/^I  follow  "(.*?)"$/)  do  |link|    click_link(link) end Thursday, July 18, 13
  22. Capybara.default_driver  =  :poltergeist Capybara.app_host  =  'http://localhost:4567/' World(Capybara) Sauce.config  do  |c|

       c[:start_tunnel]  =  true    c.browsers  =  [        ["OS  X  10.6","CHROME","26"],        ["Windows  7","IE","7"],        ["Windows  7","Firefox","18"],        ["Windows  7","Opera","11"]    ] end Thursday, July 18, 13
  23. package  cucumber.examples.java.websockets; import  cucumber.api.java.en.Given; import  org.openqa.selenium.WebDriver; public  class  NavigationStepdefs  {

           private  final  WebDriver  webDriver;        public  NavigationStepdefs(SharedDriver  webDriver)  {                this.webDriver  =  webDriver;        }        @Given("^I  am  on  the  front  page$")        public  void  i_am_on_the_front_page()  {                webDriver.get("http://localhost:"  +  ServerHooks.PORT);        } } Thursday, July 18, 13