Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Panther: test your Symfony apps with real web browsers

19.666 visualizaciones

Publicado el

From a few lines of jQuery to modern React/Vue… PWA, Symfony apps always contain JavaScript code. Unfortunately, the SF functional test helper and the Goutte web scrapping lib aren’t able to execute JS code. It means that they cannot assert on client-side generated HTML, test if an element is visible or not, deal with alert boxes or detect if a bug occurs only with a specific browser.

Panther is a brand new e2e testing and web scrapping library written in PHP that drives real browsers thanks to the WebDriver protocol from the W3C. It implements the exact same API than the BrowserKit component. It means than existing SF tests and Goutte scripts work without modification… but this time JS will be executed! The tool also brings new capabilities including taking screenshots, or executing custom JS in the execution context of the web page. To install Panther you only have one command to run, and it doesn’t need any dependency to install Panther. Let’s meet the feline!

Publicado en: Software
  • Sé el primero en comentar

Panther: test your Symfony apps with real web browsers

  1. 1. @dunglas Kévin Dunglas ❏’s Founder ❏ Symfony Core Team ❏ API Platform creator @dunglas
  2. 2. @dunglas ❏ Self-managed company, since 2011 ❏ Entirely owned by the employees ❏ 30 people, 1,000% growth in 6 years! ❏ Hiring in Paris & London:
  3. 3. @dunglas A Very Simple Blog
  4. 4. @dunglas Install the Website Skeleton Symfony + Twig + Doctrine + common dev & debug tools
  5. 5. @dunglas Enable Bootstrap
  6. 6. @dunglas Testing a Symfony App
  7. 7. @dunglas
  8. 8. @dunglas 3 Components to Emulate a Browser
  9. 9. @dunglas
  10. 10. @dunglas A Web Scraping Library
  11. 11. @dunglas A Functional Test
  12. 12. @dunglas Generate a Test Skeleton
  13. 13. @dunglas
  14. 14. @dunglas Run the Test
  15. 15. @dunglas Functional Tests in Symfony ❏ KernelTestcase: ❏ Extends PHPUnit’s TestCase ❏ boots the Symfony app ❏ WebTestCase: ❏ extends KernelTestcase ❏ uses BrowserKit (that uses DomCrawler and CssSelector) ❏ creates HTTP Foundation’s Request and allows to inspect Response through a clean API
  16. 16. @dunglas WebTestCase is elegant, developer-friendly and fast,
 but what if: ❏ something is hidden by a faulty CSS rule ❏ a JS error prevents the page to load ❏ the browser blocks the form (XSS detection…) ?
  17. 17. @dunglas You’ll never know!
  18. 18. @dunglas And what if you rely on: ? Symfony Encore +
  19. 19. You can’t test it!
  20. 20. @dunglas Why? Because BowserKit doesn’t support JavaScriptnor CSS
  21. 21. @dunglas Introducing Symfony Panther 😺
  22. 22. @dunglas Panther, in a few words ❏ Executes real web browsers ❏ So, same features than browsers including JS and CSS ❏ Implements BrowserKit’s API ❏ Built on top of Facebook’s PHP WebDriver and the WebDriver Protocol, implements PHP WebDriver’s API ❏ Provide convenient methods for JS testing: ❏ wait, execute script, screenshot… ❏ Standalone lib, for testing and web scraping
  23. 23. @dunglas Guess what? You already master Panther!
  24. 24. @dunglas
  25. 25. @dunglas Run the Test
  26. 26. @dunglas Drop-in replacement for existing WebTestCase tests and Gouttescripts
  27. 27. @dunglas Choose your Weapon 🔪 🔫 💣
  28. 28. @dunglas Extra Capabilities %
  29. 29. @dunglas Access your Services
  30. 30. @dunglas Easy to use, Developer-friendly ❏ Nothing to install ❏ Nothing to configure ❏ neither Selenium, ❏ nor a web server ❏ Panther just works!
  31. 31. @dunglas You only Believe What you See?
  32. 32. @dunglas How Does it Work?
  33. 33. @dunglas ChromeDriver ❏ Panther is shipped with ChromeDriver binaries ❏ It’s a standalone server, exposing
 a Selenium/W3C compliant WebDriver API ❏ It automatically finds the local Chrome install ❏ It can start Chrome in headless mode!
  34. 34. @dunglas Panther Supports Any WebDriver API ❏ ChromeDriver is not mandatory ❏ Experimental support for Geckodriver
 (same as ChromeDriver, but for Firefox) ❏ Compatible with the Selenium server and Selenium Grid ❏ Compatible with remote testing services such as:
  35. 35. @dunglas The Builtin Web Server ❏ Panther transparently serves your project using the builtin PHP web server ❏ it finds the PHP binary ❏ it finds the document root (public/ with Flex) ❏ it starts the project in test environment ❏ Yes, it works even on Windows!
  36. 36. @dunglas Panther Can Work with Any Web Server ❏ You use Docker, or Vagrant? ❏ Panther has got you covered ❏ You can configure the URL to use… ❏ …and disable the builtin web server!
  37. 37. @dunglas Continuous Integration
  38. 38. @dunglas Panther Is Compatible With: ❏ Travis CI ❏ AppVeyor (Windows) ❏ Docker (GitLab CI, Circle CI, custom…) ❏ SauceLabs, BrowserStack and other browser testing services
  39. 39. @dunglas Travis
  40. 40. @dunglas Docker
  41. 41. @dunglas Test Environment
  42. 42. @dunglas Config and Environment Variables The builtin web server inherits from env vars set in the current context:
  43. 43. @dunglas We’re trying to make this easier, and you can help us:
  44. 44. @dunglas Database Testing and Fixtures
  45. 45. @dunglas Introducing AliceBundle,
 Panther & WebTestCase’s new best friend
  46. 46. @dunglas Install AliceBundle
  47. 47. @dunglas AliceBundle: What’s Inside? ❏ Faker: pseudo-random data generator ❏ Alice: an expressive syntax on top of Faker ❏ Symfony integration (new: Flex integration) ❏ Support for Doctrine ORM, ODM and Eloquent ❏ New: DB testing helpers (inspired by Laravel)
  48. 48. @dunglas Describe the Data you Want
  49. 49. @dunglas Purge the DB and Load Fixtures before every test:
  50. 50. @dunglas Faster Panther Tests
  51. 51. @dunglas Starts and stops the web server for every test suite, instead of every test class. Contributed by @Pierstoval (symfony/panther#30)
  52. 52. @dunglas Available right now! Thanks! Any question?