Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 量角器-使用动态填充的输入测试角度形状_Angularjs_Protractor_Angularjs E2e - Fatal编程技术网

Angularjs 量角器-使用动态填充的输入测试角度形状

Angularjs 量角器-使用动态填充的输入测试角度形状,angularjs,protractor,angularjs-e2e,Angularjs,Protractor,Angularjs E2e,我正试图为我的角度应用程序编写一个e2e测试,尤其是一个有3个select输入的表单。测试需要从这些选择中随机选择选项。第一个选择已经填充了数据,但其他两个选择在选择前一个时异步填充,因此它们相互依赖 select输入也使用ng disabled,仅当根据ng repeat表达式有可用选项时才启用 我在测试中使用页面对象方法,因此我尝试使用一些实用函数来实现我在测试中需要的随机选择行为: 页面对象: this.selectRandomCustomer = function() {

我正试图为我的角度应用程序编写一个e2e测试,尤其是一个有3个select输入的表单。测试需要从这些选择中随机选择选项。第一个选择已经填充了数据,但其他两个选择在选择前一个时异步填充,因此它们相互依赖

select输入也使用ng disabled,仅当根据ng repeat表达式有可用选项时才启用

我在测试中使用页面对象方法,因此我尝试使用一些实用函数来实现我在测试中需要的随机选择行为:

页面对象:

    this.selectRandomCustomer = function() {
    var option,
      randomIndex;
    this.customerSelect.click();
    this.customerSelectOptions.count().then(function(count) {
      randomIndex = Math.floor(Math.random() * count);
      option = element(by.repeater('customer in vm.customers').row(randomIndex));
      option.click();
    });
  };

  this.selectRandomOrder = function() {
    if(this.orderSelect.isEnabled()===true) {
      var option,
        randomIndex;
      this.orderSelect.click();
      this.orderSelectOptions.count().then(function(count) {
        randomIndex = Math.floor(Math.random() * count);
        option = element(by.repeater('order in vm.orders').row(randomIndex));
        option.click();
      });
    }
  };
鉴于从
customerSelect
中选择一个选项后,
orderSelect
只能在填充选项后被选择,我想知道调用
this.customerSelectOptions.count()
时是否会连接到返回的承诺,因此调用
this.selectrandoorder
,但这似乎是未定义的,因为我从量角器中得到一个错误,它说它找不到
selectrandormorder
函数

现在我只能选择第一个选项,因为它总是在初始页面加载时填充

另外,我不确定使用
isEnabled()
是否真的对我有效,因为我确信这应该会在我的第二次输入中返回true,但如果我将其注销,我会看到false。这在禁用ng时不起作用吗

对于处理最初不会填充数据的表单上的输入,并等待angular获取和填充任何可用选项的最佳实践是什么

谢谢

更新:

我通过调用
getAttribute()
检查
disabled
属性的存在来实现这一点

因此,从
it
块中的spec文件中,我可以调用

page.customerSelect.getAttribute('disabled').then(function(result){
    if(!result) {
        page.selectRandomCustomer();
    }
});

page.orderSelect.getAttribute('disabled').then(function(result){
    if(!result) {
        page.selectRandomOrder();
    }
});
理想情况下,我希望能够在单击selectRandomCustomer中的选项后调用selectRandomOrder:

this.selectRandomCustomer = function() {
    var option,
        randomIndex;
    this.customerSelect.click();
    this.customerSelectOptions.count().then(function(count) {
        randomIndex = Math.floor(Math.random() * count);
        option = element(by.repeater('customer in vm.customer').row(randomIndex));
        option.click();
        //Like to be able to call selectRandomOrder but only after angular has finished performing AJAX request for data and received response
    });
};

this.selectRandomOrder = function() {
    var option,
        randomIndex;
    this.orderSelect.click();
    this.orderSelectOptions.count().then(function(count) {
        randomIndex = Math.floor(Math.random() * count);
        option = element(by.repeater('order in vm.orders').row(randomIndex));
        option.click();
    });
};

我确实尝试调用了
此函数。在
选项之后立即选择RandomOrder
。单击()
,但我收到一个错误,说没有这样的函数,似乎从返回的promise函数回调内部无法访问
此函数。

发布的代码中至少有一个主要问题:

if(this.orderSelect.isEnabled()===true) {
此处
isEnabled()
返回一个承诺。您必须解析它以检查其值:

var self = this;  // saving the page object reference
this.orderSelect.isEnabled().then(function (isEnabled) {
    if (isEnabled) {
        var option,
            randomIndex;
        self.orderSelect.click();
        self.orderSelectOptions.count().then(function(count) {
            randomIndex = Math.floor(Math.random() * count);
            option = element(by.repeater('order in vm.orders').row(randomIndex));
            option.click();
        });
    }
});

啊,是的,好吧,你说至少有一个主要问题。那么我在这里还应该注意些什么呢?Thanks@mindparse这取决于……问题的当前状态是什么?你成功了吗?谢谢。谢谢,我确实让它工作了,但使用了getAttribute()而不是isEnabled()。我想我读到一些关于isEnabled如何与ng disabled一起工作不好的文章。无论如何,将我的更新视为理想情况,我希望从每个promise回调中调用更多函数,以链接对页面对象中函数的调用。这样我就可以有一个名为“selectOptions”的实用函数,我可以从测试规范文件中调用它。