Automation Test Practice

Follow me on GitHub

Cypress Automation Test Overview

Cypress is an emerging JavaScript-based end to end automation test framework running on browsers directly. It is not based on Selenium — if you have heard about another JavaScript-based automation test framework Protractor, it is still based on Selenium actually.

Pre-condition knowledge

For engineers who are familiar with JAVA/Python + selenium, to learn Cypress, of course, at first we need to be familiar with JavaScript syntax, I mean the new JavaScript after ES5.

Secondly, as Cypress behind is a Node.js server process, it would be helpful to have basic Node.js knowledge.

Last but not least, Asynchronous is an important concept which will be mentioned often in Cypress learning. To know a little bit on how JavaScript engine working can help us understand better on Asynchronous.

Custom Commands

Cypress does not suggest Page Object Model. Then how could we achieve the goal of re-usability and abstraction? A typical scenario is, for many applications testing, the first step is to login the application. We cannot copy&paste the login automation code each time. Thus we can define a “login” custom commands under \support\commands.js as following.
cypress_add.png
Then in the testing code, we just simply add cy.login() . We don’t need to build LoginPage, then call the login() method in that page as we do in Selenium.

Data Driven – Fixture

It cannot be regarded as automation test if we do not have data driven. I have introduced the concept of Fixture in Python automation testing section. Fixture in Cypress is even much easier.

As an simple example, we add “city.json” under folder \fixtures with following content:

{ “city”: “Toronto”}

To access this data, in the test code, I give two following example:

cypress_II.png
Question: in the 2nd example, can I write as following? Suggest you to try by yourself. If you don’t understand the result, check how does Cypress working as Asynchronous.

cypress_III.png

I will add more Cypress relevant blogs, stay tuned.

Back To Homepage