Angular 当元素不存在时,量角器检查元素的速度很慢

Angular 当元素不存在时,量角器检查元素的速度很慢,angular,protractor,Angular,Protractor,我正在为一个大型angular 4项目编写e2e测试。我编写了一个helper函数来关闭一个模态对话框(如果它存在的话)。以前的操作可能会根据条件数据自动关闭对话框,因此我不能假设对话框已启动 function closeModal() { Util.logInfo('closing'); $('.modal-backdrop').isPresent().then(exists => { if (exists) { < HAND

我正在为一个大型angular 4项目编写e2e测试。我编写了一个helper函数来关闭一个模态对话框(如果它存在的话)。以前的操作可能会根据条件数据自动关闭对话框,因此我不能假设对话框已启动

function closeModal() {
    Util.logInfo('closing');
    $('.modal-backdrop').isPresent().then(exists => {
        if (exists) {
            < HANDLE CLOSING DIALOG HERE >
        }
    });
    Util.logInfo('closed outer');
}
模态更新:

13:06:57:563 -  ** closing
13:06:57:705 -    -> action: waiting for NOT presence of element up to 5000ms
13:06:57:718 -  ** closed outer
这个块经常被调用,可能有20%的时间它不需要关闭(但我仍然需要调用它以防万一以防止错误失败),并且它会在每个测试运行中增加大约30-40秒


是否有任何方法可以加速此过程,或者至少暂时更改此块中所需的超时时间?

我认为您的代码中已设置了
隐式等待
。我以前也回答过类似的问题,阅读它以了解隐式等待是如何工作的-

但在您的情况下,这可能会有所帮助:

function closeModal() {
    Util.logInfo('closing');
    browser.manage().timeouts().implicitlyWait(0)
    $('.modal-backdrop').isPresent().then(exists => {
        if (exists) {
            < HANDLE CLOSING DIALOG HERE >
        }
    });
    // Setting back your implicit value here, i think it is 10 seconds?
    browser.manage().timeouts().implicitlyWait(10000)
    Util.logInfo('closed outer');
}
函数closeModal(){
Util.logInfo(“关闭”);
browser.manage().timeout().implicitlyWait(0)
$('.modal background').isPresent().then(exists=>{
如果(存在){

}
});
//把你的隐式值放回去,我想是10秒?
browser.manage().timeout().implicitlyWait(10000)
Util.logInfo(“外部关闭”);
}
其思想是在查找可能不存在的元素之前禁用隐式等待,然后将其恢复回来。请注意,我们根本不等待模式窗口的出现。它可能会出现几乎没有延迟,并且ISIS将已经通过-所以考虑小等待作为一个选项:

function closeModal() {
    browser.manage().timeouts().implicitlyWait(0)
    let modalPresent = protractor.ExpectedConditions.presenceOf($('.modal-backdrop')) 
    browser.wait(modalPresent, 1000).then(()=> {
        <handle modal is present state here>
        }, err=> {
        // Just skipping, if modal not present. This prevents promise to be rejected
    })
    // Setting back your implicit value here, i think it is 10 seconds?
    browser.manage().timeouts().implicitlyWait(10000)
}
函数closeModal(){
browser.manage().timeout().implicitlyWait(0)
让modalPresent=量角器.ExpectedConditions.presenceOf($('.modal background'))
browser.wait(modalPresent,1000)。然后(()=>{
},err=>{
//如果模态不存在,则跳过。这可以防止拒绝承诺
})
//把你的隐式值放回去,我想是10秒?
browser.manage().timeout().implicitlyWait(10000)
}

这正是问题所在。我禁用了
isPresent()
周围的隐式等待,现在它可以完美地工作。
function closeModal() {
    browser.manage().timeouts().implicitlyWait(0)
    let modalPresent = protractor.ExpectedConditions.presenceOf($('.modal-backdrop')) 
    browser.wait(modalPresent, 1000).then(()=> {
        <handle modal is present state here>
        }, err=> {
        // Just skipping, if modal not present. This prevents promise to be rejected
    })
    // Setting back your implicit value here, i think it is 10 seconds?
    browser.manage().timeouts().implicitlyWait(10000)
}