我目前在返回 ES6 Promises 的 Protractor 测试中调用一些外部代码。
我希望使用 ControlFlow 链接这些 promise ,但在编译 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)
有什么方法可以包装 promise 以使其兼容?
最佳答案
控制流正在寻找 selenium-webdriver
提供的 ManagedPromise
。如果 testServer.fixture
返回原生 ES6 promise ,这将不起作用。原生 ES6 promise 不一样 webdriver.promise.Promise
关于selenium-webdriver - 将原生 ES6 Promise 添加到 Typescript 中的 Protractor/WebDriverJS ControlFlow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40414458/