Setting an Angular model using Protractor(使用 Protractor 设置 Angular 模型)
问题描述
我正在尝试使用 Protractor 在我的网站上模拟用户故事.
I'm trying to emulate a user story on my website with Protractor.
用户必须输入使用自动完成的输入.在现实生活中,用户必须在输入中键入一些文本,然后使用鼠标或更自然地使用向下箭头键选择正确的命题.
The user has to type in an input that uses auto-completion. In real life, the user has to type some text in the input, then select the right proposition with either her mouse or more naturally her downarrow key.
问题是我似乎无法用 Protractor 模拟它.element.sendKeys 只是不允许您这样做.我已经尝试了十几种不同的方式,但充其量只能产生不可预测的结果.
The problem is that I can't seem to simulate that with Protractor. element.sendKeys just does not allow you to do that. I have tried in a dozen different manners and it yields unpredictable results at best.
所以我想直接操作我输入的 ng-model.有没有办法从量角器访问元素的范围并在其上调用函数/设置属性?
So I would like to manipulate the ng-model behing my input directly. Is there a way to access the scope of an element from Protractor and call functions/set properties on it?
这是我的问题的简化版本:
Here is a simplified version of my problem :
查看:
<div ng-controller="MyController">
<input id="my-input" ng-model="myModel"/>
</div>
控制器:
myModule.controller('MyController', ['$scope', function($scope){
$scope.myModel = "";
//[...]
}]);
e2e 量角器测试:
describe("setting myModel to a fixture value", function(){
it("should set myModel to 'a test value'", function(){
var myInput = element('my-input');
// Now what?
});
});
推荐答案
你可以使用.evaluate()
直接设置你的模型值:
You can use .evaluate()
to set your model value directly:
var elm = element(by.model("obj.field"));
elm.evaluate("obj.field = 'test';");
获取模型值:
elm.evaluate("obj.field").then(function (value) {
console.log(value);
});
这篇关于使用 Protractor 设置 Angular 模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Protractor 设置 Angular 模型


基础教程推荐
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01