npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chai-webdriverio-async

v3.0.0

Published

chai assertions for webdriverio without node-fibers

Downloads

1,557

Readme

chai-webdriverio-async

CircleCI Coverage Status semantic-release Commitizen friendly npm version

Async fork of chai-webdriverio.

Provides async webdriverio sugar for the Chai assertion library. Allows you to create expressive integration tests:

await expect('.frequency-field').to.have.text('One time')
await expect('.toggle-pane').to.not.be.displayed()

What sorts of assertions can we make?

All assertions start with a WebdriverIO-compatible selector, for example:

  • expect('.list') (CSS selector)
  • expect('a[href=http://google.com]') (CSS Selector)
  • expect('//BODY/DIV[6]/DIV[1]') (XPath selector)
  • expect('a*=Save') (Text selector)

Then, we can add our assertion to the chain.

  • await expect(selector).to.be.clickable() - Test whether [at least one] matching element is clickable
  • await expect(selector).to.be.displayed() - Test whether or not [at least one] matching element is displayed
  • await expect(selector).to.be.displayedInViewport() - Test whether or not [at least one] matching element is displayed in viewport
  • await expect(selector).to.be.existing() - Test whether [at least one] matching element exists in the DOM
  • await expect(selector).to.be.focused() - Test whether or not [at least one] matching element is focused
  • await expect(selector).to.be.selected() - Test whether or not [at least one] matching element is selected
  • await expect(selector).to.have.text('string') - Test the text value of the selected element(s) against supplied string. Succeeds if at least one element matches exactly
  • await expect(selector).to.have.text(/regex/) - Test the text value of the selected element(s) against the supplied regular expression. Succeeds if at least one element matches
  • await expect(selector).to.have.text(/regex/) - Test the text value of the selected element(s) against the supplied regular expression. Succeeds if at least one element matches
  • await expect(selector).text.to.ordered.include.members(['foo', 'bar']) - Test that the text of the selected elements includes 'foo' followed by 'bar'
  • await expect(selector).text.to.have.members(['foo', 'bar']) - Test that the text of the selected elements is exactly the set ['foo', 'bar'], in any order
  • await expect(selector).text.to.satisfy(fn) - Test that fn returns true when called with the array of texts of the selected elements
  • await expect(selector).to.have.attribute('attributeName') - Test whether [at least one] matching element has the given attribute
  • await expect(selector).to.have.attribute('attributeName', 'string') - Test the attribute value of the selected element(s) against supplied string. Succeeds if at least one element matches exactly
  • await expect(selector).to.have.attribute('attributeName', /regex/) - Test the attribute value of the selected element(s) against supplied regular expression. Succeeds if at least one element matches exactly
  • await expect(selector).to.have.count(n) - Test that exactly n elements exist in the DOM with the supplied selector
  • await expect(selector).to.have.count.above(n) - Test that more than n elements exist in the DOM with the supplied selector
  • await expect(selector).to.have.count.below(n) - Test that less than n elements exist in the DOM with the supplied selector
  • await expect(selector).to.have.count.at.least(n) - Test that at least n elements exist in the DOM with the supplied selector
  • await expect(selector).to.have.count.at.most(n) - Test that at most n elements exist in the DOM with the supplied selector
  • await expect(selector).to.have.value('string') - Test that [at least one] selected element has a value matching the given string
  • await expect(selector).to.have.value(/regex/) - Test that [at least one] selected element has a value matching the given regular expression
  • await expect(selector).value.to.ordered.include.members(['foo', 'bar']) - Test that the value of the selected elements includes 'foo' followed by 'bar'
  • await expect(selector).value.to.have.members(['foo', 'bar']) - Test that the value of the selected elements is exactly the set ['foo', 'bar'], in any order
  • await expect(selector).value.to.satisfy(fn) - Test that fn returns true when called with the array of values of the selected elements
  • await expect(selector).to.have.focus() - (alias for to.be.focused())

You can also always add a not in there to negate the assertion:

  • await expect(selector).not.to.have.text('property')

Assertions on promises resolving to elements

You can also use the same assertions above on promises that resolve to an element or array of elements:

await expect(browser.$('.foo')).to.be.clickable()

This allows you to use the Page Object Pattern.

However, if an assertion fails, the error message won't contain the selector unless you attach it to promise.selector, e.g.:

await expect(
  Object.assign(browser.$('.foo'), { selector: '.foo' })
).to.be.clickable()

Obviously you wouldn't want to do this manually, but rather wrap the browser methods to attach the selector property.

How to wait for one of these conditions to be true?

Just use chai-wait-for and replace expect on any assertion with waitFor, where waitFor is created by calling boundWaitFor.

Do not use implicit wait all all, ever..

Setup

Setup is pretty easy. Just:

var chai = require('chai')
var chaiWebdriver = require('chai-webdriverio').default
chai.use(chaiWebdriver(browser))

// And you're good to go!
await browser.url('http://github.com')
await chai
  .expect('#site-container h1.heading')
  .to.not.contain.text("I'm a kitty!")

Compatability

WebdriverIO

Only intended to be compatible with Webdriver 5/6 right now.

Node.js

Requires Node.js 8.x

Contributors:

  • @mltsy : exist, text assertions, documentation & test adjustments

License

Apache 2.0