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

Dimitris Mitsis - Automated tests with CodeCeption - WordCamp Athens 2016

Dimitris Mitsis - Automated tests with CodeCeption - WordCamp Athens 2016

A717e9d055b2284e573b2412e32f5397?s=128

WordPress Greek Community

November 19, 2016
Tweet

Transcript

  1. #wcAth2016 Δημήτρης Μήτσης Αυτοματοποιημένα test με το CodeCeption

  2. Δημήτρης Μήτσης WPML DEVELOPMENT • QUALITY ASSURANCE • PERFORMANCE TESTING

  3. AUTOMATED TESTING • Use of special software to compare the

    actual output of an application with the one we expect
  4. Manual tests Integration tests Unit Tests

  5. NEEDS FOR AUTOMATED TESTING • Expedite procedure of quality control

    • Quick releases • Integration with WordPress • Integration with 3rd party plugins
  6. UNIT-TEST • TEST DRIVEN DEVELOPMENT (TDD) • PHPUnit Unit testing:

    tests if specific parts of the application output the expected result for a given input
  7. BENEFITS OF UNIT-TESTS • Enforce coding standards • Full awareness

    of the stack-trace Avoid phrases like: “Works but I don’t know why” White-box testing
  8. 2 UnitTests – 0 Integration tests

  9. • Avoid regressions (re-appearance of the same bug) • Ensure

    that existing functionality remains • Frequency of updates SIMPLE NEEDS FOR AUTOMATED TESTING
  10. UPDATES FOR WP SEO, WC & WP IN 2016

  11. BEST COFFEE OF YOUR WEEK

  12. CODECEPTION • Testing framework for PHP applications • Easy and

    simple to use • Modular and extensible • Promotes design patterns
  13. Unit Tester The geek! Knows the application inside- out Functional

    Tester The tester who understands the application but has access to the interface too Acceptance Tester The user which can only test what he sees in the screen CODECEPTION Black box testing Grey box testing White box testing Integration tests
  14. INSTALLATION OF CODECEPTION Requirements • Selenium Standalone • WordPress (website)

    (locally or in server) • Browser • Composer • Phar αρχείο (executable) Installation
  15. CODECEPTION – BOOTSTRAP $ wget http://codeception.com/codecept.phar $ php codecept.phar bootstrap

  16. None
  17. None
  18. None
  19. None
  20. None
  21. CODECEPTION – MANUAL TEST STEPS • Create a test product

    • View product in the front-end • Add product to cart • Continue with checkout
  22. CODECEPTION – GENERATE TEST $ php codecept.phar generate:cept acceptance WooCommerceBasic

    /tests/acceptance/WooCommerceBasicCept.php
  23. None
  24. EMPTY CEST $ codeception.com/docs/06-ModulesAndHelpers#hooks

  25. CODECEPTION – BOOTSTRAP

  26. CODECEPTION –

  27. CODECEPTION –

  28. CODECEPTION – $

  29. CODECEPTION –

  30. php codecept.phar run acceptance --steps java -jar selenium-standalone.jar

  31. CODECEPTION – LOCATORS • CSS ID  click(“#css-id”) • CSS

    CLASS  click(“.css-class”) • TEXT  click(“Text”) • xPath  click(“//div[@xpath]”) Firebug and FirePath are your friends
  32. CODECEPTION & SELENIUM IDE Two Firefox Add-ons • SeleniumIDE •

    CodeCeption Formatters
  33. CODECEPTION HELPERS tests/_support/ΑcceptanceTester.php

  34. CODECEPTION Remember to build after editing this file! php codecept.phar

    build
  35. CODECEPTION

  36. CODECEPTION – DESIGN PATTERNS Page Objects & Step Objects •

    Each PageObject emphasizes only on one page and its elements. • Each StepObject emphasizes on similar recurring steps
  37. CODECEPTION – PAGE OBJECTS • Locators are defined • Common

    steps associated to one page are also defined in the PageObejct • They make tests easier to read
  38. CODECEPTION php codecept.phar generate:pageobject EditProductPage

  39. CODECEPTION

  40. CODECEPTION

  41. Q & A

  42. THAT’S IT! HAPPY TESTING  TINYURL.COM/

  43. CODECEPTION – LINKS

  44. CODECEPTION – TIPS <a id=”start_now” href=”...” >Link</a> $I->click( “#start_now” );

  45. CODECEPTION – TIPS <div data-slug=”our-plugin” > // => Somewhere in

    the DOM.. //div => ...there is a ...<div>... //div[ ] => ...and it has attributes... //div[ @data-slug=’our_plugin’ ]