chai-webdriver-exec ビルドステータス

selenium-webdriverChai で実行されたスクリプトのアサーションをサポートします。このプラグインは DOM ベースのアサーションでのみサポートを追加する chai-webdriver プラグインを補完します。

アサーション

すべてのアサーションは exec メカニズムを使用し、chai.expect() と連携します。

chai.expect('return document.childElementCount').exec.to.equal(1)
chai.expect('return document.childElementCount').exec.to.exist

実行されるスクリプトは chai.expect() の最初の引数であり、executeScript() に渡されます。アサーションが機能するには、スクリプトには戻り値が必要です。

可能なアサーションの一覧については、テストファイル を参照してください。基本的に すべての BDD アサーション は、次のものを除いてサポートされています:argumentsitselfextensiblesealedfrozenthrowrespondTochangeincreasedecrease (スクリプトをリモートで実行する性質のため)。

非同期フロー

これらのアサーションはすべて非同期であると推定されます (selenium-webdriver の promise チェーンを使用)。これらのアサーションはすべてコールバックを取るか、promise とチェーンすることができます。たとえば

expect(script).exec.to.have.ownProperty('string', function(){...})
expect(script).exec.to.have.ownProperty('string').then(function(){...})

selenium-webdriver/testing ラッパーを使用する場合、この使用法は不要です。

使用方法

npm i --save-dev chai-webdriver-exec

次にテストファイルで

var chaiWebdriverExec = require('chai-webdriver-exec')
chai.use(chaiWebdriverExec(driver))

var webdriver = require('selenium-webdriver'),
  test = require('selenium-webdriver/testing')
var driver = new webdriver.Builder()
  .forBrowser('firefox')
  .build()

var chai = require('chai')
var chaiWebdriverExec = require('chai-webdriver-exec')
chai.use(chaiWebdriverExec(driver)) // here you hook it up

test.describe('some cool feature', function() {
  this.timeout(10000)
  
  test.it('should work as expected', function() {
    driver.get('http://github.com');
    chai.expect('return window.scrollX').to.be.a('number')
  })
})

テスト

npm test