1.1.1 • Published 29 days ago

cypress-page-object-model v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
29 days ago

Cypress-POM-Ready-To-Use (2024 Edition)

A production-ready Cypress automation framework with Page Object Model, supporting both UI and API testing.

Key Features

  • TypeScript support with type definitions
  • Page Object Model implementation
  • API testing capabilities with custom commands
  • Parallel test execution
  • CI/CD ready with GitHub Actions
  • Environment-based configuration
  • Comprehensive reporting
  • Built-in retry mechanisms for flaky tests

Quick Start

  1. Clone and Install
git clone https://github.com/padmarajnidagundi/Cypress-POM-Ready-To-Use
cd Cypress-POM-Ready-To-Use
npm install
  1. Run Tests
npm run test:ui          # Run UI tests
npm run test:api         # Run API tests
npm run test:parallel    # Run all tests in parallel
npm run test:ci         # Run tests in CI mode

For QA Engineers

Writing UI Tests

  1. Create Page Objects
// cypress/pageObjects/pages/loginPage.ts
import BasePage from '../basePage'

class LoginPage extends BasePage {
    private selectors = {
        username: '#username',
        password: '#password',
        submitBtn: '[data-testid="login-btn"]'
    }

    login(username: string, password: string) {
        this.getElement(this.selectors.username).type(username)
        this.getElement(this.selectors.password).type(password)
        this.getElement(this.selectors.submitBtn).click()
    }
}
  1. Write Tests
// cypress/e2e/ui/login.cy.ts
import LoginPage from '../../pageObjects/pages/loginPage'

describe('Login Tests', () => {
    const loginPage = new LoginPage()
    
    beforeEach(() => {
        loginPage.visit('/login')
    })

    it('should login successfully', () => {
        loginPage.login('testuser', 'password')
        // assertions
    })
})

Writing API Tests

  1. Use Built-in Commands
// cypress/e2e/api/users.cy.ts
describe('Users API', () => {
    it('should create a new user', () => {
        cy.request({
            method: 'POST',
            url: '/api/users',
            body: {
                name: 'Test User',
                role: 'QA'
            }
        }).then(response => {
            expect(response.status).to.eq(201)
        })
    })
})

Best Practices

  1. Selectors

    • Use data-testid attributes: [data-testid="login-button"]
    • Store selectors in page objects
    • Use meaningful selector names
  2. Test Organization

cypress/
├── e2e/
│   ├── api/           # API Tests
│   │   ├── users/
│   │   └── auth/
│   └── ui/            # UI Tests
│       ├── login/
│       └── dashboard/
├── pageObjects/
│   ├── components/    # Reusable components
│   └── pages/         # Page specific objects
└── fixtures/          # Test data
  1. Custom Commands
    • Create reusable commands for common operations
    • Use TypeScript for better type checking
    • Document command parameters

Environment Configuration

// cypress.config.js
module.exports = {
  env: {
    apiUrl: 'https://api.dev.example.com',
    userRole: 'admin',
    featureFlags: {
      newUI: true
    }
  }
}

Running Tests in CI

  1. GitHub Actions (pre-configured)
npm run test:ci
  1. Jenkins (sample configuration)
pipeline {
    agent any
    stages {
        stage('Test') {
            steps {
                sh 'npm ci'
                sh 'npm run test:ci'
            }
        }
    }
}

Debugging Tips

  1. Time Travel

    • Use Cypress Time Travel feature
    • Check screenshots in cypress/screenshots
    • Review videos in cypress/videos
  2. Logging

    • Use cy.log() for debug information
    • Enable Chrome DevTools in interactive mode

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Add tests for new features
  4. Submit a pull request

Support

License

MIT License - feel free to use in your projects

Contact

1.1.1

29 days ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.23

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.10

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago