首页 > 解决方案 > 量角器 - 等待 Angular 10 应用程序总是失败

问题描述

感谢您提出我的问题。

多年来,我们一直在使用量角器并取得了巨大的成功。我们所有较新的应用程序都在 Angular 10 中构建或升级到 Angular 10。我们非常依赖我们的显式等待。这已经很长时间没有给我们带来问题了。但是,由于我们在 waitForDisplayed 或 waitForClickable 时升级,当 WaitForAngularEnabled = true 时它总是会超时。

另一方面,如果 WaitForAngularEnabled = false 并且我们使用 seleniums browser.expectedConditions 它可以正常工作。有人看到 Angular 10 和量角器有什么问题吗?

这是我们的通用等待方法

import { browser, ElementFinder, ExpectedConditions as EC } from 'protractor';

/** Wait for this Component to be clickable.
 * @param {number} [waitTimeoutMilliseconds] If set, override protractor defaults for maximum time to wait.
 * @returns {Promise<void>} A promise that resolves when the element is clickable.
 * @memberof Component
 */
public async WaitForClickable(timeoutMilliseconds?: number): Promise<void> {
    try {
        if(browser.waitForAngularEnabled()){
            await browser.wait(EC.elementToBeClickable(this.ComponentElement), timeoutMilliseconds);
        }
        else{
            let bEC = browser.ExpectedConditions;

            return browser.wait(bEC.elementToBeClickable(this.ComponentElement), timeoutMilliseconds, "First Name text field should be visible.");
        }
        
    }
    catch (e) {
        throw new Error(`Component` + (this.DisplayName ? ` (${this.DisplayName}) - ` : ' - ') + `WaitForClickable:\n${e}`);
    }
}


    /** Waits for this Component's element to be both present on the DOM and visible.
     * @param {number} [waitTimeoutMilliseconds]  If set, override protractor defaults for how long to wait.
     * @returns {Promise<void>} A promise that resolves when the element is present and visible.
     * @memberof Component
     */
    public async WaitForDisplayed(waitTimeoutMilliseconds?: number): Promise<void> {
        try {
            if(browser.waitForAngularEnabled()){
                await browser.wait(EC.and(EC.presenceOf(this.ComponentElement), EC.visibilityOf(this.ComponentElement)), waitTimeoutMilliseconds);
            }
            else{
                let bEC = browser.ExpectedConditions;

                return browser.wait(bEC.visibilityOf(this.ComponentElement), waitTimeoutMilliseconds, "First Name text field should be visible.");
            }
        }
        catch (e) {
            throw new Error(`Component` + (this.DisplayName ? ` (${this.DisplayName}) - ` : ' - ') + `WaitForDisplayed:\n${e}`);
        }
    }

请注意,我们必须添加 if(browser.waitForAngularEnabled()) 因为我们总是在等待时超时,我们仍然想使用通用方法。我认为这是因为角度区域永远不会稳定,但我找不到任何迹象。

任何帮助,将不胜感激

标签: angulartypescriptseleniumautomationprotractor

解决方案


推荐阅读