如何将Jasmine与CucumberJS一起使用
How can I use Jasmine with CucumberJS?
如何将茉莉花与cucumberjs搭配使用?
我从中尝试了此解决方案https://stackoverflow.com/a/30763260/5453732
但我一直有这样的错误:TypeError:this.expect(…).toBe不是World中的函数。(/myApp/tests/e2e/steps/main.step.js:33:79)
第39行:
this.expect(element(by.css('[data-el="' + field + '"]')).isPresent()).toBe(true);
app/modules/user/tests/e2e/user.feature
#user.feature
Feature: Login feature
As a user
I want authenticate my account
Scenario: Authentication success
Given I am on "#/" page
Given I check if "navbar-menu-user-module" is visible
Given I wait "3" seconds
/tests/e2e/steps/main.step.js
module.exports = function () {
this.World = require("../support/world.js").World;
this.path = '#/';
this.Given(/^I am on "?([^"]*)"? page$/, function (arg1, callback) {
browser.get(arg1);
callback();
});
this.Given(/^I wait "?([^"]*)"? seconds$/, function (arg1, callback) {
browser.sleep(3000);
callback();
});
this.Given(/^I check if "?([^"]*)"? is visible$/, function (field, callback) {
this.expect(element(by.css('[data-el="' + field + '"]')).isPresent()).toBe(true);
callback();
});
};
/tests/e2e/support/world.js
var World, chai, chaiAsPromised;
chai = require('chai');
chaiAsPromised = require('chai-as-promised');
World = function World(callback) {
chai.use(chaiAsPromised);
this.expect = chai.expect;
callback();
}
module.exports.World = World;
量角器.conf.js
/* protractor.conf.js */
exports.config = {
directConnect: true,
seleniumServerJar: 'node_modules/selenium-server/lib/runner/selenium-server-standalone-2.48.2.jar',
specs: [
'app/modules/user/tests/e2e/*.feature'
],
getPageTimeout: 30000,
capabilities: {
'browserName': 'chrome',
version: '',
platform: 'ANY'
},
onPrepare: function() {
var width = 1024, height = 800;
browser.get('#/');
browser.driver.manage().window().setSize(width, height);
},
framework: 'cucumber',
cucumberOpts: {
require: [
'tests/e2e/steps/main.step.js'
],
format: 'pretty', // or summary
keepAlive: false
},
onCleanUp: function() {}
};
和我的html:
<a data-el="navbar-menu-user-module" href="./#/user">User Module</a>
package.json
{
"name": "myApp",
"version": "1.0.0",
"description": "myApp",
"dependencies": {
},
"devDependencies": {
"chai": "^3.3.0",
"chai-as-promised": "^5.1.0",
"jasmine-core": "~2.3.4",
...
"protractor": "^2.5.1",
"selenium-server": "^2.48.2",
"selenium-standalone": "^4.7.0",
"selenium-webdriver": "^2.48.0",
}
}
需要记住的关键是CucumberJS和Jasmine是互斥的。您只能将Jasmine的expect
与Jasmine框架结合使用。toBe()
是Jasmine的expect
提供的一个函数,它在您的框架中不存在。这就是您收到您描述的错误的原因。
由于您使用CucumberJS来构建测试,因此需要使用一个单独的断言库,最流行的断言库是Chai
。您需要使用Chai
提供的函数来进行断言。在您的情况下,您可能希望使用equal()
函数。还要记住,Protractor的isPresent()
函数返回一个promise,因此您需要使用chai-as-promised
提供的eventually
链。总之,以下断言:
this.expect(element(by.css('[data-el="' + field + '"]')).isPresent()).toBe(true);
应更改为:
this.expect(element(by.css('[data-el="' + field + '"]')).isPresent()).to.eventually.equal(true);
您可以使用我们的jasmine expect库。我们从Jasmine中取出期望库,并将其作为一个单独的模块发布。
https://www.npmjs.com/package/xolvio-jasmine-expect
- 转义符不能与innerHTML一起使用
- 高亮显示与数组字符串一起使用时文本插件中断
- setTimeout可以与闭包内的函数一起使用吗
- 将依赖外部库的UMD模块与browserfy捆绑在一起
- Highcharts colorsByPoint与系列中的线性渐变一起使用时不起作用
- 如何将js库与typescript一起使用
- 将webpack和babel与父项目目录中的文件一起使用
- 将 Drag&Drop 与 jsTree 和 DataTables 一起使用
- Javascript-如何让脚本与Ajax请求的数据一起运行
- 将两个ext.TabPanels滚动到一起
- 将jQuery UI Timepicker Addon与React一起使用
- 什么是curl以及如何将其与nodejs一起使用
- Javascript”;onmousemove”;事件无法与类一起使用
- 将require('..')与变量一起使用与在webpack中使用字符串相比
- 如何在php中创建一个函数,该函数与文本区域一起工作,通过输入类似[color:red]的内容来打印具有等效颜色的文本
- 三角库可以与firefox一起使用,但不能在Chrome中使用
- 为什么不't我的ruby代码与javascript文件一起插入
- 通过jQueryAjax一起发布Array和Form数据时出现问题
- 如何将Jasmine与CucumberJS一起使用
- 如何检查复选框是否与Protractor、CucumberJS和Chai一起选中