TS-CypressIO

CypressIO Typescript Test Automation Project Structure

Here’s a project structure mockup designed for a TypeScript (TS) project using CypressIO, npm, Page Object Model (POM), and GitHub integration. It includes a .github directory for CI/CD and other relevant files:


Project Structure

project-root/
│
├── cypress/
│   ├── e2e/
│   │   ├── login.spec.ts       # Example test file
│   │   └── home.spec.ts        # Another test file
│   │
│   ├── fixtures/
│   │   └── user.json           # Test data for scenarios
│   │
│   ├── support/
│   │   ├── commands.ts         # Custom commands for Cypress
│   │   └── e2e.ts              # Test configuration and hooks
│   │
│   ├── pages/                  # Page Object Model files
│   │   ├── loginPage.ts        # Login Page Object
│   │   └── homePage.ts         # Home Page Object
│   │
│   └── plugins/
│       └── index.ts            # Cypress plugin configuration
│
├── .github/
│   ├── workflows/
│   │   ├── nightly-build.yml   # Nightly CI/CD workflow
│   │   └── on-push-build.yml   # On each push CI/CD workflow
│   │
│   ├── CODEOWNERS              # Code owners configuration
│   └── pull_request_template.md # PR template
│
├── .gitignore                  # Ignored files and directories
├── cypress.config.ts           # Cypress configuration file
├── package.json                # npm package dependencies
├── tsconfig.json               # TypeScript configuration
└── README.md                   # Project documentation

File Examples


cypress/pages/loginPage.ts

class LoginPage {
  private usernameField = '#username';
  private passwordField = '#password';
  private loginButton = '#login';

  enterUsername(username: string) {
    cy.get(this.usernameField).type(username);
  }

  enterPassword(password: string) {
    cy.get(this.passwordField).type(password);
  }

  clickLogin() {
    cy.get(this.loginButton).click();
  }
}

export const loginPage = new LoginPage();

cypress/e2e/login.spec.ts

import { loginPage } from '../pages/loginPage';

describe('Login Test', () => {
  it('should login with valid credentials', () => {
    cy.visit('/login');
    loginPage.enterUsername('testuser');
    loginPage.enterPassword('password123');
    loginPage.clickLogin();

    cy.url().should('include', '/dashboard');
  });
});

cypress/fixtures/user.json

{
  "username": "testuser",
  "password": "password123"
}

.github/workflows/nightly-build.yml

name: Nightly Build

on:
  schedule:
    - cron: "0 0 * * *" # Every day at midnight

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 16

      - name: Install dependencies
        run: npm install

      - name: Run Cypress tests
        run: npx cypress run

.github/CODEOWNERS

# Define code owners
* @your-github-username

.github/pull_request_template.md

## Description
- [ ] Does this PR address the issue or add a new feature?

## Checklist
- [ ] Code is tested
- [ ] Documentation is updated

## How to Test
Provide steps to test your changes.

.gitignore

# Logs
logs/
*.log

# Dependency directories
node_modules/

# Cypress artifacts
cypress/screenshots/
cypress/videos/

# Build output
dist/

# Environment files
.env

README.md

# Cypress TypeScript Project

## Description
This project demonstrates a test automation framework using Cypress, TypeScript, and the Page Object Model.

## Features
- TypeScript for strong typing
- Page Object Model for test scalability
- GitHub workflows for CI/CD

## Setup
1. Clone the repository.
2. Run `npm install` to install dependencies.
3. Run `npm test` to execute tests.

## Folder Structure
- `cypress/e2e`: Test files
- `cypress/pages`: Page objects
- `cypress/fixtures`: Test data
- `.github`: CI/CD configuration

This structure is designed to be modular, scalable, and easy to maintain, with practical examples for each file type. Let me know if you’d like further customization!