【发布时间】:2018-07-27 20:10:50
【问题描述】:
我正在尝试使用 selenium、mocha 和 chai-as-promised 测试 Web 应用程序。我似乎无法让 mocha 等待 chai-as-promised 断言得到解决。我的测试代码如下所示:
var selenium = require('selenium-webdriver')
var By = selenium.By
var chai = require('chai')
var cap = require('chai-as-promised')
chai.use(cap)
expect = chai.expect
describe('Test Group', function() {
var driver
before(function() {
driver = new selenium.Builder()
.withCapabilities(selenium.Capabilities.chrome())
.build()
driver.getWindowHandle()
})
after(function() {
driver.sleep(500).then(function() {
driver.quit()
})
})
describe('Authentication', function() {
describe('#login redirect', function() {
it('should redirect to /users/login when not logged in', function() {
driver.get('http://127.0.0.1:3000/')
driver.sleep(500).then(function() {
return expect(driver.getCurrentUrl()).to.eventually.contain('WONT CONTAIN THIS')
})
})
})
})
})
测试总是通过,尽管断言无法通过。测试也会返回这些错误:
Test Group
Authentication
#login redirect
✓ should redirect to /users/login when not logged in
1 passing (34ms)
(node:24883) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): AssertionError: expected 'http://127.0.0.1:3000/users/login' to include 'WONT CONTAIN THIS'
(node:24883) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
【问题讨论】:
标签: node.js selenium-webdriver promise mocha.js chai