2

What should I add to package.json and import in each e2e.spec.ts file to have such a possibility?

Currently when I change e2e.spec.js to e2e.spec.ts the file is compiled and I have errors saying Cannot find name 'browser' etc.

I tried to

import {browser, element, by} from 'protractor';

but then during compilation I've got errors

node_modules/protractor/built/browser.d.ts(1,1): error TS1084: 
Invalid 'reference' directive syntax.

My package.json (only important parts)

{
  "scripts": {
    "lite": "lite-server",
    "tsc": "tsc",
    "typings": "typings",
    "pree2e": "npm run webdriver:update",
    "webdriver:update": "webdriver-manager update"
  },
  "dependencies": {
    "@angular/common": "~2.0.1",
    "@angular/compiler": "~2.0.1",
    "@angular/core": "~2.0.1",
    "@angular/forms": "~2.0.1",
    "@angular/http": "~2.0.1",
    "@angular/platform-browser": "~2.0.1",
    "@angular/platform-browser-dynamic": "~2.0.1",
    "@angular/router": "~3.0.1",
    "@angular/upgrade": "~2.0.1",
    "angular2-in-memory-web-api": "0.0.20",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.12",
    "systemjs": "0.19.39",
    "zone.js": "^0.6.25"
  },
  "devDependencies": {
    "canonical-path": "0.0.2",
    "concurrently": "^3.0.0",
    "jasmine": "^2.5.2",
    "jasmine-fail-fast": "^2.0.0",
    "karma": "^1.3.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-jasmine": "^1.0.2",
    "lite-server": "^2.2.2",
    "protractor": "^4.0.8",
    "protractor-jasmine2-screenshot-reporter": "^0.3.2",
    "typescript": "^1.8.10",
    "typings": "^1.4.0"
  }
}

and sample test suite

// import {browser, element, by} from 'protractor';
describe('Test suite related with health tab', () => {
    beforeEach(function () {
        browser.get('');
    });
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
koral
  • 2,807
  • 3
  • 37
  • 65
  • Looks like this is related: http://stackoverflow.com/questions/38529236/protractor-configuration-error-w-typescript-angular-2 – koral Oct 03 '16 at 13:31

2 Answers2

2

Since Protractor 4.0.5, they use using TypeScript 2.0.x. I've just gone through upgrading my project to use these, and it took a bit of work - for example, you won't need typings anymore (though I think you can still use it). Use the import from protractor that you have. When I did this I got the error you had when building. I am using Visual Studio 2015 Pro - and I had been using a TypeScript 1.8.3 extension. I changed this this to TypeScript 2.0.3 (which my project is using) and the build error went away.

This may be helpful if you want to convert typings to @types TypeScript typings in NPM @types org packages

Community
  • 1
  • 1
L Aslett
  • 41
  • 3
0

I had to upgrade typescript to >= 2.0.0 and downgrade protractor to 3.3. Then I don't have to add any import to e2e-spec.ts.

koral
  • 2,807
  • 3
  • 37
  • 65