【问题标题】:Failed: Cannot read property 'then' of undefined (protractor)失败:无法读取未定义的属性“then”(量角器)
【发布时间】:2016-12-01 07:58:47
【问题描述】:
       //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 被激活。

通常是禁用的。

错误是

失败:无法读取未定义的属性“then” 堆: TypeError:无法读取未定义的属性“then”

当我改成这个

//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:无法读取未定义的属性“点击”

它不读取我的规范类,它一进入另一个规范。

同样是这样的

            //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();
            })

【问题讨论】:

  • 如何获取元素 createTaskButton ?

标签: angularjs protractor


【解决方案1】:
  1. expect(actual).toBe(expected) 不可用,因为它不返回承诺。
  2. 看来你应该试试ExpectedConditions

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();

【讨论】:

  • 但是当我在这里选择产品var checkedCount = productPage.selectedProducts.count(); expect(checkedCount).toBe(1); 时,它已启用。不需要点击?
  • 从您的帖子中您说 createTaskButton 已禁用,因此您应该等待 createTaskButton 可点击。那个或者你的 createTaskButton 不是一个实际的元素。
  • 我改变了你的,因为它给出了错误量角器。预期条件;但仍然出现错误:`失败:无法读取未定义堆栈的属性“isPresent”:TypeError:无法读取未定义的属性“isPresent”,尽管我没有存在。错误行是browser.wait(EC.elementToBeClickable(productDialogPage.createTaskButton, 4222));
  • 也许了解您如何定义“createTaskButton”也会有所帮助。听起来它在您的 productDialogPage 对象中不存在。
  • @pronto 这是你的问题吗? stackoverflow.com/questions/40909682/…
【解决方案2】:

对我而言,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();
});

【讨论】:

    猜你喜欢
    • 2018-06-15
    • 1970-01-01
    • 2017-04-21
    • 2020-08-22
    • 1970-01-01
    • 2019-08-19
    • 2016-10-23
    • 2014-09-07
    相关资源
    最近更新 更多