输入'promise.Promise '不能指定为'承诺' “

问题描述 投票:2回答:1

我正面临着量角器测试的一些奇怪问题。我使用以下代码来获取元素的文本。

getTitleElementValue(): Promise<string> {
    return this.getTitleElement().getAttribute('value')
  }

一切顺利,直到我把我的代码推到git。我立刻拉了最新的代码,然后我收到了错误

Type 'promise.Promise<string>' is not assignable to type 'Promise<string>'

我对输出感到困惑,需要一些关于这个问题的输入。我想提供任何其他细节。下面是package.json

    {
  "name": "ris-beta",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "generate:proxy": "node config/proxy.js",
    "start": "npm run generate:proxy && ng serve --ssl true --ssl-key config/ssl/localhost.key --ssl-cert config/ssl/localhost.crt --proxy-config proxy.conf.json --host=0.0.0.0",
    "start:http": "npm run generate:proxy && ng serve --proxy-config proxy.conf.json --host=0.0.0.0",
    "test": "ng test --watch=false",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor",
    "lint": "ng lint --type-check",
    "deploy": "npm run test && npm run clean-build && npm run deploy-only",
    "rimraf": "rimraf",
    "clean:dist": "npm run rimraf -- dist",
    "clean-build": "npm run clean:dist && ng build -prod --aot=false --sourcemaps",
    "deploy-only": "node config/deploy.js",
    "compodoc": "./node_modules/.bin/compodoc -p src/tsconfig.app.json"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.0.0-rc.6",
    "@angular/cdk": "^5.2.3",
    "@angular/common": "^5.2.7",
    "@angular/compiler": "^5.2.7",
    "@angular/core": "^5.2.7",
    "@angular/forms": "^5.2.7",
    "@angular/http": "^5.2.7",
    "@angular/material": "^5.2.3",
    "@angular/platform-browser": "^5.2.7",
    "@angular/platform-browser-dynamic": "^5.2.7",
    "@angular/router": "^5.2.7",
    "@ngrx/effects": "^4.1.0",
    "@ngrx/store": "^4.1.0",
    "@ngrx/store-devtools": "^4.0.0",
    "angular-split": "^0.2.7",
    "angular-tree-component": "^5.2.0",
    "bootstrap": "4.0.0-alpha.6",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "ngx-clipboard": "^9.0.0",
    "normalize.css": "^7.0.0",
    "primeng": "^5.0.0",
    "rxjs": "=5.5.2",
    "tinymce": "4.7.4",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "1.5.0-rc.3",
    "@angular/compiler-cli": "^5.2.7",
    "@angular/language-service": "^5.2.7",
    "@compodoc/compodoc": "^1.0.8",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "^6.0.101",
    "archiver": "2.0.0",
    "codelyzer": "~3.2.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-phantomjs-launcher": "^1.0.4",
    "karma-remap-istanbul": "^0.6.0",
    "ngx-clipboard": "^9.0.0",
    "normalize.css": "^7.0.0",
    "phantomjs-polyfill": "0.0.2",
    "protractor": "~5.1.2",
    "quill": "^1.3.4",
    "sync-request": "4.0.3",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2"
  }
}

提前致谢。

protractor webstorm
1个回答
5
投票

因为量角器有自己的Promise工具,目前量角器仍然使用自己的Promise工具,而不是使用Nodejs native Promise

你使用Nodejs native Promise声明了结果值,应该使用Protractor self Promise工具。

import { browser, by, protractor, promise, ElementFinder } from 'protractor'

getTitleElementValue(): promise.Promise<string> {
   return this.getTitleElement().getAttribute('value')
}

仅供参考,量角器开始使用Nodejs原生Promise正在进行并计划于2018/10发生。

© www.soinside.com 2019 - 2024. All rights reserved.