设置量角器黄瓜e2e角度测试并使用Jasmine



我想知道在使用量角器和黄瓜时是否可以使用Jasmine库。

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

我做错了什么?此外,浏览器会打开,并且不会重定向到所需的位置。url选项卡中有data:,。这是什么意思?

如果您使用cucumber作为测试框架,则在不导入Jasmine的情况下无法使用它。

在给定的代码中,您希望在黄瓜测试脚本中使用Jasmine提供的断言api:expect。实际上,您可以使用其他断言库。

chaichai-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')

最新更新