Search code examples
protractorwebstorm

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


I am facing some strange issue with the protractor tests. I have used the following piece of code to get the text of the element.

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

all went good till I pushed my code to git. Immediately I pulled the latest code and from then I am getting the error

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

I am confused with the output and need some some inputs from you regarding the issue. would like to provide any other details. below is the 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"
  }
}

Thanks in advance.


Solution

  • Because Protractor has self Promise implement and currently Protractor still use self Promise implement, not use Nodejs native Promise.

    You declared the result value using Nodejs native Promise, should use the Protractor self Promise implement.

    import { browser, by, protractor, promise, ElementFinder } from 'protractor'
    
    getTitleElementValue(): promise.Promise<string> {
       return this.getTitleElement().getAttribute('value')
    }
    

    FYI, Protractor switch to use Nodejs native Promise is going on and plan to happen at 2018/10.