Author: Emil Akhadov
This project contains an automated end-to-end test suite for the Google Calculator component that appears when searching for "calculator" on Google. The tests are built using Cypress.io.
The primary goal of this project is to build an automated end-to-end test suite that tests the functionality of this calculator component on Google. The calculator only has the buttons 0123456789.=+-×÷AC/CE.
To run these tests, ensure you have Node.js v18+ installed.
-
Clone the repository:
git clone https://github.com/eagauss/google-calculator-testing.git cd google-calculator-testing -
Install dependencies:
npm ci
This will install Cypress and
@cypress/xpath, which are listed asdevDependenciesinpackage.json.
Important Note: Due to Google's limitations, you might encounter a CAPTCHA. You will need to manually solve this CAPTCHA only once for the tests to proceed.
You can run the tests in two modes:
-
Headed (browser visible):
npm run cy:run
This command will execute the tests in a Chrome browser that is visible during the execution.
-
Open Cypress Test Runner:
npm run cy:open
This command will open the Cypress Test Runner application, allowing you to select and run specific tests, view their execution, and debug.
The tests are organized as follows:
cypress.config.js: This file contains the Cypress configuration, includingbaseUrl,viewportWidth,viewportHeight, and experimental features.cypress/e2e/calculator.cy.js: This file contains the main test suite with various calculator scenarios.cypress/support/page_objects/calculatorPage.js: This file defines the Page Object Model for the calculator, providing methods to interact with calculator elements.
The test suite covers a variety of scenarios, including:
- Basic arithmetic operations (addition, subtraction, multiplication, division).
- Operations with positive and negative numbers.
- Operations involving decimals.
- Division by zero handling (results in 'Infinity' or 'Error').
- Clear Entry (
CE) and All Clear (AC) functionality. - Typing expressions directly into the display and pressing Enter.
- Cypress.io: End-to-end testing framework (v14.4.0)
@cypress/xpath: XPath selector plugin (v2.0.3)
While this project uses @cypress/xpath for element selection, note that:
- The plugin is no longer actively maintained
- I recommend migrating to
data-cyattributes for future-proofing - XPath is used here primarily for demonstration purposes