我希望使用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'
}
};
Run Code Online (Sandbox Code Playgroud)
如您所见,该项目使用"黄瓜"作为框架.如何在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
Run Code Online (Sandbox Code Playgroud)
/ path/to/myproj/features/stepDefinitions.js
module.exports = function() {
this.Given(/^some precondition$/, function (callback) {
expect(true).toEqual(true);
callback();
});
};
Run Code Online (Sandbox Code Playgroud)
当执行此操作时,"expect"未定义,可能是因为Jasmine尚未集成,并且它期望全局化.这是完整的错误消息:
$ $(npm bin)/protractor protractor.conf.js
Starting …Run Code Online (Sandbox Code Playgroud) 我在karma-jasmine上调用命令行选项时遇到问题,该选项只允许执行那些匹配给定模式的测试.我的规范如下:
/ path/to/single-test/main.spec.js
describe('my first test suite', function() {
it('always passes', function() {
expect(true).toBe(true);
});
it('still always passes', function() {
expect(true).toBe(true);
});
});
Run Code Online (Sandbox Code Playgroud)
我假设描述(例如"仍然总是通过")是与grep命令行选项指定的模式匹配的项目.当我尝试运行第二个例子时,它的描述是唯一包含单词"still"的例子,两个例子都被执行而不是只执行一个:
$ karma start -- --grep=still
INFO [karma]: Karma v0.12.35 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Linux 0.0.0)]: Connected on socket 7Dn7Ez1Reap7ch0Uzsb0 with id 44623726
PhantomJS 1.9.8 (Linux 0.0.0): Executed 2 of 2 SUCCESS (0.002 secs / 0.001 secs)
Run Code Online (Sandbox Code Playgroud)
如何基于模式执行这一个示例?在官方文档不给模式匹配选项的使用的样本.
我在拉动请求的讨论中读到,grep选项可以与"fit"和"fdescribe"结合使用.这在测试时有效.但是,在使用grep with"fit"的情况下,grep选项的pattern参数的目的是什么?(能够有选择地执行测试而不需要增加源代码会很好!)
以下是我项目中的其余文件供参考:
/ …
command-line pattern-matching jasmine karma-runner karma-jasmine
在AngularJS中,一个指令如何使用基于事件的通信($emit,$broadcast和$on)与另一个具有隔离范围的指令进行通信?我已经创建了两个指令,当从第二个指令中删除隔离范围时,第一个指令能够使用emit成功地与第二个指令进行通信.但是,当隔离范围添加回第二个时,通信会中断.
var app = angular.module('myApp', []);
app.directive("firstDir", function() {
return {
restrict: 'E',
controller: function($scope) {
$scope.set = function() {
$scope.$emit('MY_NEW_SEARCH', $scope.searchQuery);
}
},
template: '<input type="text" ng-model="searchQuery"><button ng-click="set()">Change Value</button>'
};
});
app.directive("secondDir", function() {
return {
restrict : 'E',
scope: {},
controller : function($scope) {
var _that = $scope;
$scope.$on('MY_NEW_SEARCH', function(e, data) {
_that.data = data;
});
$scope.data = 'init value';
}
};
});
Run Code Online (Sandbox Code Playgroud)
我创建了一个Plunker来说明问题.您会注意到,如果您在第二个指令的指令定义对象中注释掉"scope"属性,则通信可以正常工作:您可以在第一个指令的输入框中键入一个字符串,按下第一个指令的按钮指令,并将字符串传递给第二个指令,该指令将其显示在视图上.(就目前而言,由于隔离范围问题,Plunker已损坏,请参阅app.js文件的第19行.)
http://plnkr.co/edit/AXUVX9zdJx1tApDhgH32
这是我的首要目标:我为第二个指令使用隔离范围的原因是将范围内部与范围外部区分开来.(我的项目中使用的实际"第二指令"比这个玩具示例复杂得多.这就是必要的.)我知道AngularJS提供了将外部范围映射到指令内部范围的机制.我很好奇这些机制中的任何一个对于映射基于事件的通信事件是否有用.
如果答案结果是隔离范围对于基于事件的通信是不可克服的,那么在我已经说明的情况下完成指令通信指令的最佳方法是什么,同时仍然实现我的目标?谢谢!
angularjs ×2
jasmine ×2
command-line ×1
cucumber ×1
emit ×1
karma-runner ×1
protractor ×1
testing ×1