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()
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 clickableawait expect(selector).to.be.displayed()
- Test whether or not [at least one] matching element is displayedawait expect(selector).to.be.displayedInViewport()
- Test whether or not [at least one] matching element is displayed in viewportawait expect(selector).to.be.existing()
- Test whether [at least one] matching element exists in the DOMawait expect(selector).to.be.focused()
- Test whether or not [at least one] matching element is focusedawait expect(selector).to.be.selected()
- Test whether or not [at least one] matching element is selectedawait 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 exactlyawait 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 matchesawait 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 matchesawait 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 orderawait expect(selector).text.to.satisfy(fn)
- Test thatfn
returnstrue
when called with the array of texts of the selected elementsawait expect(selector).to.have.attribute('attributeName')
- Test whether [at least one] matching element has the given attributeawait 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 exactlyawait 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 exactlyawait expect(selector).to.have.count(n)
- Test that exactlyn
elements exist in the DOM with the supplied selectorawait expect(selector).to.have.count.above(n)
- Test that more thann
elements exist in the DOM with the supplied selectorawait expect(selector).to.have.count.below(n)
- Test that less thann
elements exist in the DOM with the supplied selectorawait expect(selector).to.have.count.at.least(n)
- Test that at leastn
elements exist in the DOM with the supplied selectorawait expect(selector).to.have.count.at.most(n)
- Test that at mostn
elements exist in the DOM with the supplied selectorawait expect(selector).to.have.value('string')
- Test that [at least one] selected element has a value matching the given stringawait expect(selector).to.have.value(/regex/)
- Test that [at least one] selected element has a value matching the given regular expressionawait 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 orderawait expect(selector).value.to.satisfy(fn)
- Test thatfn
returnstrue
when called with the array of values of the selected elementsawait expect(selector).to.have.focus()
- (alias forto.be.focused()
)
You can also always add a not
in there to negate the assertion:
await expect(selector).not.to.have.text('property')
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.
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 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!")
Only intended to be compatible with Webdriver 5/6 right now.
Requires Node.js 8.x
Contributors:
- @mltsy :
exist
,text
assertions, documentation & test adjustments
Apache 2.0