Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

QA Fest 2014. Анна Гаврилюк. Cool as сucumber

835 views

Published on

Что такое Gherkin? Как всё это работает, например с Cucumber-jvm? Какие обычные и специфичные features реализует фреймворк? Каковы best practices его использования? Когда вообще все это стоит применять?
Данный доклад интересен для тех кто желает ознакомится с BDD и вышеназванным фреймворком. Много практических примеров и несколько советов по использованию.

Published in: Technology
  • Be the first to comment

QA Fest 2014. Анна Гаврилюк. Cool as сucumber

  1. 1. COOL AS A CUCUMBER QA FEST 2014
  2. 2. 04.11.2014 / 2 Gherkin COBOL (COmmon Business-Oriented Language)
  3. 3. WHAT IS IT? 04.11.2014 / 3
  4. 4. Gherkin 04.11.2014 / 4 Feature: Short summary title As a common user I want to be able to do something So that I have a profit Scenario: Particular case Given some precondition And some other precondition When some action is done by user And some other action And yet another action Then some testable outcome is achieved And something else we can check happens too Prepare Act Assert
  5. 5. Step Definitions & Runners 04.11.2014 / 5 package myprecious.tests.cucumber.steps; public class CertainSteps { @Given("^some precondition$") public void step_definition() { ... //My code here } @When("^some action is done by user$") public void some_action_is_done { ... //Some Selenium here } ... package myprecious.tests.cucumber.runners; @RunWith(Cucumber.class) @Cucumber.Options( tags = {"~@skipped", "~@inProgress", "~@current"}, strict = true, format = { "json:target/cukes.json"}, monochrome = true, glue = {"myprecious.tests.cucumber.steps", " myprecious.tests.cucumber.hooks"}) public class LetTehTestsOut { } regular expressions only informative role locations for test parts “features” is separate one @runMe ~@dontRunMe reporting options @tag Scenario: Particular case Given some precondition
  6. 6. WHAT CAN A SCENARIO DO? 04.11.2014 / 6
  7. 7. Hooks 04.11.2014 / 7 Feature: Payment operations @ui Scenario: Make payment using current card Given I have logged And I have selected card ... @service Scenario: Get internal payment info Given I have submitted payment : ... public class TaggedHooks { @Before("@ui") public void startUpUi() { //open browser ... } @After("@ui") public void clearUi(Scenario scenario) { if (scenario.getStatus().equals("failed")) { byte[] screenshot = ((TakesScreenshot)driver). getScreenshotAs(OutputType.BYTES); scenario.embed(screenshot, "image/png"); } OR (“@ui, @service”) AND ({“@ui”, “@service”}) only scenario status if few, executed in backward order ~ works here too
  8. 8. Feature: Card operations Scenario: Change PIN successfully Given I am on account main page And I select my card from list And I enter the correct PIN When I change the PIN to 9876 Then the system should know my new PIN is 9876 Scenario: Transaction list Given I am on account main page And I select my card from list And I enter the correct PIN And card was used at least once When I click info panel Then list of transactions is shown Scenario: Print card information Given I am on account main page And I select my card from list And I enter the correct PIN When I click print button Then page with card information is shown And it contains card account number Background 04.11.2014 / 8 Feature: Card operations Background: User selected a card Given I am on account main page And I select my card from list And I enter the correct PIN Scenario: Change PIN successfully When I change the PIN to 9876 Then the system should know my new PIN is 9876 Scenario: Transaction list Given card was used at least once When I click info panel Then list of transactions is shown Scenario: Print card information When I click print button Then page with card information is shown And it contains card account number
  9. 9. Examples 04.11.2014 / 9 Feature: User registration Scenario: Tooltips for email registration Given I am on quick registration form When I fill "Email" field with "" And I click somewhere else Then I should see error message "Email cannot be blank" When I fill "email" field with "darth.vader" And I click somewhere else Then I should see error message "Please input valid Email address" When I fill "email" field with "admin@domain.com" And I click somewhere else Then I should see error message "Email has already been taken" When I fill "password" field with "" And I click somewhere else Then I should see error message "Password cannot be blank" When I fill "password" field with "asdf" And I click somewhere else Then I should see error message "Password is too short" Feature: User registration Scenario Outline: Tooltips for email registration Given I am on quick registration form When I fill "<field_name>" field with "<value>" And I click somewhere else Then I should see error tooltip "<error_message>" Examples: | field_name | value | error_message | | Email | | Email cannot be blank | | Email | luke.skywalker | Please input valid Email address | | Email | admin@domain.com | Email has already been taken | | Password | | Password cannot be blank | | Password | asdf | Password is too short |
  10. 10. WHAT CAN A STEP DEFINITION DO? 04.11.2014 / 10
  11. 11. Usual variables 04.11.2014 / 11 When I select 28 as a "delivery date" @When("^I select (d+) as a "(.+)"$") public void stepDefA(int number, String controlName){ Given months "September,July,March" are checked @Given("^months "(.+)" are checked$") public void stepDefB(List<String> monthNames){ Given delivery date is “28-02-2014" @Given("^delivery date is "(d{2}-d{2}-d{4})"$") public void stepDefC(@Format("dd-MM-yyyy") Date today) { Then payment is updated in DB2 database @Then("^payment is updated in (DB2|Oracle) database$") public void stepDefD(String dbName){ Then error dialog is shown again @When("^error dialog is shown(?: again)?$") public void stepDefE(){
  12. 12. Multiline text 04.11.2014 / 12 Then informational message is shown: """ Welcome to the Cosa Nostra card activation system. ======= If you would like us to take care of these losers before they cause you any trouble, please proceed to payment card information menu. """ Given I have a user account "Test Testersen" When it is granted <Role> rights And I submit a support request Then I should receieve an email: """ Dear T. Testersen, Unfortunately all our specialists are busy. Please <Action> <Person> in order to get further help with Your issue. Thank You for using our service. """ Examples: | Role | Action | Person | | customer | call | customer support team | | customer support | email | service operations team | | service operations | brace | yourself | @Then("^informational message is shown:$") public void info_message_shown(String messageText) {
  13. 13. Data tables 04.11.2014 / 13 Given following accounts already exist in DB: | debitorName | debtorAddress1 | debtorPostCd | updateDate | | "Anakin Skywalker" | "Sand str 8, 2" | "Tatooine" | <current> +1d | | "R2D2" | "MISTY JUNGLE 1" | "DAGOBAH" | <current> -1d | | "Qui-Gon Jinn" | "Shrine, apt. 63" | "Yavin 4" | <current> -3d | | "Padme Amidala" | "Theed Royal Palace" | "Naboo" | <current> -3d | | "Luke Skywalker" | "Misty Jungle 1" | "Dagobah" | <current> -1d | | "Lando Calrissian" | "Building 2A, room 45" | "Bespin" | <current> -1d | | "Han Solo" | "Deck 06A, 12" | "Hoth" | <current> +3d | | "Leia Organa" | "Laser str. 13" | "Alderaan" | <current> -1d | @Then("^following accounts already exist in DB:$") public void stepDefA(DataTable accounts) { @Then("^following accounts already exist in DB:$") public void stepDefB(List<Map<String>> accounts) { @Then("^following accounts already exist in DB:$") public void stepDefC(List<AccountClass> accounts) { @Then("^following accounts already exist in DB:$") public void stepDefD(List<List<String>> accounts) {
  14. 14. HOW CAN WE MAKE IT BETTER? 04.11.2014 / 14
  15. 15. Integrate 04.11.2014 / 15 Maven failsafe plugin to launch the tests. Test reports passed in json to Jenkins Cucumber report plugin.
  16. 16. Use the power 04.11.2014 / 16 Backgrounds, examples, regexps … Given I am on the advanced search page And I select "Endocrinology" from "Specialty" And I choose "Yes" within "Accepts Insurance" And I fill in "ZIP Code" with "90010" And I select "5 miles" from "Search Radius" When I press "Search" When I search for a provider with the criteria: | Provider Type | Doctor | | Specialty | Endocrinology | | Accepts Insurance | Yes | | ZIP | 90010 | | Search Radius | 5 miles | When I search for a provider with the default criteria and: | Specialty | Endocrinology | | Accepts Insurance | No | ... When I search for a provider with the default criteria Then the search criteria should include: | Provider Type | Doctor | | Specialty | General | | Accepts Insurance | Yes | | ZIP | 90010 | | Search Radius | 5 miles |
  17. 17. Use the power … of regexps? 04.11.2014 / 17 When I use email (?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:.[a-z0- 9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[x01-x08x0bx0cx0e-x1fx21x23-x5bx5d-x7f]|[x01- x09x0bx0cx0e-x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0- 9](?:[a-z0-9-]*[a-z0-9])?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0- 9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0- 9]:(?:[x01-x08x0bx0cx0e-x1fx21-x5ax53-x7f]|[x01-x09x0bx0cx0e-x7f])+)]) When I am logged in ... When I am logged in as "Joda" @Then("^I am logged in$") .* Anything or nothing .+ Something d* none or more digits d+ some digits "[^"]*" Something in quotes an? Something optional ... @When("^(?:I am logged|I log) in as an? "([^"]*)"$") @Then("^(?:receipt has )?following payment (?:information|info) :$")
  18. 18. Choose your domain 04.11.2014 / 18 Scenario: User with valid credentials Given an unauthenticated user When the user tries to navigate to the welcome page Then they should be redirected to the login page When the user enters a valid name in the Name field And the user enters the corresponding password in the Password field And the user presses the Login button Then they should be directed to the welcome page • Security domain, user authentication • Password based authentication domain • UI widgets domain • Domain of web assets Scenario: User with valid credentials Given an unauthenticated user When the user tries to access a restricted asset Then they should be directed to a login page When the user submits valid credentials Then they should be redirected back to the restricted content • “WHAT”  User authentication domain • “HOW” Web based security domain
  19. 19. Declarative vs. Imperative 04.11.2014 / 19 How exactly to do it ?What should be done? Scenario: Successful login Given a user "Smith" with password "qwerty" And I am on the login page And I fill in "User name" with "Smith" And I fill in "Password" with "qwerty" When I press "Log in" Then I should see "Welcome, Smith" Background: Scenario: Successful login Given a user "Smith" with password "qwerty" And I am on the login page And I fill in "User name" with "Smith" And I fill in "Password" with "qwerty" When I press "Log in" Then I should see "Welcome, Smith" Scenario: User is greeted upon login Given the user "Smith" has an account When he logs in Then he should see "Welcome, Smith" Background: The user is logged in Given a logged in user Feature: The System Scenario: Everything Works Given the system exists When I use it Then it should work, perfectly
  20. 20. WHEN DO WE NEED IT? 04.11.2014 / 20
  21. 21. 04.11.2014 / 21 Don’t use Cucumber unless you live in the magic kingdom of non-programmers-writing-tests (and send me a bottle of fairy dust if you’re there!) ~ David Heinemeier Hansson 1. Non-developers are involved too  Product owner  Test engineer ? Test automation engineer 2. Executable specification 3. BDD, TDD  Specification, not script  Abstract, declarative  Shared language  Key examples Collaboration tool Jira (Behave Plug-in), Cucumber Pro, Relish . . .  Developer
  22. 22. Useful links and sources Web • github.com/cucumber/cucumber-jvm • cukes.info/ – project page • dannorth.net/archives/ – creator of BDD • aslakhellesoy.com/ – framework creator • agileforall.com/blog/ – usage examples • cucumber.pro/ – Cucumber Pro + blog Books • The Cucumber Book – Wynne M, Hellesøy A, 2012 04.11.2014 / 22
  23. 23. 04.11.2014 / 23 anna.gavriluk@iteraconsulting.com Skype: angavriluk
  24. 24. THANKS FOR TRYING TO STAY AWAKE

×