我想知道在使用量角器和黄瓜时是否可以使用茉莉花库。
protractor.conf.js
:
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/features/*.feature'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
cucumberOpts: {
require: './src/steps/**/*.ts',
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
}
};
tsconfig.e2e.json
:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "commonjs",
"target": "es5",
"types": [
"jasmine",
"node"
]
}
}
我的步骤定义:
import { ChangeProfilePage } from './change-profile.po';
import { When, Then, Before } from 'cucumber';
let page: ChangeProfilePage;
Before(() => {
page = new ChangeProfilePage();
page.goToChangeProfile();
page.init();
});
When('The user fills in the form with valid inputs', () => {
page.setFaroId("123BA");
page.setFirstName("Baptiste");
page.setLastName("Arnaud");
page.setEmail("bapt@gaz.com");
page.setAdmin(true);
});
Then('The user clicks on the submit button', () => {
page.submitForm();
});
Then('The user should see the {string} indicator', (string) => {
expect(page.getSubmitMessage()).toEqual(true);
});
它会打印出警告:
DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
它说expect is not defined
。
我在这里做什么错?此外,浏览器将打开,并且不会重定向到所需位置。网址标签中有data:,
。什么意思?
答案 0 :(得分:1)
如果使用Cucumber作为测试框架,则必须先导入Jasmine才能使用。
在给定的代码中,您想在黄瓜测试脚本中使用Jasmine提供的断言api:expect
。实际上,您可以改用其他断言库。
像chai
和chai-as-promised
一样,它们独立于任何测试框架。
// conf.js
exports.config = {
onPrepare: function() {
var chai = require('chai');
chai.use(require('chai-as-promised'));
global.expect = chai.expect;
}
};
// test script
// validate non-promise value (can't use `eventually`)
expect('a string').to.equal('b string');
// validate promise value (must use `eventually`)
expect(xx.getText()).to.eventually.equal('yyyyy')