Protractor.js如何在硬错误重新加载之间等待结果

时间:2015-05-01 00:10:13

标签: javascript angularjs protractor

我必须测试一个流,其中angular必须在重新开始测试返回的页面之前进行硬重定向。

这会导致在网络上讨论的UnknownError: javascript error: document unloaded while waiting for result错误。

但是,我找不到解决方法。这两行之间出现问题:

    element(by.id('signup-btn')).click();
    expect(element(by.id('accept-btn')).isDisplayed()).toBeTruthy();

第一行提交一个表单,该表单导致硬重定向(如在$window.location.href='/something'中)将Web应用程序返回到由第二行测试的页面。但重定向borks projector.js。

有办法做到这一点吗?

1 个答案:

答案 0 :(得分:0)

而不是期望断言你可以使用等待功能

首先声明一个定义全局最大时间的模块。

var Transitions = function(){};

//Sleep function to counter the custom animation  that has been addes

Transitions.prototype.maxTimeToLook = 30000;

exports.Transitions = new Transitions();

这将是量角器寻找元素的最大超时时间。 然后你可以使用这样的预期条件函数而不是期望

    browser.wait(protractor.ExpectedConditions.presenceOf(element(by.id('accept-btn'))), sync.maxTimeToLook);

您遇到的问题是因为您在单击按钮时使用expect,期望条件检查要在页面上呈现的元素。在我的测试中有效的一种解决方法是使用

根据API文档https://angular.github.io/protractor/#/api?view=ExpectedConditions.prototype.stalenessOf

ExpectedConditions.prototype.presenceOf

An expectation for checking that an element is present 
on the DOM of a page. This does not necessarily mean that 
the element is visible.

如果存在不起作用。也许您可以使用此处提到的其他预期条件方法

https://angular.github.io/protractor/#/api?view=ExpectedConditions