abramenal / cypress-shadow-dom

Extend Cypress commands with shadow DOM support
https://npm.im/cypress-shadow-dom
MIT License
49 stars 8 forks source link
cypress cypress-io cypress-plugin cypress-shadow-dom cypressio cypressjs shadow-dom

(deprecated) cypress-shadow-dom

GitHub license npm version All Contributors

Extend Cypress commands with shadow DOM support

This package adds a custom Cypress command that allows you to make an abstraction on how exactly you upload files through you HTML controls and focus on testing the functionality.

Project reached its dead end because of recent feature introduced by @43081j (and reference issue cypress/issues/144).

Please consider using this experimental built-in feature as well as submitting issues and code contributions there.

Warmest thanks for all the contributors that helped this project evolve!

Table of Contents

Installation

The package is distributed via npm should be installed as one of your project's devDependencies:

npm install --save-dev cypress-shadow-dom

Usage

cypress-shadow-dom extends Cypress' cy command. Add this line to your project's cypress/support/commands.js:

import 'cypress-shadow-dom';

Here is a basic example:

cy.shadowGet('todo-list')
  .shadowFind('todo-list-item')
  .its('length')
  .should('eq', 4);

See more usage guidelines in example. It also contains all the available commands in their natural use case.

API

Here's a set of available commands:

shadowGet

Querying shadow DOM elements is made with:

cy.shadowGet(selector, options);

This command returns shadowSubject that is a valid subject to execute any command below.

shadowFind

Additional querying within found shadow DOM elements:

shadowSubject.shadowFind(selector, options);

Example:

cy.shadowGet('todo-list').shadowFind('todo-form');

This command returns shadowSubject that is a valid subject to execute any command below.

In order to set a custom timeout for dynamically loaded elements that appear later than 4 seconds after render, use custom timeout:

cy.shadowGet('todo-list').shadowFind('todo-form', { timeout: 8500 });

shadowEq

To take the nth element from found shadow DOM collection:

shadowSubject.shadowEq(index, options);

shadowFirst

To take the first element from found shadow DOM collection:

shadowSubject.shadowFirst(options);

So, simply:

cy.shadowGet('todo-list')
  .shadowFind('todo-form')
  .shadowFirst();

shadowLast

To take the last element from found shadow DOM collection:

shadowSubject.shadowLast(options);

shadowContains

To validate some element's text content:

shadowSubject.shadowContains(content, options);

shadowTrigger

To trigger any event:

shadowSubject.shadowTrigger(eventName, options);

shadowClick

A shorthand to trigger a click event:

shadowSubject.shadowClick(options);

shadowType

Types some text content inside given shadow DOM input control:

shadowSubject.shadowType(content, options);

Contributors

Thanks goes to these wonderful people (emoji key):


tst

🐛

Joshua de Lange

🐛

Lucas Schnüriger

💻

Milan Andric

📖 🤔

Ryan Wheale

🤔 💻

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT