设置 protractor-cucumber e2e Angular 测试并使用 Jasmine?
Setup protractor-cucumber e2e Angular tests and use 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
。实际上,您可以改用其他断言库。
像 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')
我想知道在使用量角器和黄瓜时是否可以使用 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
。实际上,您可以改用其他断言库。
像 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')