0
看來它不能正常工作。量角器+打字稿+異步/等待:失敗 - 10001ms後等待超時
Failed: Wait timed out after 10012ms
我嘗試了很多等待案件但無論如何堆棧跟蹤得到一個超時錯誤。
如何進行管理?
這裏是我的代碼:(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)
失敗:未知錯誤:元素點擊時無法點擊(887,411)。其他元素將收到點擊:... – Jack