JSPM

  • Created
  • Published
  • Downloads 13
  • Score
    100M100P100Q63898F
  • License MIT

Extends the functinality of Cypress to ease its usage.

Package Exports

  • cypress-extender

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cypress-extender) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

cypress-extender

Cypress Extender, extends the basic functinality of Cypress to ease its usage.

Why

In the usual cy.get , every test fails, when element doesn't exist.

Where sometimes, we want to test cases where element doesn't exist, or we want to wait while while the element doesn't exist

i.e. open dropdown and wait for inner element to be created there, to identify, it's opened

With Cypress Extender it's possible, in fact we can use an if ccondition, or while loop, to test condition of element

Prerequisites

In order to use this plugin:

  • Cypress must be installed.

Installation

To install the plugin to your project please use:

npm install cypress-extender

in order to also add it to your package.json file so you can use:

npm install --save-prod cypress-extender

Manual

Once Cypress Extender is installed,

there are 2 main options to use this plugin

  • initCypress - adds this plugin's commands to cypress
  • load and use specific function - doesn't change anything in cypress commands

initCypress

in order to load all the extender commands to cypress use:

const { initCypress } = require('cypress-extender');
initCypress();

or alternativly:

import { initCypress } from 'cypress-extender';
initCypress();

in both ways, you'll get many new functions added to cypress, such as:

        cy.exists('body').should('be.true');
        cy.exists('bodyy').should('be.false'); 
        cy.isVisible('body').should('be.true');
        cy.isVisible('bodyy').should('be.false'); 
        cy.hasText('body', 'default blank page').should('be.true');
        cy.hasText('body', 'default blanket page').should('be.false');        

and many more options, as you can find below, in this page.

Load required function

If you decide, that you don't want to change anything in cypress commands, however you want to test boolean cases in if statement, or wait for a condition in a while loop, this is probably the better option for you.

in order to load specific function, use:

const { exists } = require('cypress-extender');

or alternativly:

import { exists } from 'cypress-extender';

in both ways you'll be able to test things like:

if (exists('body')) { /* DO SOMETHING */ }
while (exists('body')) { /* DO SOMETHING */ }
for (let i = 0; i <  SOME_MAX_TRIES && exists('body'); i++ ) {
    /* DO SOMETHING */
}

so you'll be able for example to implement something like

const isOpened = () => exists(' SELECTOR THAT APPEARS WHEN OPENED');
const openDropDown = !isOpened() && cy.get('SOME SELECTOR TO OPEN').click();

Also here we support visible in a differnt way, than the usual cy.get('SELECTOR').should('be.visible');

what if, for example you want to wait for element to exist and to be visible, now you can. Simply use something like:

import { isVisible } from 'cypress-extender';
while (isVisible('SELECTOR OF ELEMENT')) {
    /* DO SOMETHING */
}

very simple to use, and should make cypress code much easier to use.

Supported functions

    </tbody>
</table>

there are more options available for this plugin, and hopefully I will find some time to update all of them here.
function what is it
exists element should exist, in DOM
isVisible exists in DOM and visible
isCheckbox element exists and is a checkbox
isChecked element exists and is checked
contains element exists and its text contains GIVEN TEXT, this function get 2 arguments cssSelector, text
equals element exists and its text equals to GIVEN TEXT, this function get 2 arguments cssSelector, text(element should be equal to)
isEmpty element exists and has no children
hasNoChildren element exists and has no children
isDisabled element exists and is disabled
isEnabled element exists and is enabled (not disabled)
isFile element exists and is of type file (mostly input[type=file])
isFirstChild element exists and is the first child of its parent element
isFocused element exists and is in focus state
hasSelector element exists and has among its descendants element that matches the css selector
isHeader element exists and is of type header (h1, h2, h5 ...)
isHidden element exists and is hidden
isImage element exists and is of type image
isInput element exists and is of type input
isAnimated element exists and is recognized as running some animation (by JQuery)
isButton element exists and is of type button