chai-webdriver

selenium-webdriver を利用した、Chai アサーションライブラリの拡張機能を提供します。表現力の豊かな統合テストを作成できます。
expect('.frequency-field').dom.to.contain.text('One time')
expect('.toggle-pane').dom.to.not.be.visible()
どのようなアサーションを行うことができますか?
すべてのアサーションは、Sizzle 互換の CSS セレクタから始まります。例えば
expect('.list')
expect('div > h1')
expect('a[href=http://google.com]')
次に、`dom` フラグを追加します。
expect(selector).dom
最後に、アサーションをチェーンに追加します。
expect(selector).dom.to.have.text('string')
- DOM のテキスト値を指定された文字列と比較します。完全一致のみ。expect(selector).dom.to.contain.text('string')
- DOM のテキスト値を指定された文字列と比較します。部分一致も許容。expect(selector).dom.to.match(/regex/)
- DOM のテキスト値を正規表現と比較します。expect(selector).dom.to.have.text(/regex/)
- DOM のテキスト値を正規表現と比較します。(上のmatch
と同じ)。expect(selector).dom.to.be.visible()
- 要素が表示されているかどうかを確認します。expect(selector).dom.to.be.disabled()
- フォーム要素が無効化されているかどうかを確認します。expect(selector).dom.to.have.count(number)
- 指定されたセレクタを持つ DOM に存在する要素の数をテストします。expect(selector).dom.to.have.style('property', 'value')
- 要素の CSS スタイルをテストします。現状では完全一致のみ。expect(selector).dom.to.have.value('string')
- フォームフィールドの値を指定された文字列と比較します。expect(selector).dom.to.have.htmlClass('warning')
- 要素がwarning
をクラス属性の一つとして持っていることをテストします。expect(selector).dom.to.have.attribute('attribute', 'value')
- 要素のattribute
をvalue
と完全一致でテストします。value
を省略すると、属性の存在のみをチェックします。expect(selector).dom.to.have.attribute('attribute', /regex/)
- 要素のattribute
を正規表現とテストします。
アサーションを否定するには、常にnot
を追加できます。
expect(selector).dom.not.to.have.style('property', 'value')
非同期処理
これらのアサーションはすべて非同期(selenium-webdriver のプロミスチェーンを使用)であるとみなされます。すべてコールバックを受け取るか、プロミスとチェーンすることができます。例えば
expect(selector).dom.to.have.text('string', function(){...})
expect(selector).dom.to.have.text('string').then(function(){...})
セットアップ
セットアップはとても簡単です。
// Start with a webdriver instance:
var sw = require('selenium-webdriver');
var driver = new sw.Builder()
.withCapabilities(sw.Capabilities.chrome())
.build()
// And then...
var chai = require('chai');
var chaiWebdriver = require('chai-webdriver');
chai.use(chaiWebdriver(driver));
// And you're good to go!
driver.get('http://github.com');
chai.expect('#site-container h1.heading').dom.to.not.contain.text("I'm a kitty!");
コントリビュート
とても簡単です。
npm install # download the necessary development dependencies
npm run-script build # compile coffee-script into javascript
npm test # build and run the specs
ライセンス
MIT.