1.3k likes | 3.02k Views
Integrating Cucumber with Selenium. Puscasu Dragos 13.02.2014. There is an A for everything. What is Cucumber What is BDD. Best Practices. Cucumber Feature Integration with Selenium. Examples. Behaviour-Driven Development – BDD.
E N D
Integrating Cucumber with Selenium Puscasu Dragos 13.02.2014
There is an A for everything • What is Cucumber • What is BDD • Best Practices • Cucumber Feature • Integration with Selenium • Examples
Behaviour-Driven Development – BDD • Software development process based on test-driven development (TDD) • Evolved out of established agile practices • Brings focus through concept of business value • What’s the next most important thing the system doesn’t do? • Consistent vocabulary - eliminating some of the ambiguity and miscommunication that occur when technical people talk to business people • Everyone speaks the same LANGUAGE • Story template : • As a [X= person or role that will benefit] I want [Y= some feature] so that [Z= benefit or value of the feature]
Cucumber – Language:Gherkin • Feature: Some descriptive text of what is desired • In order to realize a named business value • As an explicit system actor • I want to gain some beneficial outcome which furthers the goal • Scenario: Some determinable business situation • Given some precondition • When some action by the actor • Then some testable outcome is achieved • And something else we can check happens too
Cucumber – Features • “Feature: … ” – start feature, provide title • “In order to… As a… I want to…” – provide context to readers, not parsed in order to match a definition • “Scenario: … ” – start scenario, provide scenario description • Given/When/Then/And/But – steps of the scenarios, matched by a regular expression (defined elsewhere) • Feature file (*.feature) – consists of one feature • A feature • Every ”sentence” is considered as a step which needs to be implemented • Contains a list of scenarios • May contain “Scenario outline” • May contain “Background”
Cucumber – Features • “Scenario: …” keyword – optional title • A scenario has one ore more Steps • “Scenario Outline:…” - express through the use of a template with placeholders: • Scenario Outline: Eating • Given there are <start> cucumbers • When I eat <eat> cucumbers • Then I should have <left> cucumbers • Examples: • | start | eat | left | • | 12 | 5 | 7 | • | 20 | 5 | 15 | • Run once for each row in the Examples section - placeholders take the real value from the Examples: table row
Cucumber – Features • Add context to scenarios(Background) Feature: Access to a site Background: Given that I open the application in Internet Explorer And I am logged in And I have admin rights Scenario: Delete a music video from the application in Internet Explorer Given I go to video management screen When I delete video number 25 Then Video 25 is no longer displayed in the video management screen
Cucumber – Features public class StepDefinition{ @Given("^I have an instance of my class$") public void I_have_an_instance_of_my_class() { } @When("^I call my method with \"([^\"]*)\"$") public void I_call_my_method_with_(String arg1) { } @Then("^I receive \"([^\"]*)\"$") public void I_receive_(String arg1) { } }
Cucumber – Features • Tags - organize your features and scenarios: • @billing • Feature: Verify billing • @important • Scenario: Missing product description • Tags can be specified in @Cucumber.Options : • @Cucumber.Options ( • features = {“path_to_feature_files”}, • glue = {“path_to_step_definition_class”}, • tags = “@important”) / tags = “~@Smoke”)
Cucumber – Features • Cucumber Reports: • Junit • HTML • JSON
Integration with Selenium • <dependency> • <groupId>org.seleniumhq.selenium</groupId> • <artifactId>selenium-java</artifactId> • <version>2.39.0</version> • </dependency>
Best practices #1 Write declarative features
Best practices #2 • Insert a narrative • Feature: Some descriptive text of what is desired • In order to realize a named business value • As an explicit system actor • I want to gain some beneficial outcome which furthers the goal
Best practices #3 Reuse step definitions
Best practices #4 Avoid conjunctive steps
Best practices #5 Use backgrounds wisely
Read more • Presentation • http://www.slideshare.net/bmabey/writing-software-not-code-with-cucumber?from_search=3 • http://www.slideshare.net/rapaul/acceptance-tests?utm_source=slideshow&utm_medium=ssemail&utm_campaign=download_notification • http://alkesh.github.io/iprug-cucumber-presentation/#1 • Article/Blog • http://dannorth.net/introducing-bdd/ • http://dannorth.net/2011/01/31/whose-domain-is-it-anyway/ • http://cukes.info/step-definitions.html • http://zsoltfabok.com/blog/2012/09/cucumber-jvm-web-with-spring-mvc/ • http://docs.behat.org/guides/1.gherkin.html
Thank You Puscasu Dragos Senior Software Tester