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

WordPress Greek Community

November 19, 2016
Tweet

More Decks by WordPress Greek Community

Other Decks in Programming

Transcript

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

    View Slide

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

    View Slide

  3. AUTOMATED TESTING
    • Use of special software to compare the actual output of an
    application with the one we expect

    View Slide

  4. Manual tests
    Integration tests
    Unit Tests

    View Slide

  5. NEEDS FOR AUTOMATED TESTING
    • Expedite procedure of quality control
    • Quick releases
    • Integration with WordPress
    • Integration with 3rd party plugins

    View Slide

  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

    View Slide

  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

    View Slide

  8. 2 UnitTests – 0 Integration tests

    View Slide

  9. • Avoid regressions (re-appearance of the same bug)
    • Ensure that existing functionality remains
    • Frequency of updates
    SIMPLE NEEDS FOR AUTOMATED TESTING

    View Slide

  10. UPDATES FOR WP SEO, WC & WP IN 2016

    View Slide

  11. BEST COFFEE OF YOUR WEEK

    View Slide

  12. CODECEPTION
    • Testing framework for PHP applications
    • Easy and simple to use
    • Modular and extensible
    • Promotes design patterns

    View Slide

  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

    View Slide

  14. INSTALLATION OF CODECEPTION
    Requirements
    • Selenium Standalone
    • WordPress (website)
    (locally or in server)
    • Browser
    • Composer
    • Phar αρχείο (executable)
    Installation

    View Slide

  15. CODECEPTION – BOOTSTRAP
    $ wget http://codeception.com/codecept.phar
    $ php codecept.phar bootstrap

    View Slide

  16. View Slide

  17. View Slide

  18. View Slide

  19. View Slide

  20. View Slide

  21. CODECEPTION – MANUAL TEST STEPS
    • Create a test product
    • View product in the front-end
    • Add product to cart
    • Continue with checkout

    View Slide

  22. CODECEPTION – GENERATE TEST
    $ php codecept.phar generate:cept
    acceptance WooCommerceBasic
    /tests/acceptance/WooCommerceBasicCept.php

    View Slide

  23. View Slide

  24. EMPTY CEST
    $
    codeception.com/docs/06-ModulesAndHelpers#hooks

    View Slide

  25. CODECEPTION – BOOTSTRAP

    View Slide

  26. CODECEPTION –

    View Slide

  27. CODECEPTION –

    View Slide

  28. CODECEPTION –
    $

    View Slide

  29. CODECEPTION –

    View Slide

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

    View Slide

  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

    View Slide

  32. CODECEPTION & SELENIUM IDE
    Two Firefox Add-ons
    • SeleniumIDE
    • CodeCeption Formatters

    View Slide

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

    View Slide

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

    View Slide

  35. CODECEPTION

    View Slide

  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

    View Slide

  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

    View Slide

  38. CODECEPTION
    php codecept.phar generate:pageobject EditProductPage

    View Slide

  39. CODECEPTION

    View Slide

  40. CODECEPTION

    View Slide

  41. Q & A

    View Slide

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

    View Slide

  43. CODECEPTION – LINKS

    View Slide

  44. CODECEPTION – TIPS
    Link
    $I->click( “#start_now” );

    View Slide

  45. CODECEPTION – TIPS

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

    View Slide