Selenium-webdriverテストを作成するために、chai-as-promised + mochaを使用しています。webdriver はpromisesを広範囲に使用するため、これらのタイプのテストには chai-as-promised を使用した方がよいと考えました。
問題は、テストが失敗したときにエラーが mocha によって適切にキャッチされず、何も出力せずに失敗することです。
サンプルコード:
it 'tests log', (next) ->
log = @client.findElement(By.css("..."))
Q.all([
expect(log.getText()).to.eventually.equal("My Text")
expect(log.findElement(By.css(".image")).getAttribute('src'))
.to.eventually.equal("/test.png")
]).should.notify(next)
文書化された動作によると、期待が失敗した場合、chai-as-promisedはエラーを mocha に渡す必要があります。右?
バリエーションとして、
私もこれらを試しましたが、役に立ちませんでした:
#2
# same, no error on failure
it 'tests log', (next) ->
log = @client.findElement(By.css("..."))
Q.all([
expect(log.getText()).to.eventually.equal("My Text")
expect(log.findElement(By.css(".image")).getAttribute('src'))
.to.eventually.equal("/test.png")
]).should.notify(next)
#3
# same, no error shown on failure
it 'tests log', (next) ->
log = @client.findElement(By.css("..."))
expect(log.getText()).to.eventually.equal("My Text")
.then ->
expect(log.findElement(By.css(".image")).getAttribute('src'))
.to.eventually.equal("/test.png").should.notify(next)
#4
## DOES NOT EVEN PASS
it 'tests log', (next) ->
log = @client.findElement(By.css("..."))
Q.all([
expect(log.getText()).to.eventually.equal("My Text")
expect(log.findElement(By.css(".image")).getAttribute('src'))
.to.eventually.equal("/test.png")
])
.then ->
next()
.fail (err) ->
console.log(err)
.done()