Slide 1

Slide 1 text

Easing developers’ life university.sensiolabs.com Cypress, the E2Emust learn from the past SensioLabs

Slide 2

Slide 2 text

Embrace the past, learnfromit Sensiolabs SensioLabs

Slide 3

Slide 3 text

university.sensiolabs.com Guillaume Loulier / @Guikingone Developer @SensioLabs SensioLabs

Slide 4

Slide 4 text

Imperfectly balanced, as all things should be

Slide 5

Slide 5 text

university.sensiolabs.com Unit: PHPUnit, Atoum E2E / Functional: PHPSpec, Behat, Mink, Panther, CodeCeption, Pest, Khalan, Peridot, Storyplayer Did I mention extensions, bridges and so on? State of the art - PHP SensioLabs

Slide 6

Slide 6 text

university.sensiolabs.com Unit: Jest, Mocha, Chai, Sinon E2E / Functional: Karma, Puppeter, Jasmine, Cypress, CodeceptJS, Nightwatch As before, we can talk about thousands of tools … State of the art - JS SensioLabs

Slide 7

Slide 7 text

Have you ever heard the tragedy of E2E testing?

Slide 8

Slide 8 text

university.sensiolabs.com That’s a sad story SensioLabs By convention, E2E force us to think about the application as the final user Maintenance and writing cost are way bigger than unit tests Regarding the layers that we engage during E2E tests, the whole testing experience can be slower (UI, DB, API’s, etc), not to mention external services (Mercure, Vulain, emails, message brokers, etc) Modern architectures can slow down the testing process (SPA, PWA, etc)

Slide 9

Slide 9 text

Could we learn this power to solve issues?

Slide 10

Slide 10 text

university.sensiolabs.com SensioLabs Cypress is an E2E framework Available via Yarn, NPM and Docker Well known syntax (easy to use and fast) , a lot of shortcuts and commands to ease the writing experience Main browsers natively supported (except IE, let be serious) Backed and developed by the Cypress company (under MIT licence)

Slide 11

Slide 11 text

university.sensiolabs.com Cypress act as a wrapper around Chai, jQuery, Sinon, Mocha and many more Cypress can intercept, mock and wait for XHR / fetch requests The whole UI can be bypass to speed up tests The debug experience is improved thanks to screenshots, videos and a dedicated replay for failing steps Sell me this library SensioLabs

Slide 12

Slide 12 text

university.sensiolabs.com More? SensioLabs Code coverage, visual testing tools, Typescript, IDE support, BrowserStack, parallelization, dashboard Github / Gitlab / Bitbucket integrations, Slack notifications Unit tests, API tests (REST/GraphQL), Lighthouse integration, performances analyzes, carbon footprint analyze, component testing and much more! Want to test hybrid apps (Ionic, React Native, etc)?

Slide 13

Slide 13 text

Cypress& Symfony SensioLabs

Slide 14

Slide 14 text

university.sensiolabs.com Quick & easy installation Both REST and GraphQL APIs are natively supported Symfony UX ? Already supported Webpack Encore? Not an issue SensioLabs

Slide 15

Slide 15 text

Holdon, not so fast

Slide 16

Slide 16 text

university.sensiolabs.com Poor integration with Symfony No Selenium support (for now?) No isolated client support Clients configuration poorly documented Better browser support and network requests support out of the box What about Panther ? SensioLabs

Slide 17

Slide 17 text

university.sensiolabs.com Native DOM access, JS support Need to adapt against the PO / QA syntax / usages No locale support Less drivers (but easier browser configuration) And Behat? SensioLabs

Slide 18

Slide 18 text

And what if you show me some code?

Slide 19

Slide 19 text

university.sensiolabs.com Quick start yarn add --dev cypress (Cypress is not required in production environment) symfony serve, launch a new server on https://127.0.0.1:8000 yarn run cypress open, create defaults files and required directories then launch Cypress via a GUI SensioLabs

Slide 20

Slide 20 text

university.sensiolabs.com Easy setup SensioLabs A dashboard is available in GUI mode to configure the tests and launch them Each test can be isolated and launch to separate the errors / debug Instant access to the documentation and support, not to mention the replay and the online dashboard

Slide 21

Slide 21 text

university.sensiolabs.com Let’s test SensioLabs

Slide 22

Slide 22 text

university.sensiolabs.com Deep dive Cypress allows to use hooks to use repetitive tasks / commands Thanks to commands, we can automate tasks and ease the writing experience Assertions can be chained to improve readability and focus on the end requirement Thanks to the “jQuery” syntax, elements can be easily found SensioLabs

Slide 23

Slide 23 text

university.sensiolabs.com Time to ease our steps Commands helps to ease and automate the recurrent tasks (fixtures, cache, etc) Can be used in tests, hooks, loops, etc No limitations regarding HTTP calls, other commands usage, assertions, etc SensioLabs

Slide 24

Slide 24 text

university.sensiolabs.com Automate everything SensioLabs Repetitive tasks as login can be boring to test Commands are a great way to ease these use cases If needed, commands can be overwritten, chained, etc

Slide 25

Slide 25 text

university.sensiolabs.com Develop, test, adapt, repeat SensioLabs Want to test on multiple devices? Can be defined via the configuration, hooks, commands or during the tests Wide support for modern devices and custom sizes

Slide 26

Slide 26 text

Sadly, there’s something that I need to tell you

Slide 27

Slide 27 text

university.sensiolabs.com Sad news SensioLabs As easy as it looks, Cypress cannot handle every use case Without a proper bridge, Symfony seems hard to interact with Server errors debug can be a real pain The Docker integration / usage is quite hard BC breaks, unmaintained bridges / extensions

Slide 28

Slide 28 text

Any advices?

Slide 29

Slide 29 text

university.sensiolabs.com Writing tests outside of the tested application tend to make them easier to maintain and more resilient Cross-browser testing must become the standard Thanks to the bundle approach, Cypress could welcome a dedicated bundle Thanks to our experience with Behat and other tools, we could easily structure and improve Cypress tests A lot SensioLabs

Slide 30

Slide 30 text

university.sensiolabs.com Don’t fear control, embrace it SensioLabs Cypress forces us to use a specific structure / approach, don’t be afraid to adapt it and modernize it Filter, group, watch, repeat Intercept, mock heavy network requests, watch and test your UI (thanks to visual testing) Measure performances, frontend indicators, etc

Slide 31

Slide 31 text

So, should I use it?

Slide 32

Slide 32 text

university.sensiolabs.com Yes SensioLabs If you wish to write resilient, fast and up- to-date tests which support recent frontend evolutions, yes If you need to handle actual browsers, network requests and modern practices / frameworks, yes If you’re not afraid of maintaining tests, writing JS and improving your CI / CD, yes If you need to improve teamwork, improve delivery and deploy more often, yes

Slide 33

Slide 33 text

The end Any questions? SensioLabs