将原生 ES6 Promise 添加到 Typescript 中的 Protractor/WebDriverJS ControlFlow
Add native ES6 Promise to Protractor/WebDriverJS ControlFlow in Typescript
我目前正在 Protractor 测试中调用一些外部代码 returns ES6 Promises。
我希望使用 ControlFlow 链接这些承诺,但在编译 Typescript 时出现类型错误。
测试中:
import {browser} from 'protractor';
...
it('should have a title', () => {
let flow = browser.controlFlow();
flow.execute(testServer.fixture('user_test_roles'));
});
当运行:
[13:04:39] E/launcher - Error: ⨯ Unable to compile TypeScript
src/app/app.e2e.ts (9,18): Argument of type 'Promise<{}>' is not assignable to parameter of type '() => {} | Promise<{}>'.
Type 'Promise<{}>' provides no match for the signature '(): {} | Promise<{}>' (2345)
如果我尝试 flow.wait()
我会得到不同类型的错误:
[13:08:27] E/launcher - Error: ⨯ Unable to compile TypeScript
src/app/app.e2e.ts (9,15): Argument of type 'Promise<{}>' is not assignable to parameter of type 'Function | Promise<{}>'.
Type 'Promise<{}>' is not assignable to type 'webdriver.promise.Promise<{}>'.
Property 'cancel' is missing in type 'Promise<{}>'. (2345)
有什么方法可以包装承诺以使其兼容?
控制流正在寻找 selenium-webdriver
提供的 ManagedPromise
。如果 testServer.fixture
返回原生 ES6 promise,这将不起作用。原生 ES6 承诺不一样 webdriver.promise.Promise
我目前正在 Protractor 测试中调用一些外部代码 returns ES6 Promises。
我希望使用 ControlFlow 链接这些承诺,但在编译 Typescript 时出现类型错误。
测试中:
import {browser} from 'protractor';
...
it('should have a title', () => {
let flow = browser.controlFlow();
flow.execute(testServer.fixture('user_test_roles'));
});
当运行:
[13:04:39] E/launcher - Error: ⨯ Unable to compile TypeScript
src/app/app.e2e.ts (9,18): Argument of type 'Promise<{}>' is not assignable to parameter of type '() => {} | Promise<{}>'.
Type 'Promise<{}>' provides no match for the signature '(): {} | Promise<{}>' (2345)
如果我尝试 flow.wait()
我会得到不同类型的错误:
[13:08:27] E/launcher - Error: ⨯ Unable to compile TypeScript
src/app/app.e2e.ts (9,15): Argument of type 'Promise<{}>' is not assignable to parameter of type 'Function | Promise<{}>'.
Type 'Promise<{}>' is not assignable to type 'webdriver.promise.Promise<{}>'.
Property 'cancel' is missing in type 'Promise<{}>'. (2345)
有什么方法可以包装承诺以使其兼容?
控制流正在寻找 selenium-webdriver
提供的 ManagedPromise
。如果 testServer.fixture
返回原生 ES6 promise,这将不起作用。原生 ES6 承诺不一样 webdriver.promise.Promise