- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望使用 Protractor、CucumberJS 和 Jasmine 来测试我的项目。如何将 Jasmine 和 CucumberJS 与 Protractor 一起使用?这是我创建的项目设置:
/path/to/myproj/protractor.conf.js
exports.config = {
seleniumServerJar: 'node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar',
specs: [
'features/*.feature'
],
baseUrl: 'http://localhost:8080',
multiCapabilities: [
{
'browserName': 'chrome'
}
],
allScriptsTimeout: 380000,
getPageTimeout: 20000,
framework: 'cucumber',
cucumberOpts: {
require: 'features/stepDefinitions.js',
format: 'summary'
}
};
如您所见,该项目使用“cucumber”作为框架。如何在 CucumberJS 旁边添加 Jasmine 框架?这是通过 Protractor 配置文件还是代码中的其他地方?
/path/to/myproj/features/demo.feature
Feature: Some terse yet descriptive text of what is desired
Scenario: Some determinable business situation
Given some precondition
/path/to/myproj/features/stepDefinitions.js
module.exports = function() {
this.Given(/^some precondition$/, function (callback) {
expect(true).toEqual(true);
callback();
});
};
这个执行的时候,没有定义“expect”,估计是因为Jasmine还没有集成,而expect global也随之而来。这是完整的错误消息:
$ $(npm bin)/protractor protractor.conf.js
Starting selenium standalone server...
[launcher] Running 1 instances of WebDriver
Selenium standalone server started at http://192.168.1.115:59957/wd/hub
(::) failed steps (::)
ReferenceError: expect is not defined
at World.<anonymous> (/path/to/myproj/features/stepDefinitions.js:3:5)
at process._tickCallback (node.js:355:11)
Failing scenarios:
/path/to/myproj/features/demo.feature:3 # Scenario: Some determinable business situation
1 scenario (1 failed)
1 step (1 failed)
Shutting down selenium standalone server.
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1
/path/to/myproj/package.json
{
"name": "myproj",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"cucumber": "0.4.9",
"protractor": "git+https://github.com/angular/protractor.git#0262268fa43b9eefac815d986740efa07bb15818"
}
}
注意:我在我的 package.json 中使用了对 Protractor Git 存储库的特定提交,因为最新版本 (2.1.0) 有 a bug ,这会阻止与 CucumberJS 的集成。
最佳答案
CucumberJS 和 Jasmine 是互斥的;您将无法在 Cucumber 步骤中使用 Jasmine 的预期。您要做的是加载一个单独的期望模块。我会建议 Chai与 chai-as-promised插入。 (chai-as-promised 简化了围绕 promises 编写期望的过程。 Protractor 覆盖 Jasmine 中的 expect()
函数以在幕后为您执行此操作)您很可能希望在你的世界,因为这是在你的步骤定义中提供对它的访问的最简单方法。你的世界看起来像这样:
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;
然后在您的步骤定义文件中,您只需根据 CucumberJS documentation 加载到世界中并且你的步骤定义将被限定为提供对世界所有属性的访问:
module.exports = function() {
this.World = require("path/to/world.js").World;
this.Given(/^some precondition$/, function (callback) {
this.expect(true).to.equal(true);
callback();
});
};
现在,为了一些无耻的 self 推销:如果你将 Protractor 与 CucumberJS 一起使用,我建议你看看我帮助构建的一个名为 CukeFarm 的模块。 .它预配置了一些您会发现有用的模块,并提供了许多可用于大多数项目的通用步骤定义。
关于angularjs - 如何在 Protractor 中使用 Jasmine 和 CucumberJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30740824/
我使用 File > Settings > JavaScript > Libraries 在 Webstorm 8.0.4 中设置 Jasmine 集成。我添加了 karma-jasmine带有我的
假设我有 spyOn($cookieStore,'get').and.returnValue('abc'); 对于我的用例来说,这太笼统了。任何时候我们打电话 $cookieStore.get('so
我正在阅读有关 Jasmine 测试的教程,它建议您应该使用标准 Jasmine 目录树结构(这似乎与 RSpec 目录树结构有关)。我用谷歌搜索了一个小时,找不到任何有关此标准目录树的信息。 考虑到
问题 如何使用Jasmine插件通过Jasmine运行Karma时更新所使用的karma-jasmine的版本? 仅当Jasmine插件集成了较新版本的karma-jasmine时,才会更新Jasmi
我想在每个规范执行后获得测试的通过或失败状态: var passed = jasmine.getEnv().currentSpec.results().passed(); if (!pas
我有一个与 Karma 一起运行的 Jasmine 测试: describe('When a logged in user chooses Rent and Payment PIN is enable
在我的新手理解中,Jasmine 提供了以下语法: describe('FooBar', function(){ it('should blah-blah', function(){ ex
我认为我通过编写这样的 Jasmine 模拟取得了很好的进展。但我无法修复这个错误。 spyOn 方法实际上是如何工作的?事实上这种方法似乎被广泛使用。 2.0 有什么变化 describe('Tes
有大量文档展示了如何将匹配器添加到 Jasmine 规范(例如 here )。 有人找到了向整个环境添加匹配器的方法吗?我想创建一组有用的匹配器,供任何和所有测试调用,而无需在我的规范中复制粘贴。 目
我正在尝试查找所有现有 Jasmine 期望匹配器(例如“toContain”等)的列表... 哪里可以找到这个?我搜索了一段时间,但找不到像 api 这样的东西。 Jasmine 网站也没有任何类型
我熟悉 python 单元测试测试,如果断言失败,该测试将被标记为“失败”,并继续进行其他测试。另一方面,即使其中一个失败, Jasmine 也会继续完成所有期望。如何让 Jasmine 在第一个期望
工具:Protractor 3.3.0、Jasmine 2.4.1、Selenium Standalone Server。 我有一个测试套件,里面有大量的 spec.js 文件,每个文件都包含我的应用
Jasmine 中是否有与 console.log 类似的方法?如果我想注销我 mock 的 $controller 或服务的值,有没有办法做到这一点? 最佳答案 您应该只使用 console.log
我已经通过运行 npm install jasmine -g 全局安装了 jasmine。 运行 jasmine -v 给我 jasmine v2.5.0 jasmine-core v2.5.0 然后
我有gulp-jasmine-phantom正在运行,但我得到 ReferenceError: Tictactoe is not defined 。我感觉我犯了一些根本性的错误。 我的文件结构: gu
我已经创建了一个 JavaScript 项目,需要使用 Jasmine 进行单元测试。我遵循了以下步骤: 1. npm install jasmine --save-dev - 从项目根目录 2.现在
我正在为我的应用程序使用 Yeoman+Angular Generator,我一直在努力与 Jasmine 相处!这就是我卡住的地方。我希望能够在 Jasmine 测试中使用 jQuery 选择器。我
it('should for something', function check(done) { browser.sleep(2000); $('.csTx').isPresent().th
Javascript 编码有点新,所以请耐心等待。 我阅读了以下链接 jasmine with jscoverage automated testing 但是,由于我没有 Ruby 项目,因此它似乎不
在Jasmine headless (headless)Webkit中运行测试时,我遇到了一个简单的TypeError: 'undefined' is not an object失败。但是没有提示在哪
我是一名优秀的程序员,十分优秀!