ser*_*gpa 5 cucumber chai protractor chai-as-promised angular
我正在尝试使用 TypScript 编写我的 Cucumber 测试,如下所示:
import { browser, $$ } from 'protractor';
import { Given, Then } from 'cucumber'
import { expect } from 'chai';
Given('I navigate to the homepage', function (callback) {
browser.get('http://localhost:4200');
callback();
});
Then('I want to see the welcome message {string}', function (message, callback) {
expect($$('h1').first().getText()).to.eventually.equal(message).and.notify(callback);
});
Run Code Online (Sandbox Code Playgroud)
然而,量角器抱怨:
错误:无效的柴属性:最终
我怎样才能导入这个?我试过了:
import { eventual } from 'chai-as-promised';
Run Code Online (Sandbox Code Playgroud)
但这不起作用。我怎样才能做到这一点?我还尝试使用 重写Then调用await,但编译器抱怨您不能将回调与异步函数混合使用。啊!
在您的量角器配置中,在onPrepare函数末尾添加以下几行:
onPrepare: function() {
...
// Load chai assertions
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
// Load chai-as-promised support
chai.use(chaiAsPromised);
// Initialise should API (attaches as a property on Object)
chai.should();
}
Run Code Online (Sandbox Code Playgroud)
使用异步函数时,您应该从函数签名中删除回调。
Then('I want to see the welcome message {string}',
async function (message) {
await chai.expect($$('h1').first().getText())
.to.eventually.equal(message);
});
Run Code Online (Sandbox Code Playgroud)