失败:无法读取属性'然后'未定义的(量角器)

时间:2016-12-01 07:58:48

标签: angularjs protractor

       //get count of checked checkboxes, 
//count must be 1 because it selected one product
                    var checkedCount = productPage.selectedProducts.count();
                    expect(checkedCount).toBe(1).then(function () {
                        browser.sleep(2222);
                        productDialogPage. createTaskButton.click();
                    });

这是我的代码。当用户选择时,createtaskbutton将变为活动状态。

通常会被禁用。

错误是

  

失败:无法读取属性'然后'未定义的     堆:       TypeError:无法读取属性'然后'未定义的

当我改为

//get count of checked checkboxes, count must 1 be because it selected one product
                var checkedCount = productPage.selectedProducts.count();
                expect(checkedCount).toBe(1);
                browser.sleep(4222);


                //click task create and expect confirm dialog to be displyed
                productDialogPage.createTaskButton.click();



same
  

消息:       失败:无法阅读属性'点击'未定义的     堆:       TypeError:无法读取属性'点击'未定义的

它没有读取我的spec类,它一进入另一个规范。

同样适用于此

            //get count of checked checkboxes, count must 1 be because it selected one product
            var checkedCount = productPage.selectedProducts.count();
            expect(checkedCount).toBe(1);
            browser.sleep(4222);



            browser.wait(function() {
                return productDialogPage.createTaskButton.isPresent();
            })

2 个答案:

答案 0 :(得分:2)

  1. expect(actual).toBe(expected)不可用,因为它不会返回承诺。
  2. 您似乎应该尝试ExpectedConditions
  3. var EC = ExpectedConditions;
    
    //get count of checked checkboxes, 
    //count must be 1 because it selected one product
    var checkedCount = productPage.selectedProducts.count();
    expect(checkedCount).toBe(1);
    
    browser.wait(EC.elementToBeClickable(productDialogPage.createTaskButton, 4222));
    
    //click task create and expect confirm dialog to be displyed
    productDialogPage.createTaskButton.click();
    

答案 1 :(得分:0)

对我来说,ExpectedConditions(http://www.protractortest.org/#/api?view=ProtractorExpectedConditions.prototype.elementToBeClickable)有所帮助,请参阅之前的答案。你必须解决这些承诺。希望能帮助到你! :-)

productPage.selectedProducts.count().then(function(countOfSelectedProducts) {
            expect(countOfSelectedProducts).toBe(1);
            });
        });

// and then wait till your TaskButton is enabled via ExpectedConditions.elementToBeClickable 

var EC = protractor.ExpectedConditions;

browser.wait(EC.elementToBeClickable(productDialogPage.element.createTaskButton()), 10000).then(function() {
        productDialogPage.element.createTaskButton.click();
});