This is Automated test which was build to test Google Calculator Functionality using Cypress.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
A step by step series of examples that tell you how to get a development env running
Navigate to the folder where your project is located.
npm i
- NPM - If you want to know what does "npm i" do
This command will execute all avaliable tests:
npm run test:e2e
This command will execute functional tests:
npm test:e2e:functional
This command will execute smoke tests:
npm run test:e2e:smoke
This command will open Cypress GUI:
npm run cypress open
In order to avoid code duplication in project i wrote custom commands which are located in support/commands.js
Using those commands (functions) allows us to write test in extremely simple way and avoid code duplication.
Code below will execute math operation: 9 * 9 and will verify that the answer is correct automatically (81).
cy.mathOperations(numbers.nine, numbers.multiply, numbers.nine);
Example of another math operation: Code below will execute math operation: 7 - 6 and will verify that the answer is correct automatically (1).
cy.mathOperations(numbers.seven, numbers.subtract, numbers.six);
Code below will make a click on calculator button and automatically verify that this value was displayed on calculator: It requires two parameters: numbers.one.idLocator - Is an Identifier**(ID)** of a button which we want to click. numbers.one.value - Is a Numeric value of a button. (Numeric value is needed in order to compare Calculator output with expected result)
cy.verifyNumberButtonInput(numbers.one.idLocator, numbers.one.value);
In order to avoid code duplication i am using Page Object. In this example i made just a Single Page Object, but of course bigger size app will contain multiple page objects. This is an example of a Page Object element:
nine: {
value: 9,
idLocator: "#cwbt15"
}
multiply: {
value: "*",
displayValue: "ร",
idLocator: "#cwbt26"
}
It will allow us to in our test to Referencing to this data instead of re-declaring it over and over.
Cypress is new tool and during my work i experienced multiple issues which i want to note:
- In my test i was needed to add a wait because from time to time i had a failure on Button click. Url to this issue
cy.wait(150);
I spend over 4 hours by looking for the solution because "wait" is considered a bad practice, but none of the solutions worked. This one will not work aswell:
cy.get('#query-btn').invoke('width').should('be.gt', 0)
- In some cases force clicks were required to add because click were not always being executed.
{ force: true }
- If you will run the test too often Google may time your test out and bring a captcha screen.
- Anton Filiptsov
This project is licensed under the MIT License - see the LICENSE.md file for details