是否可以从Angular e2e场景执行jQuery命令?如何从Angular e2e测试范围执行jQuery?
例如,如果我想执行:$('.picker-col-id-id').attr('class');
我得到一个错误:
TypeError: Property '$' of object [object Object] is not a function
是否可以从Angular e2e场景执行jQuery命令?如何从Angular e2e测试范围执行jQuery?
例如,如果我想执行:$('.picker-col-id-id').attr('class');
我得到一个错误:
TypeError: Property '$' of object [object Object] is not a function
正如它看起来像jQuery缺少注释中提到。您需要将其添加到您的业力配置文件或直接添加到runner.html。
如果你想将它添加到你的人缘配置文件增加了files
条目添加引用jQuery的,例如,
files = [
ANGULAR_SCENARIO,
ANGULAR_SCENARIO_ADAPTER,
'app/components/jquery/jquery.js', // <== This should point to jQuery
'test/e2e/**/*.js'
];
另外,如果你从runner.html
运行的端到端的测试,你可以加载它在那里,后角和脚本,如前:
<!doctype html>
<html lang="en">
<head>
<title>End2end Test Runner</title>
<script src="../lib/angular/angular-scenario.js" ng-autotest></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="scenarios.js"></script>
</head>
<body>
</body>
</html>
这里的问题是,AngularJs情景测试运行运行在一个iframe应用程序。跑步者本身没有加载jQuery。
最好使用角度场景dsl。从e2e testing docs:
element(selector, label).{method}(key, value)
Executes the method passing in key and value on the element matching the given jQuery selector, where method can be any of the following jQuery methods: attr, prop, css. The label is used for test output.
虽然不是从文档清晰,你也可以使用“ATTR”的方法只有1参数来获得属性的值。
element('.picker-col-id-id').attr('class');
如果需要其他的jQuery的功能,象对焦(),你可以这样来做:
element('.picker-col-id-id').query(function(elements, done) {
elements.focus();
done();
});
或延长角DSL
angular.scenario.dsl('jQueryFunction', function() {
return function(selector, functionName /*, args */) {
var args = Array.prototype.slice.call(arguments, 2);
return this.addFutureAction(functionName, function($window, $document, done) {
var $ = $window.$; // jQuery inside the iframe
var elem = $(selector);
if (!elem.length) {
return done('Selector ' + selector + ' did not match any elements.');
}
done(null, elem[functionName].apply(elem, args));
});
};
});
而且使用这种方式:
jQueryFunction('.picker-col-id-id', 'focus');
或一般:
jQueryFunction(selector, jQueryFunctionName, arg1, arg2, ...);
谢谢。浪费了几天的时间寻找这些信息。 – 2013-07-19 15:04:07
因为jQuery不存在。你确定你正确地引用了它吗? – SomeShinyObject 2013-05-06 14:31:07
尝试'jQuery('。picker-col-id-id')'... – 2013-05-06 14:46:24
该解决方案没有帮助,jQuery无法识别e2e范围 – Igal 2013-05-07 06:28:02