• <i id='D6BVy'><tr id='D6BVy'><dt id='D6BVy'><q id='D6BVy'><span id='D6BVy'><b id='D6BVy'><form id='D6BVy'><ins id='D6BVy'></ins><ul id='D6BVy'></ul><sub id='D6BVy'></sub></form><legend id='D6BVy'></legend><bdo id='D6BVy'><pre id='D6BVy'><center id='D6BVy'></center></pre></bdo></b><th id='D6BVy'></th></span></q></dt></tr></i><div id='D6BVy'><tfoot id='D6BVy'></tfoot><dl id='D6BVy'><fieldset id='D6BVy'></fieldset></dl></div>
      <bdo id='D6BVy'></bdo><ul id='D6BVy'></ul>
  • <small id='D6BVy'></small><noframes id='D6BVy'>

    <legend id='D6BVy'><style id='D6BVy'><dir id='D6BVy'><q id='D6BVy'></q></dir></style></legend>
      1. <tfoot id='D6BVy'></tfoot>

      2. 使用 Protractor 设置 Angular 模型

        Setting an Angular model using Protractor(使用 Protractor 设置 Angular 模型)
        <tfoot id='E1WuX'></tfoot>
        <i id='E1WuX'><tr id='E1WuX'><dt id='E1WuX'><q id='E1WuX'><span id='E1WuX'><b id='E1WuX'><form id='E1WuX'><ins id='E1WuX'></ins><ul id='E1WuX'></ul><sub id='E1WuX'></sub></form><legend id='E1WuX'></legend><bdo id='E1WuX'><pre id='E1WuX'><center id='E1WuX'></center></pre></bdo></b><th id='E1WuX'></th></span></q></dt></tr></i><div id='E1WuX'><tfoot id='E1WuX'></tfoot><dl id='E1WuX'><fieldset id='E1WuX'></fieldset></dl></div>

          <tbody id='E1WuX'></tbody>

          1. <legend id='E1WuX'><style id='E1WuX'><dir id='E1WuX'><q id='E1WuX'></q></dir></style></legend>

            <small id='E1WuX'></small><noframes id='E1WuX'>

                <bdo id='E1WuX'></bdo><ul id='E1WuX'></ul>

                  本文介绍了使用 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 模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What are valid deviceNames for Chrome emulation testing with Protractor?(使用 Protractor 进行 Chrome 模拟测试的有效设备名称是什么?)
                  Protractor Check if Element Does Not Exist(量角器检查元素是否不存在)
                  Protractor e2e Tests Login Redirection(Protractor e2e 测试登录重定向)
                  Explain about async/ await in Protractor(解释 Protractor 中的 async/await)
                  Protractor browser.wait doesn#39;t wait(量角器 browser.wait 不等待)
                  How to use Protractor with Angular 2?(如何在 Angular 2 中使用量角器?)

                    <tfoot id='o6ZFz'></tfoot>
                          <bdo id='o6ZFz'></bdo><ul id='o6ZFz'></ul>

                          <small id='o6ZFz'></small><noframes id='o6ZFz'>

                          <legend id='o6ZFz'><style id='o6ZFz'><dir id='o6ZFz'><q id='o6ZFz'></q></dir></style></legend>
                            <tbody id='o6ZFz'></tbody>

                            <i id='o6ZFz'><tr id='o6ZFz'><dt id='o6ZFz'><q id='o6ZFz'><span id='o6ZFz'><b id='o6ZFz'><form id='o6ZFz'><ins id='o6ZFz'></ins><ul id='o6ZFz'></ul><sub id='o6ZFz'></sub></form><legend id='o6ZFz'></legend><bdo id='o6ZFz'><pre id='o6ZFz'><center id='o6ZFz'></center></pre></bdo></b><th id='o6ZFz'></th></span></q></dt></tr></i><div id='o6ZFz'><tfoot id='o6ZFz'></tfoot><dl id='o6ZFz'><fieldset id='o6ZFz'></fieldset></dl></div>