selenium-webdriver - 将原生 ES6 Promise 添加到 Typescript 中的 Protractor/WebDriverJS ControlFlow

标签 selenium-webdriver typescript jasmine protractor es6-promise

我目前在返回 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/

相关文章:

java - 无法将 BASE64 解码为 Selenium 2 中的图像文件

java - 如何在selenium测试框架中生成没有主类的可运行jar文件?

compiler-construction - TypeScript 编译错误 TS5037 : Cannot compile external modules unless the '--module' flag is provided

typescript - 更好的 typescript 文件引用

Typescript 无法保留对所有者类的引用

jasmine - PhantomJS "Can' t 找到变量 : require"when using PhantomJasmine

unit-testing - 使用依赖项测试 AngularJS 服务

Selenium Grid2 - 远程节点未连接到集线器

java - 如何根据selenium webdriver中的其他元素选择一个元素

javascript - 使用 Jasmine 2.0 对 $scope.$evalAsync 函数进行单元测试