Behavior Driven Development and Automation Testing Using Cucumber

31,136 views

Published on

Published in: Technology

Behavior Driven Development and Automation Testing Using Cucumber

  1. 1. BEHAVIOR-DRIVEN DEVELOPMENT (BDD) AND AUTOMATION TESTING WITH CUCUMBER November 2013 KMS Technology: http://kms-technology.com 1
  2. 2. SAMPLE REQUIREMENT Feature: login to the system. As a user, I want to login into the system when I provide username and password. Scenario: login successfully Given the login page is opening When I input username into the username textbox And I input valid password into the password textbox And I click Login button Then I am on the Home page 2
  3. 3. AUTOMATION TEST @Test public void fb_login_test() throws Exception { driver.get("https://www.facebook.com/"); driver.findElement(By.id("email")).clear(); driver.findElement(By.id("email")).sendKeys("bddtest@yahoo.com"); driver.findElement(By.id("pass")).clear(); driver.findElement(By.id("pass")).sendKeys("********"); driver.findElement(By.id("u_0_e")).click(); } 3
  4. 4. HOW? 4
  5. 5. AGENDA BDD and Agile Development Practice Automation Testing with Cucumber Developing Cucumber-Based Automation Framework BDD/Cucumber – Pros & Cons 5
  6. 6. HOW WE ENGAGE, WHY WE ARE YOUR BEST PARTNER…. Bright Minds, Brilliant Solutions 6 BDD & AGILE DEVELOPMENT PRACTICE
  7. 7. BEHAVIOR-DRIVEN DEVELOPMENT 7
  8. 8. GIVEN, WHEN, THEN 8
  9. 9. BDD AND AGILE DEVELOPMENT PRACTICE 9
  10. 10. HOW WE ENGAGE, WHY WE ARE YOUR BEST PARTNER…. Bright Minds, Brilliant Solutions 10 AUTOMATION TESTING WITH CUCUMBER
  11. 11. CUCUMBER APPROACH 11 Given /^I launch "([^"]*)" page$/ do |page| visit(page) End When /^I fill in "([^"]*)" with "([^"]*)"$/ do |field, value| fill_in field, :with => value end
  12. 12. SCENARIO EXAMPLE IN BDD FORMAT Feature: login to the system. As a user, I want to login into the system when I provide username and password. @tag_login_email Scenario Outline: Verify that can login gmail Given I launch "https://accounts.google.com" page When I fill in “Email " with “<Email >" And I fill in “Passwd" with "<Password> " And I click on "signIn" button Then I am on the “Home” page Scenarios: | Email | Password | | kms.admin@gmail.com | kms@2013 | | kms.user@gmail.com | kms@1234 | 12
  13. 13. HOW CUCUMBER EXECUTE A SCENARIO 13
  14. 14. SUMMARY 14
  15. 15. TESTING AREA Web application Web services • Desktop application – http://pragprog.com/book/idgtr/scripted-gui-testing-with-ruby • Mobile application – http://www.moncefbelyamani.com/ios-automated-testing-with-calabash-cucumber-ruby/ 15
  16. 16. CASE STUDY Complete 70% automation testing following agile process for a Healthcare Data Provider Client: – Health Market Science (HMS) Business Challenges: – 90% automation testing must be done for every 4- week sprint – Big Data Technology – Since MySQL, Oracle to NoSQL, Cassandra, Storm, Hadoop – Complicated test data creation 16
  17. 17. INSTALLATION • Ruby: – Windows: http://rubyinstaller.org/ – Linux: https://rvm.io/rvm/install • Cucumber: • gem install cucumber http://rubygems.org/gems/cucumber 17
  18. 18. DEMO • Web application: Cucumber + Capybara • Web Services: Cucumber + HTTParty + Savon 18
  19. 19. DEMO: WEB APPLICATION 19 Cucumber Capybara Selenium WebDriver Poltergeist phantomjs
  20. 20. 20 DEMO: WEB APPLICATION
  21. 21. 21 Navigating • (Object) visit(url) – The request method is always GET. – url (String) - The relative/absolute URL to navigate to. – Examples: • visit('http://google.com') DEMO: WEB APPLICATION
  22. 22. 22 Navigating Action • (Object) click_link(locator, options = {}) – Finds a link by id or text and clicks it. • (Object) click_button(locator, options = {}) – Finds a button by id, text or value and clicks it. • (Object) fill_in(locator, options = {}) – Locate a text field or text area. The field can be found via its name, id or label text. DEMO: WEB APPLICATION
  23. 23. 23 Navigating Action Check Point • (Boolean) has_content?(content) / • (Boolean) has_no_content?(content) – content (String) - The text to check for – Examples: • page.has_content?(‘hello’) • page.has_no_content?(‘hello’) DEMO: WEB APPLICATION
  24. 24. 24 Navigating Action Check Point • RSpec magic matchers – page.should have_selector('table tr') – page.should have_no_selector(:content) – page.should have_css('table tr.foo') – page.should have_content('foo') DEMO: WEB APPLICATION
  25. 25. DEMO: WEB APPLICATION
  26. 26. Regular ExpressionRegular Expression Regular Expression DEMO: WEB APPLICATION
  27. 27. HOW WE ENGAGE, WHY WE ARE YOUR BEST PARTNER…. Bright Minds, Brilliant Solutions 27 TAKE A REST
  28. 28. DEMO • Web Services: Cucumber + HTTParty + Savon 28
  29. 29. DEMO: WEB SERVICES 29 • At a glance: RESTful Web Service SOAP Web Service HTTParty/ RestClient /Json Savon Libs Cukes! GET/POST: Content: JSON {“data_id”:”1001”, “active”:”yes” “age”:”29”} GET/POST: Content: XML <SOAP:Env xlms… <data_id>1001</data_id> <active>yes</active> <age>29</age> </SOAP:Env>
  30. 30. DEMO: WEB SERVICES HTTParty HTTParty.get 'http://myexample.com/newfeeds‘  Response.body={“id”:”100”,”Message”:”Hello”} HTTParty.post 'http://myexample.com/updateStatus', {:date => “Nov-11-2013”, :status => “Full of energy today”}  Response.body={“update”:”success”,”id”:”425”} HTTParty.put 'http://myexample.com/status/message’, {:timeout => 5000}  Response.body={“success”:”true”,”message”:”me ssage_1377057406713”} HTTParty.delete 'http://myexample.com/status/message_13770574067 14‘ => Response.body={“success”:”false”,”reason”:”non- exist”} 30 JSON ActualRslt = JSON.parse(response.body) Msg1 = ActualRslt[“message”] #= “Hello” ActualRslt = JSON.parse(response.body) Msg1 = ActualRslt[“update”] #= “success” ActualRslt = JSON.parse(response.body) Msg1 = ActualRslt[“message”] #= “message_1377057406713” ActualRslt = JSON.parse(response.body) Msg1 = ActualRslt[“success”] #= “false” Msg1 = ActualRslt[“reason”] #= “non-exist”
  31. 31. DEMO: WEB SERVICES Savon # create a client for the service client = Savon.client(wsdl: 'http://service.example.com?wsdl') client.operations => [:find_user, :list_users] # call the 'findUser' operation response = client.call(:find_user, message: { id: 42 }) 31 actualRes = response.xml <?xml version="1.0" encoding="utf- 8"?><soap:Envelope....XMLSchema"> <soap:Body><findUserResponse xmlns="http://service.example.com"> <findUserResult><Success>true</Success> <LastName>Smith</LastName> <FirstName>John</FirstName> <City>Mountain View</City> <State>CA</State><WeatherID> </findUserResult></findUserResponse> </soap:Body></soap:Envelope>
  32. 32. DEMO: WEB SERVICES Feature: Get Weather status to display on webpage As an owner of Traveling Service, I want to be able to get weather status of any location based on address of client's request Scenario Outline: Get weather status by address of client's requests Given The check IP location and weather web services are running When I send request to get location detail of address "<Address>" Then I should have ZIP code and "<Country>" of that location And I send request to get weather status of that location by its ZIP code Then I should receive current "Temperature, Wind, RelativeHumidity" and "<City_Name>" and "<State>" of that location Scenarios: |Address |Country |City_Name |State | |www.google.com |United States |Mountain View |California | 32
  33. 33. HOW WE ENGAGE, WHY WE ARE YOUR BEST PARTNER…. Bright Minds, Brilliant Solutions 33 DEVELOPING CUCUMBER-BASED AUTOMATION FRAMEWORK
  34. 34. DEVELOPING CUCUMBER-BASED AUTOMATION FRAMEWORK 34 Web Service UIDatabase Step Library & Object Definition Environment Configuration Web driver (IE,CH,FF) Cassandra MySQL Oracle RESTful WS SOAP WS Test Data Repo. Reports /Logs CORE LAYER Feature Repository Test Execution Tester A Tester B Tester C Tester D TRANSLATION LAYER DESCRIPTION LAYER Web Apps OCI8, Cassandra HTTParty Savon, JSON Openssl Capybara Xmlparser ……….
  35. 35. DEVELOPING CUCUMBER-BASED AUTOMATION FRAMEWORK 35 Web Service UIDatabase Step Library & Object Definition Environment Configuration Web driver (IE,CH,FF) Cassandra MySQL Oracle RESTful WS SOAP WS Test Data Repo. Reports /Logs CORE LAYER Feature Repository Test Execution Tester A Tester B Tester C Tester D TRANSLATION LAYER DESCRIPTION LAYER Web Apps OCI8, Cassandra HTTParty Savon, JSON Openssl Capybara Xmlparser ……….
  36. 36. DEVELOPING CUCUMBER-BASED AUTOMATION FRAMEWORK 36 Web Service UIDatabase Step Library & Object Definition Environment Configuration Web driver (IE,CH,FF) Cassandra MySQL Oracle RESTful WS SOAP WS Test Data Repo. Reports /Logs CORE LAYER Feature Repository Test Execution Tester A Tester B Tester C Tester D TRANSLATION LAYER DESCRIPTION LAYER Web Apps OCI8, Cassandra HTTParty Savon, JSON Openssl Capybara Xmlparser ……….
  37. 37. DEVELOPING CUCUMBER-BASED AUTOMATION FRAMEWORK 37 Web Service UIDatabase Step Library & Object Definition Environment Configuration Web driver (IE,CH,FF) Cassandra MySQL Oracle RESTful WS SOAP WS Test Data Repo. Reports /Logs CORE LAYER Feature Repository Test Execution Tester A Tester B Tester C Tester D TRANSLATION LAYER DESCRIPTION LAYER Web Apps OCI8, Cassandra HTTParty Savon, JSON Openssl Capybara Xmlparser ……….
  38. 38. DEVELOPING CUCUMBER-BASED AUTOMATION FRAMEWORK 38 Web Service UIDatabase Step Library & Object Definition Environment Configuration Web driver (IE,CH,FF) Cassandra MySQL Oracle RESTful WS SOAP WS Test Data Repo. Reports /Logs CORE LAYER Feature Repository Test Execution Tester A Tester B Tester C Tester D TRANSLATION LAYER DESCRIPTION LAYER Web Apps OCI8, Cassandra HTTParty Savon, JSON Openssl Capybara Xmlparser ……….
  39. 39. 39 DEVELOPING CUCUMBER-BASED AUTOMATION FRAMEWORK A Hybrid Test Automation Framework Keyword-Driven Test Library Architecture Functional Decomposition Data-Driven Object Action Argument Login.txt_usr set myname Login.txt_pwd set mypass Login.btn_sign click Framework Method
  40. 40. HOW WE ENGAGE, WHY WE ARE YOUR BEST PARTNER…. Bright Minds, Brilliant Solutions 40 BDD/CUCUMBER – PROS & CONS
  41. 41. 41 BDD/CUCUMBER - PROS  BBD is FRIENDLY and UNDERSTANDABLE by non- technical User  Great support from RUBY community - Automation framework based BDD Cucumber is NOT REALLY HARD to develop and maintenance  Support on MULTIPLE PLATFORM, OS and different browsers
  42. 42. 42 BDD/CUCUMBER - CONS  Incompatibility among GEM versions  Lacking of tool for managing Features and Scenarios effectively
  43. 43. ARE YOUR BEST PARTNER…. Bright Minds, Brilliant Solutions 43 Q&A
  44. 44. © 2013 KMS Technology THANK YOU 44
  45. 45. REFERENCES 45 • All about BDD Cucumber: http://cukes.info/ • BDD cucumber book: http://www.amazon.com/The-Cucumber- Book-Behaviour-Driven-Development/dp/1934356808 • Ruby gems: http://rubygems.org • Ruby programming: http://www.ruby-lang.org

×