Presentation is loading. Please wait.

Presentation is loading. Please wait.

Behaviour Driven Development with Cucumber and selenium using Java.

Similar presentations


Presentation on theme: "Behaviour Driven Development with Cucumber and selenium using Java."— Presentation transcript:

1 Behaviour Driven Development with Cucumber and selenium using Java

2 BDD Domain Driven Design - DDD ● Common understanding ● Common language ● Test Driven Development - TDD ● Good technical practices ● Small steps ● Combined → Behaviour Driven Development

3 Test automation Test Driven Development, TDD – Develop it the right way Behaviour Driven Development, BDD – Develop the right thing

4 Three core principles Business and Technology should refer to the same system in the same way Any system should have an identified, verifiable value Up-front analysis, design and planning all have a diminishing return

5 Common language Used by all involved Customer Developers Others?

6 Verifiable value Protect revenue Increase revenue Manage cost Increase brand value Make the product remarkable Provide more value to your customer

7 Big design up-front No big design up-front The further you plan ahead, the less accurate you will be

8 Three questions What is the most important thing the system should do? What is the next most important thing the system doesn't do yet? If we were to switch off the system, where and what would be the biggest impact?

9 Time to create a specification

10 When are we done?

11 Interpret and translate We need to read the spec. Understand it Translate it into code Parse and execute it? No, not all specs are created equal

12 Solution Write specifications so  Translations isn't needed  It is possible to execute them

13 Format Given – Setup the system When – Change the state of the system Then – Verify the new state

14 Tools

15 Audience Readers  Customers  Developers Maintainers  Product owner  Developers

16 Why Cucumber  It is one of the least technical tools  It is a very active open source project  It supports a variety of languages

17 A concrete example Feature: Testing Accounts and Deposits for HDFC bank Scenario: Testing account and deposits for HDFC bank Given I go to hdfcbank url When I go to accounts and deposits Then I should see the account details |Savings Accounts|Salary Accounts|Current Accounts|Deposits|Demat Account|

18 Advantages The format is ● Easy to read ● Easy to understand ● Easy to discuss ● Easy to parse

19 Parse and execute ● A parser is developed ● Add native code to implement the steps Setup – Given Execute – When Assert - Then

20 Write a step definition in Java @Given("^I go to hdfcbank url$") public void i_go_to_hdfcbank_url() throws Throwable { } @When("^I go to accounts and deposits$") public void i_go_to_accounts_and_deposits() throws Throwable { } @Then("^I should see the account details$") public void i_should_see_the_account_details(DataTable arg1) throws Throwable { }

21 Write code to make the step pass public class AccAndDeposits { WebDriver driver; @Given("^I go to hdfcbank url$") public void i_go_to_hdfcbank_url() throws Throwable { driver = new FirefoxDriver(); driver.get("http://www.hdfcbank.com"); driver.manage().window().maximize(); } @When("^I go to accounts and deposits$") public void i_go_to_accounts_and_deposits() throws Throwable { driver.findElement(By.xpath("//div[@id='hometab1']/div[2]/h3[1]")).click(); } @Then("^I should see the account details$") public void i_should_see_the_account_details(List technologies) throws Throwable { WebElement accAndDepo = driver.findElement(By.className("accContent")); List allAccounts = accAndDepo.findElements(By.tagName("a")); for(int i=0;i<allAccounts.size();i++){ System.out.println(allAccounts.get(i).getText()); Assert.assertTrue(allAccounts.get(i).getText().equals(technologies.get(i)),technologies.get(i) +" not found"); }

22 Run it again and see the step pass

23 Why is Cucumber better ● Compared to well known tools like JUnit? ● It isn't, it's just easier to read for non coders ● The readability has increased ● Communication is easier

24 Benefits ● Less unnecessary work ● Better regression tests ● Less speculative work ● Less re-work

25 Maintenance  Maintained together ● Specs ● Tests ● Code  Maven  Continuous Integration, CI

26 Tips  Always use the a common language  Don't over specify – start easy  Never specify implementation details

27 Resources  Cucumber - http://cukes.info/  Selenium - http://seleniumhq.org/  Maven - http://maven.apache.org/  Jenkins - http://jenkins-ci.org/  Blog -http://thomassundberg.wordpress.com/

28 Thank You


Download ppt "Behaviour Driven Development with Cucumber and selenium using Java."

Similar presentations


Ads by Google