Cypress is an end to end testing tool based on React, Angular JS and Mocha BDD syntax. You can install Cypress as npm package or a desktop application. You can also integrate it with CI tool (Jenkins, Circle CI, Travis CI, etc.), Github, Slack, and others.
Here are the steps to start doing a test using Cypress:
- Install Cypress via npm
- Write test script
- Generate report using — reporter junit
- Generate report using — reporter mochawesome for better view
- Run Cypress Testing using Jenkins
1. Install Cypress via npm
Open Command Prompt and write this command below:
npm install --save-dev cypress
If you want to install cypress as a desktop application, you can download the app in https://download.cypress.io/desktop
2. Write test script with filename googlemapsSample.js
//googlemapsSample.jsdescribe('My First Test', () => {
it('Search Google Maps', () => {
cy.visit('https://maps.google.com')
//Get an input, type something then click button Search
cy.get('.searchbox-hamburger-container').type('Golden Gate Bridge')
cy.get('.searchbox-searchbutton-container').click()
//Verify search result (URL)
cy.url().should('eq', 'https://www.google.com/maps/search/Golden+Gate+Bridge/@37.8199286,-122.4804438,17z')
})
})
Run test script with command below on command prompt:
cypress run --spec 'your_testscript_path\googlemapsSample.js
If you want to run test in browser chrome, firefox, edge, etc. You can add — browser . The full command will be:
cypress run --spec 'your_testscript_path\googlemapsSample.js --browser chrome
3. Generate report using — reporter junit
For generating cypress test report, you can run the command below on command prompt:
cypress run --spec 'cypress\integration\samples\googlemaps.js'--reporter junit --reporter-options mochaFile=result.xml,toConsole=true
4. Generate report using — reporter mochawesome for better view
Install mochawesome inside your project folder with command:
npm install --save-dev mochawesome
After mochawesome is installed, you can run the command below on command prompt to generate the test report:
cypress run --spec 'cypress\integration\samples\googlemaps.js'----reporter mochawesome
mochawesome package will generate 2 main files with format *.html and *.json.
You can check other files generated by mochawesome at https://www.npmjs.com/package/mochawesome
5. Run Cypress Testing using Jenkins
Before run Cypress on Jenkins, you need install cypress first, with step:
Click Manage Jenkins > Click Global Tool Configuration > Click NodeJS installations… > Fill Global npm packages to install to cypress > Click Save
After setting the global tool config, you can create Jenkins project with step:
Create new Freestyle project >Setting Build Environment (choose provide node &npm bin/folder to path) > Setting Build and choose Execute Windows Batch Command then write command syntax below > Click Save > Click Build Now
//command in Build
cypress run --spec 'your_testscript_path\googlemapsSample.js
If you want to trigger Jenkins Build periodically, you should set a schedule value with format Minute (0–59), Hour (0–23), Day (1–31), Month (1–12), Day of the week(0–6).
For example if you want to build Jenkins triggering daily at 08:30 in the morning, Monday to Friday, you can set schedule with value 30 08 * * 1–5
You can see the generated test report with filename result.xml in Jenkins Project Workspace.
After Jenkins build success, Jenkins will send notification to your slack channel.
If you want send email notification, you can configure it in Post-build Actions.
Thanks for reading.