Cypress e2e Testing in the Jenkins Pipeline

If you have problems running Cypress in Jenkins, this excellent article will help: https://medium.com/aubergine-solutions/install-cypress-io-front-end-testing-tool-dependencies-on-amazon-linux-ami-ec2-instance-f676da4abbdd.For the Cypress part we install the following node package that allows us to execute commands in parallel:npm install concurrently –save-devAnd extend our package.json scripts section by:"cypress:ci": "concurrently "cypress run" –kill-others "ng serve" –success first",The “cypress:ci” task will be executed by the “e2e Tests” step in the Jenkins pipeline..Now we can press the “Build Now” button in the Jenkins and get the following result:When inspecting the console output of the build, we can verify that the Cypress tests really ran:But what if a test fails?.Currently we would need to check the console output in Jenkins to figure out what went wrong..What we need is a test reporter for Mocha..To have the relevant settings we put the following into the cypress.json file in our project’s root directory:For this to work we need to have the JUnit Plugin installed in the Jenkins..That should already be the case by default..We then insert a “post” block after the “stages” in our Jenkinsfile:stages { …}post { always { junit 'results/cypress-report.xml' }}Thus, an action is added to the end of the pipeline, which is generating the test report and allows us to see the failing tests:That’s it for now..The complete sources are available on GitHub..As a next step, you could look into Parallelisation of cypress tests to decrease your overall build time..And of course it would be cool to also see the screenshots and videos of the failed tests directly in Jenkins.. More details

Leave a Reply