量角器时间问题 [英] Protractor Timing Issues

查看:100
本文介绍了量角器时间问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在我的量角器测试规范之一中具有以下代码:

I currently have the following code in one of my test specs for Protractor:

.then(function() {
    return button.click();
})
.then(function() {
    return element(otherButton).isDisplayed();
})
.then(function(otherButtonIsPresent) {
    if(otherButtonIsPresent) {
        return browser.wait(EC.elementToBeClickable(element(otherButton)), getWaitTime())
            .then(function() {
                element(otherButton).click();
                return element(continueButton).isPresent();
            })
    }
})

当我使用Chrome使用-debug-brk 和-insert 标志,我能够通过这些检查并照常恢复。当我运行不带标志的相同测试时,该测试失败,并且在尝试单击 otherButton 期间停滞。

When I use Chrome to debug using the --debug-brk and --inspect flags, I am able to pass these checks and resume as normal. When I run the same test without the flags, the test fails and stalls during looking for otherButton before trying to click on it.

我想知道这是否是因为在调试过程中,我设置了断点并等待按钮显示在屏幕上,然后再尝试单击它们。

I'm wondering if this is because during debugging, I set breakpoints and wait for the buttons to show up on the screen before attempting to click on them.

在尝试单击该元素之前,我需要确保该元素在页面上可见,并且想知道是否还有其他方法可以完成此操作?

I need to make sure that this element is visible on the page before trying to click it and was wondering if there were another way if accomplishing this?

谢谢

推荐答案

我正在使用答案,因为目前还没有评论。

I'm using Answer as I can't comment yet.

您基本上是在自己提到它:单击按钮后,您只想等待下一个按钮可单击。
因此,您的 .then()功能应从其依赖的按钮开始。在我看来,三个排队的 .then()函数取决于相同的条件,因此在您 .click()第一个按钮,第二个 .then()立即执行,而不等待之前的 .click()完成。

You're basically mention it yourself: after you clicked a button you just want to wait until a next button is clickable. Therefore your .then()-functions should start from the button it depends on. To me it seems, the three lined-up .then()-functions depend on the same condition, so after you .click() the first button, the second .then() gets immediately executed, not waiting the previous .click() to finish.

因此将 .then()直接放在相关的 .click()和前面的 .then()函数内部,这应该可以工作:

Therefore putting the .then() directly behind the relevant .click() and inside the preceding .then()-function, this should work:

.then(function() {
    element(button).click().then(function(){
       element(otherButton).click().then(function(){
           return element(continueButton).isPresent();
       });
    });
});

或者,如果您使用ExpectedConitions,则不需要。然后( )-功能。由于量角器应管理ControlFlow,因此可以在不链接 .then()功能的情况下编写ControlFlow:

Or if you go with ExpectedConitions, you shouldn't need .then()-functions. Because Protractor should manage the ControlFlow, allowing you to write it without chained .then()-functions:

.then(function() {
    browser.wait(EC.elementToBeClickable(element(button)), getWaitTime());
    element(button).click();
    browser.wait(EC.elementToBeClickable(element(otherButton)), getWaitTime());
    element(otherButton).click();
    browser.wait(EC.elementToBeClickable(element(continueButton)), getWaitTime());
    return element(continueButton).isPresent();
});

这篇不错的文章详细介绍了异步编写,但是要感谢Protractor同步执行。

This nice post elaborates a bit on asynchronous writing, but thanks to Protractor synchronous execution.

作为结合我的两个输入的示例,可以对测试进行双重保护:

As alternative an example combining my both inputs, kind of double-securing the test:

.then(function() {
    browser.wait(EC.elementToBeClickable(element(button)), getWaitTime());
    element(button).click().then(function(){
       browser.wait(EC.elementToBeClickable(element(otherButton)), getWaitTime());
       element(otherButton).click().then(function(){
           browser.wait(EC.elementToBeClickable(element(continueButton)), getWaitTime());
           return element(continueButton).isPresent();
       });
    });
});

这篇关于量角器时间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆