量角器 + 打字稿 + async/await:失败 - 等待 10001 毫秒后超时

Protractor + Typescript + async/await: Failed - Wait timed out after 10001ms

它似乎没有发挥应有的作用。

Failed: Wait timed out after 10012ms

我尝试了很多 waits 的情况,但无论如何堆栈跟踪都会出现 timeout 错误。

如何管理它?

这是我的代码:(waiter.ts)

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


export class WaitConditions {

    public async clickable(element: ElementFinder, opt_message?: string) {
        await browser.wait(EC.elementToBeClickable(element), 10*1000, opt_message);
    }

BasePage.ts

import {WaitConditions} from "./waiter";
import {browser, element, ElementFinder} from "protractor";

export abstract class BasePage {

    private _conditions: WaitConditions = new WaitConditions();

    protected async click(element: ElementFinder): Promise<void> {
        await this._conditions.clickable(element);
        await element.click();
    }

    protected async type(element: ElementFinder, text: string): Promise<void> {
        await this._conditions.clickable(element);
        // await element.clear();
        await element.sendKeys(text);
    }

    protected async get(url: string): Promise<void> {
        await browser.get(url);
    }
}

google.spec.ts

    import {browser, By} from "protractor";
    import {GooglePage} from "../pageObjects/google.page"

    describe('Open the google page', () => {

    it('should have a title', async () => {
        await expect(browser.getTitle()).toBe('Google');
        await browser.sleep(5000);
    })


  });

    describe('a search option and click on the search button', () => {

    it('should have the result of search', async () => {
        const google = new GooglePage();
        await google.goSearch('test1');
        await browser.sleep(5000);
         })
     });
     describe('the google search page', () => {
      it('should be ', async () => {
        const google = new GooglePage();
        await browser.get('https://www.google.com');
        await google.goSearch('test2');
        await browser.sleep(5000);
        })
     });

googlepage.ts

import {BasePage} from "../pageObjects/basePage";
import {$, browser, By, element, ElementFinder} from "protractor";
import {Key, promise as promisewd} from "selenium-webdriver";

export class GooglePage extends BasePage {

    private readonly searchButton: ElementFinder;
    private readonly searchField: ElementFinder;

    constructor () {
        super();
        this.searchButton = element(By.name('btnK'));
        this.searchField = element(By.id('lst-ib'));
    }

    public goSearch(search: string): Promise<void> {
        this.type(this.searchField, search);
        return this.click(this.searchButton);
    }
}

最终结果:

    Executed 3 out of 3 specs in 26 s

        PASSED   1 ( 33.33% )
        FAILED   2 ( 66.66% )
        SKIPPED  0 ( 0% )



1) a search option and click on the search button should have the result of search
        - Failed: Wait timed out after 10001ms
            at WebDriverError (C:\Users\user\Downloads\-examples\example\node_modules\selenium-webdriver\lib\error.js:27:5)
    at TimeoutError (C:\Users\user\Downloads\-examples\example\node_modules\selenium-webdriver\lib\error.js:238:5)
    at C:\Users\user\Downloads\-examples\example\node_modules\selenium-webdriver\lib\promise.js:2107:17
    at process._tickCallback (internal/process/next_tick.js:109:7)
From asynchronous test:
Error
    at Suite.describe (C:\Users\user\Downloads\-examples\example\specs\googlepage.spec.ts:17:5)
    at Object.<anonymous> (C:\Users\user\Downloads\-examples\example\specs\googlepage.spec.ts:15:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)

2) Given the gmail login page should be logged in
        - Failed: Wait timed out after 10012ms
            at WebDriverError (C:\Users\user\Downloads\-examples\example\node_modules\selenium-webdriver\lib\error.js:27:5)
    at TimeoutError (C:\Users\user\Downloads\-examples\example\node_modules\selenium-webdriver\lib\error.js:238:5)
    at C:\Users\user\Downloads\-examples\example\node_modules\selenium-webdriver\lib\promise.js:2107:17
    at process._tickCallback (internal/process/next_tick.js:109:7)
From asynchronous test:
Error
    at Suite.describe (C:\Users\user\Downloads\-examples\example\specs\googlepage.spec.ts:25:5)
    at Object.<anonymous> (C:\Users\user\Downloads\-examples\example\specs\googlepage.spec.ts:24:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
it('should have the result of search', async () => {
    const google = new GooglePage();
    await google.goSearch('test1');
    await browser.sleep(5000);
     })
 });

您好像没有打开页面? await browser.get('https://www.google.com');