Unleash Test Automation Power with Cypress.io
Kushan Shalindra Amarasiri
Head of Quality Engineering at Social Catfish
We are in an era of test automation and it is at its peak. There are various test automation tools available in the market. Existing test automation tools are getting updated while new tools enter to the market to overcome the limitations of current test tools available. There are tools for Web Services/ Web Applications/ Desktop and mobile automation.
As mentioned in my previous articles, if you want to be an awesome test automation engineer learning the automation tool stack is the utmost important thing that you should do. Do not rely on just one or two tools. Keep moving up the ladder by learning each tool and be a flexible and fully-fledged test automation engineer.
The tool that I'm going to let my community know in this article is called Cypress.io, which is new to the test automation arena. My sincere thanks should go to Joe Colantonio, who is also a guru in test automation arena. His article on Cypress allowed me to investigate more on this test tool further.
Cypress is an end to end frontend test automation tool which has come up recently and its based on Node.JS. Cypress is based on latest Java Scripting technology, which will handle modern web applications based on Anjular.JS or React.JS.
Going through this new great test automation tool I learned lot of its features. They are simply fantastic.
- No wait times.... - With Cypress.io there is no need to have hectic wait commands like Selenium. It handles the page loading, object loading automatically. No more fuss on explicit and even implicit waits like Selenium.
- No more exceptional coding to capture screen shots or videos on error - Cypress.io created screen shots and videos automatically on failure.
- Interactive script execution - The test runner given by Cypress.io is highly awesome and interactive. Scripts starts executing when we do modifications and save. We do not have to use extra effort to execute scripts seperatly. We can also see interactively the commands gets executed and also time tasken to execute the script.We can also select the browser to execute from the browser dropdown.
- Interactive debugging - Cypress takes separate snapshots of each command getting executed. So we can select each executed command and view screen shots of before and after execution of each command. Debugging is simply awesome.
- No reliance on Selenium or WebDriver, they have their own execution engine and there is simply awesome speed of execution.
Lets look at how we can get started with Cypress.io. First we have to download and install Node.js as it uses Node.js and run on top of it
Next go to the command line and type the following command
npm install cypress
The cypress installation will be downloaded and installed in your machine.
After installing open up Cypress.io test runner by typing the following command in your command line.
node_modules\.bin\cypress open
It automatically takes the available .js files in your ..\cypress\integration folder. Next create the following code snippet in your favorite js editor or notepad.
describe('Kushan First Test', function(){
it('Go to google',function(){
cy.visit('https://www.google.lk')
})
})
This script will navigate to google.lk web URL. You can have any text description as describe function and it function.
When double clicking on the js file you have created the script will get executed, by the Cypress test runner.
Next lets try to click on the Sign In link in BusSeat.lk URL.
describe('Kushan First Test', function(){
it('Go to Bus Seat LK',function(){
cy.visit('https://busseat.lk/')
cy.contains('Sign In').click()
})
})
Next we will expand the test script to input the email in the user name field.
describe('Kushan First Test', function(){
it('Go to Bus Seat LK',function(){
cy.visit('https://busseat.lk/')
cy.contains('Sign In').click()
cy.get('#username').type('[email protected]')
})
})
Hope this article gave the heads up on how to jump start test automation with new tool like Cypress.io, and explore the wonderful features it gives. We will explore more functionality of Cypress.io in more upcoming articles. So stay tuned.
Good Article Kushan.......
Senior QA engineer
7 年Great article