behat kickstart for drupal developers
play

BEHAT KICKSTART FOR DRUPAL DEVELOPERS Florida DrupalCamp 2016 - PowerPoint PPT Presentation

BEHAT KICKSTART FOR DRUPAL DEVELOPERS Florida DrupalCamp 2016 Orlando, FL - March 5 - 6, 2016 Peter Sawczynec Engineer INTRO TO DRUPAL TESTING ECOSYSTEM Behat SimpleTest PHPUnit JMeter Drupal Extension Mink Selenium 2.0


  1. BEHAT KICKSTART FOR DRUPAL DEVELOPERS Florida DrupalCamp 2016 Orlando, FL - March 5 - 6, 2016 Peter Sawczynec Engineer

  2. INTRO TO DRUPAL TESTING ECOSYSTEM Behat SimpleTest PHPUnit JMeter Drupal Extension Mink Selenium 2.0 Phantom.js Mockery Prophecy Codeception Wraith Casper.js Slimer.js Phantom.css Jenkins Travis CI Circle.ci CrossBrowserTesting.com Sauce Labs New Relic FLORIDA DRUPALCAMP 2016 | BEHAT KICKSTART FOR DRUPAL DEVELOPERS | PETER SAWCZYNEC | PETER.SAWCZYNEC@CIVICACTIONS

  3. INTRO TO DRUPAL/PHP TESTING ECOSYSTEM Consider using these tools in your Drupal development process: phpStorm drush composer drupal console FLORIDA DRUPALCAMP 2016 | BEHAT KICKSTART FOR DRUPAL DEVELOPERS | PETER SAWCZYNEC | PETER.SAWCZYNEC@CIVICACTIONS

  4. Behat

  5. INTRO TO BDD Behaviour Driven Development (BDD) FLORIDA DRUPALCAMP 2016 | BEHAT KICKSTART FOR DRUPAL DEVELOPERS | PETER SAWCZYNEC | PETER.SAWCZYNEC@CIVICACTIONS

  6. INTRO TO BEHAT Formal Explanation Behat is a tool that makes behavior driven development (BDD) possible. With BDD, you write human-readable stories that describe the behavior of your application. These stories can then be auto-tested against your application. FLORIDA DRUPALCAMP 2016 | BEHAT KICKSTART FOR DRUPAL DEVELOPERS | PETER SAWCZYNEC | PETER.SAWCZYNEC@CIVICACTIONS

  7. INTRO TO BEHAT Informal Explanation Behat is about the concept of using a simple coding language (Gherkin) with simple words to describe things that get done (behaviors) on your website that you want to test using an ecosystem of software libraries/tools. FLORIDA DRUPALCAMP 2016 | BEHAT KICKSTART FOR DRUPAL DEVELOPERS | PETER SAWCZYNEC | PETER.SAWCZYNEC@CIVICACTIONS

  8. Behat in Drupal

  9. BEHAT IN DRUPAL Behat usage in Drupal involves installing a set of software libraries that work quite seamlessly together FLORIDA DRUPALCAMP 2016 | BEHAT KICKSTART FOR DRUPAL DEVELOPERS | PETER SAWCZYNEC | PETER.SAWCZYNEC@CIVICACTIONS

  10. INSTALL WITH COMPOSER In Drupal 7 and 8 install and update Behat and all the additional libraries and components you need with Composer FLORIDA DRUPALCAMP 2016 | BEHAT KICKSTART FOR DRUPAL DEVELOPERS | PETER SAWCZYNEC | PETER.SAWCZYNEC@CIVICACTIONS

  11. STATE OF TESTING IN DRUPAL 8 ● Drupal 8 ships with a vendor directory that contains Behat ● Drupal 8 ships with PHPUnit ● SimpleTest module also ships in D8 core, but must be enabled FLORIDA DRUPALCAMP 2016 | BEHAT KICKSTART FOR DRUPAL DEVELOPERS | PETER SAWCZYNEC | PETER.SAWCZYNEC@CIVICACTIONS

  12. MINK, MINK EXTENSION, DRUPAL EXTENSION... ● Mink, Mink Extension, Drupal Extension, Selenium, Phantom.js ... ● Software libraries like the above are important adjuncts to Behat, these libraries create the bridge to your web pages and to Drupal so you can run tests on your site FLORIDA DRUPALCAMP 2016 | BEHAT KICKSTART FOR DRUPAL DEVELOPERS | PETER SAWCZYNEC | PETER.SAWCZYNEC@CIVICACTIONS

  13. Behat Ecosystem in Drupal

  14. DRUPAL BEHAT ECOSYSTEM Where your Behat 3.0 Behat tests get written Mink Headless Browsers Behat Feature files with steps, Browser the “Tests” Goutte Controllers Behat Context Selenium2 Gherkin PHP class files, Phantom.js the testing code PHP EXECUTION Website, Drupal Extension website pages (drupal and drush) CODE Drupal

  15. INTRO TO BDD The space where as a Drupal developer Where your you write Behat tests and supporting Behat tests get written code logic using Gherkin and PHP Behat Feature Behat Context files, class files, the “Tests” the testing code Gherkin PHP Drupal

  16. Writing Behat Testing for Drupal

  17. STEPS, SCENARIOS, BACKGROUND Comments and Annotations ● More useful and required in your code. ● Used by Drupal, Behat, Symfony and other frameworks to “discover” your code and what it does FLORIDA DRUPALCAMP 2016 | BEHAT KICKSTART FOR DRUPAL DEVELOPERS | PETER SAWCZYNEC | PETER.SAWCZYNEC@CIVICACTIONS

  18. STEPS, SCENARIOS, BACKGROUND Comments /** * Step function to visit the last created node of a specific type. and * Annotations * @param string $type * The type of node that should be visited. Examples: * * @Given I visit the last created :type node */ Comment /** * Views query plugin for an XML query. * Annotation * @ingroup views_query_plugins * (contains info for * @ViewsQuery( the framework) * id = "views_xml_backend", * title = @Translation("XML Query"), * help = @Translation("Query will be generated and run using the XML backend.") * ) */ FLORIDA DRUPALCAMP 2016 | BEHAT KICKSTART FOR DRUPAL DEVELOPERS | PETER SAWCZYNEC | PETER.SAWCZYNEC@CIVICACTIONS

  19. INTRO TO BDD Feature file # Groups: Event, search (Gherkin) Given I run drush "search-api-index" Then I login And I click "Events" Then I click "New Group Event" Behat Feature Then I should see the text "Looking for members?" files, And I follow the link element with xpath "//a[contains(@href,'/group-ela')]" the “Tests” Given I visit the last created "article" node Context class file /** (PHP) Gherkin * Step function to visit the last created node of a specific type. * * @param string $type * The type of node that should be visited. * * @Given I visit the last created :type node Behat Context */ class files, public function iVisitTheLastCreatedNodeByType($type) { the testing code $node = $this->getLastCreatedEntityFromDb('node', $type); $this->getSession()->visit($this->locatePath('/node/' . $node->nid)); PHP } Drupal

  20. INTRO TO BDD Feature file # Groups: Event, search (Gherkin) Given I run drush "search-api-index" Then I login And I click "Events" Then I click "New Group Event" Behat Feature Then I should see the text "Looking for members?" files, And I follow the link element with xpath "//a[contains(@href,'/group-ela')]" the “Tests” Given I visit the last created "article" node Context class file (PHP) /** Gherkin * Step function to visit the last created node of a specific type. * * @param string $type * The type of node that should be visited. * * @Given I visit the last created :type node Behat Context */ class files, public function iVisitTheLastCreatedNodeByType($type) { the testing code $node = $this->getLastCreatedEntityFromDb('node', $type); $this->getSession()->visit($this->locatePath('/node/' . $node->nid)); PHP } Drupal

  21. INTRO TO BDD Feature file (Gherkin) Then I login Then I should see the text "Looking for members?" Given I visit the last created "article" node Behat Feature Context class file Then I logout files, (PHP) ... /** the “Tests” * Step function to visit the last created node of a specific type. Gherkin * * @param string $type * The type of node that should be visited. * Behat Context * @Given I visit the last created :type node class files, */ the testing code public function iVisitTheLastCreatedNodeByType($type) { PHP $node = $this->getLastCreatedEntityFromDb('node', $type); Drupal

  22. STEPS Steps in Gherkin When I am on the homepage Then I should get a "200" HTTP response And I should see the button 'Log in' When I go to "/admin" Then I should get a "403" HTTP response Steps And I should see "Access denied" FLORIDA DRUPALCAMP 2016 | BEHAT KICKSTART FOR DRUPAL DEVELOPERS | PETER SAWCZYNEC | PETER.SAWCZYNEC@CIVICACTIONS

  23. STEPS, TAGS, SCENARIO Steps in use in a Scenario: Tags @smoke @access Scenario: Anonymous User permissions Scenario Title When I am on the homepage Then I should get a "200" HTTP response And I should see the button 'Log in' When I go to "/admin" Then I should get a "403" HTTP response Steps And I should see "Access denied" FLORIDA DRUPALCAMP 2016 | BEHAT KICKSTART FOR DRUPAL DEVELOPERS | PETER SAWCZYNEC | PETER.SAWCZYNEC@CIVICACTIONS

  24. TAGGING @api @permissions Feature: Specific user permissions 1. Point One Tags to identify the As an authenticated user whole feature file I should not be able to access admin pages So that I can verify my permissions 2. Point Two @smoke 3. Point Three Scenario: Anonymous User permissions When I am on the homepage Tags by scenario Then I should get a "200" HTTP response 4. Point Four And I should see the button 'Log in' 5. Point Five FLORIDA DRUPALCAMP 2016 | BEHAT KICKSTART FOR DRUPAL DEVELOPERS | PETER SAWCZYNEC | PETER.SAWCZYNEC@CIVICACTIONS

Recommend


More recommend