Adds XPath command to Cypress test runner
Clone or download

README.md

cypress-xpath CircleCI renovate-app badge

Adds XPath command to Cypress.io test runner

Install

npm install -D cypress-xpath

Then include in your project's cypress/support/index.js

require('cypress-xpath')

Use

After installation your cy object will have xpath command.

it('finds list items', () => {
  cy.xpath('//ul[@class="todo-list"]//li')
    .should('have.length', 3)
})

note: you can test XPath expressions from DevTools console using $x(...) function, for example $x('//div') to find all divs.

See cypress/integration/spec.js

Roadmap

  • wrap returned DOM nodes in jQuery #2
  • retry the assertion that follows #3
  • add TypeScript definitions #4
  • search from the previous subject element #5
  • log or not, depending on user option #19

License

This project is licensed under the terms of the MIT license.