All Projects → san650 → cypress-page-object

san650 / cypress-page-object

Licence: MIT license
Represent the screens of your website as a series of objects in your Cypress test suite

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to cypress-page-object

babel-plugin-remove-test-ids
🐠 Babel plugin to strip `data-test-id` HTML attributes
Stars: ✭ 40 (+73.91%)
Mutual labels:  e2e-tests, e2e, cypress
Sakuli
Sakuli is an end-2-end testing and monitoring tool for web sites and common UIs with multiple monitoring integrations
Stars: ✭ 115 (+400%)
Mutual labels:  e2e-tests, e2e
expo-detox-typescript-example
Sample Expo app with e2e tests using detox, jest and typescript
Stars: ✭ 81 (+252.17%)
Mutual labels:  e2e-tests, e2e
jest-retry
Jest retry pattern for flaky E2E tests
Stars: ✭ 36 (+56.52%)
Mutual labels:  e2e-tests, e2e
cypress-xhr-responses-recording
No description or website provided.
Stars: ✭ 19 (-17.39%)
Mutual labels:  e2e, cypress
ionic-workflow-guide
Create a full and powerful worflow with Ionic (Unit Testing, Environment variables, Automatic documentation, Production App Server, Automatic deployment)
Stars: ✭ 46 (+100%)
Mutual labels:  e2e-tests, e2e
Cypress
Fast, easy and reliable testing for anything that runs in a browser.
Stars: ✭ 35,145 (+152704.35%)
Mutual labels:  e2e-tests, cypress
playwright-ci
☁️ Set up Playwright in CI
Stars: ✭ 27 (+17.39%)
Mutual labels:  e2e-tests, e2e
Pending Xhr Puppeteer
Small tool to wait that all xhr are finished in puppeteer
Stars: ✭ 227 (+886.96%)
Mutual labels:  e2e-tests, e2e
Cypress Example Recipes
Various recipes for testing common scenarios with Cypress
Stars: ✭ 2,485 (+10704.35%)
Mutual labels:  e2e-tests, cypress
cypress-browser-permissions
A Cypress plugin to set launched browser preferences including permissions like Geolocation, Notifications, Microphone, etc.
Stars: ✭ 40 (+73.91%)
Mutual labels:  e2e, cypress
IridiumApplicationTesting
A&G Web Application Testing Suite
Stars: ✭ 19 (-17.39%)
Mutual labels:  e2e-tests, e2e
Recorder
A browser extension that generates Cypress, Playwright and Puppeteer test scripts from your interactions 🖱 ⌨
Stars: ✭ 277 (+1104.35%)
Mutual labels:  e2e, cypress
curso-javascript-testes
Código-fonte do curso "Aprenda a testar Aplicações Javascript"
Stars: ✭ 60 (+160.87%)
Mutual labels:  e2e-tests, e2e
odoo-cypress
Odoo Framework E2E Testing using Cypress
Stars: ✭ 19 (-17.39%)
Mutual labels:  e2e, cypress
Javascript Testing Best Practices
📗🌐 🚢 Comprehensive and exhaustive JavaScript & Node.js testing best practices (August 2021)
Stars: ✭ 13,976 (+60665.22%)
Mutual labels:  e2e-tests, e2e
cygger
Boilerplate generator for API Testing from Swagger to Cypress
Stars: ✭ 20 (-13.04%)
Mutual labels:  e2e, cypress
cypress-maildev
Cypress Maildev is a bunch of Cypress commands in order to test your messages (SMS and Emails) by using Maildev REST API.
Stars: ✭ 19 (-17.39%)
Mutual labels:  e2e, cypress
wongames
🎮 Ecommerce de jogos no estilo Steam. Desenvolvido com Next.js, TypeScript, GraphQL, etc.
Stars: ✭ 18 (-21.74%)
Mutual labels:  cypress
saloon
An E2E test seeder for enterprise web applications
Stars: ✭ 30 (+30.43%)
Mutual labels:  e2e-tests

Cypress Page Object

Represent the screens of your website as a series of objects in your Cypress test suite. This library addon eases the construction of these objects for your acceptance/integration/end to end tests.

Table of content

Quick Start

Install the library using npm

$ npm install --save-dev cypress-page-object

After installing the library you can create a page object inside your project.

Let's assume the website you want to test has a http://example.com/login.html page, we can test a failed login. Create a new integration and define a page object as follows.

import { page, visitable, fillable, clickable } from "cypress-page-object";

const loginPage = page({
  visit: visitable('/login'),
  fillUsername: fillable('#username'),
  fillPassword: fillable('#password'),
  submit: clickable('[type="submit"]'),

  errorMessage() {
    return cy.get('.error-message');
  }
});

context('My Awesome WebSite', () => {

  it('logs into the website', () => {
    loginPage
      .visit()
      .fillUsername('[email protected]')
      .fillPassword('wrong password')
      .submit()
      .errorMessage()
      .should('contain', 'Wrong username and password');
  });

});

As you can see, by having a page object we extract away the CSS selectors from the test making it more readable.

What is a Page Object?

An excerpt from the Selenium Wiki

Within your web app's UI there are areas that your tests interact with. A Page Object simply models these as objects within the test code. This reduces the amount of duplicated code and means that if the UI changes, the fix need only be applied in one place.

The pattern was first introduced by the Selenium

You can find more information about this design pattern here:

API

page

Creates a new page object. The new page object contains some utilities to make your tests a bit more DRY and easier to read.

Example

import { page, visitable, fillable, clickable } from "cypress-page-object";

const loginPage = page({
  visit: visitable('/login'),
  fillUsername: fillable('#username'),
  fillPassword: fillable('#password'),
  submit: clickable('[type="submit"]'),

  errorMessage() {
    return cy.get('.error-message');
  }
});

context('My Awesome WebSite', () => {

  it('logs into the website', () => {
    loginPage
      .visit()
      .fillUsername('[email protected]')
      .fillPassword('wrong password')
      .submit()
      .errorMessage()
      .should('contain', 'Wrong username and password');
  });

});

You can add any property to your page object and they will be accessible from your tests.

import { page } from "cypress-page-object";

const loginPage = page({});

loginPage.should('contain', 'My text');

clickable

Clicks a button or input

Example

import { page, clickable } from "cypress-page-object";

const login = page({
  submit: clickable('button[type="submit"]')
});

login.submit();
Parameter Type Description
selector string CSS selector of the element to click

fillable

Fills an input with text

Example

import { page, fillable } from "cypress-page-object";

const login = page({
  username: fillable('input#username')
  password: fillable('input#password')
});

login
  .username("[email protected]")
  .password("secret");
Parameter Type Description
selector string CSS selector of the input element
options object Additional options
options.isHidden boolean True to force write hidden inputs

visitable

Loads a page

Example

import { page, visitable } from "cypress-page-object";

const login = page({
  visit: visitable('/login')
});

login.visit();
cy.url().should('include', '/form')
Parameter Type Description
path string Full path of the page to load

Development

TBA

License

cypress-page-object is licensed under the MIT license.

See LICENSE for the full license text.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].