ArCiGo / TS-Automation-Framework

JS/TS Automation Framework template to create new projects using Cypress

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Automation Framework made with TS + Cypress

The goal of this project was to put into practice my knowledge using this amazing tool for automation testing.

Do you want to create a framework based on this project? Check this branch!

The project πŸ’»

The SWAG Labs/Sauce Demo store, from Sauce Labs, was automated using TS + Cypress. It generates an HTML report for passed and failed tests. Also, this project has GitHub Actions and Docker.

Tools βš™οΈ

  • Cypress v10.3.1.
  • cypress-mochawesome-reporter v3.2.0.
  • TypeScript v4.7.4.
  • GitHub Actions.
  • Docker.

Main project structure πŸ—‚οΈ

.
β”œβ”€β”€ .github/
β”‚   └── workflow/
β”‚       └── main.yml
β”œβ”€β”€ cypress/
β”‚   β”œβ”€β”€ e2e/
β”‚   β”‚   β”œβ”€β”€ login.spec.cy.ts
β”‚   β”‚   β”œβ”€β”€ logout.spec.cy.ts
β”‚   β”‚   └── shoppingCart.spec.cy.ts
β”‚   β”œβ”€β”€ fixtures/
β”‚   β”‚   └── products.json
β”‚   β”œβ”€β”€ support/
β”‚   β”‚   β”œβ”€β”€ commands.ts
β”‚   β”‚   β”œβ”€β”€ e2e.ts
β”‚   β”‚   └── index.ts
β”‚   └── tsconfig.json
β”œβ”€β”€ cypress.config.ts
β”œβ”€β”€ cypress.env.json
β”œβ”€β”€ Dockerfile
└── package.json

Setup πŸ› οΈ

The following steps can be executed using a terminal (I use hyper), or using the terminal provided by VS Code.

  1. Clone the repo on your computer at any path you want.-
> git clone https://github.com/ArCiGo/JS-Automation-Framework.git

> git checkout AutomationFrameworkSample_TS
  1. In the path you cloned the repo, open the project folder and install the packages.-
> cd TS-Automation-Framework

> npm i
  1. There is a cypress.env.json file without values. For demo purposes, you can fill it with these values.-
{
    "valid_user": {
        "username": "standard_user",
        "password": "secret_sauce"
    },
    "locked_user": {
        "username": "locked_out_user"
    },
    "invalid_user": {
        "username": "wrong_username",
        "password": "wrong_password"
    }
}

Run the tests ⚑

# If you don't want to open the Cypress GUI, you can execute the following commands:
> npm run cypress:open:cli
# or
> npm run html-report

# If you want to open the GUI:
> npm run cypress:open

When you run the tests, a new folder is generated inside the cypress folder (reports). This folder contains the report for the executed tests. If a test fails, the report will include a screenshot to see what the failure was.

UI Report Sample UI Report Sample

Docker πŸ‹

If you want to execute the tests using Docker, you can do the following in your terminal at the workspace project.-

# Without a Dockerfile

# Pull the Cypress Docker image you need to run the tests. You can use the latest one
> docker pull cypress/included:9.4.1

# Execute the following command to see the info of the image
> docker run -it --entrypoint=cypress cypress/included:9.4.1 info

# Then, execute the following command to run the tests inside of the container
> docker run -it -v $(pwd):/e2e -w /e2e cypress/included:9.4.1 --spec cypress/e2e --browser electron
# With a Dockerfile

# Execute the following command to compile the file. <YourVersionTag> may be any value you want
> docker build -t my-cypress-image:<YourVersionTag> .

# Then, execute the following command to run the tests inside of the container
> docker run -i -v $(pwd):/my-cypress-project -t my-cypress-image:<YourVersionTag> --spec cypress/e2e

About

JS/TS Automation Framework template to create new projects using Cypress


Languages

Language:TypeScript 88.5%Language:Dockerfile 11.5%