【发布时间】:2014-01-22 18:44:27
【问题描述】:
我正在使用 chai-as-promised + mocha 来编写一些 selenium-webdriver 测试。由于 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)
根据documented behaviour,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()
【问题讨论】:
标签: selenium testing mocha.js chai chai-as-promised