我正在尝试使用 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 模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
即使在调用 abort (jQuery) 之后,浏览器也会等待Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在调用 abort (jQuery) 之后,浏览器也会等待 ajax 调用
JavaScript innerHTML 不适用于 IE?JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不适用于 IE?)
XMLHttpRequest 无法加载,请求的资源上不存在“AXMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 无法加载,请求的资
XHR HEAD 请求是否有可能不遵循重定向 (301 302)Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 请求是否有可能不遵循重定向 (301 302))
XMLHttpRequest 206 部分内容XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分内容)
XMLHttpRequest 的 getResponseHeader() 的限制?Restrictions of XMLHttpRequest#39;s getResponseHeader()?(XMLHttpRequest 的 getResponseHeader() 的限制?)