gigeos
gigeos

Reputation: 308

Angular 2 - Protractor Tests: Cannot find name 'element' and 'name'

Hye,

I've created app.e2e-spec.ts file to create unit tests:

import {} from 'jasmine';
import {} from 'protractor';

describe('Testing login button disable if empty input texts', function() {
  it('should username have null value', function() {
    var inputsLogin = element(by.name('username'));
    expect<any>(inputsLogin.getAttribute('value')).toBe(null);
  });

  it('should password have null value', function() {
    var inputsPassword = element(by.name('password'));
    expect<any>(inputsPassword.getAttribute('value')).toBe(null);
  });

  it('should login button disable', function() {
    var loginButton = element(by.id('button-confirm'));
    expect<any>(loginButton.getAttribute('disabled')).toBe("true");
  });
});

The Unit Tests work but the problem is, when I run tsc command, I obtain these errors:

tests/tests-e2e/app.e2e-specs.ts(10,27): error TS2304: Cannot find name 'element'.
tests/tests-e2e/app.e2e-specs.ts(10,35): error TS2304: Cannot find name'by'
tests/tests-e2e/app.e2e-specs.ts(15,30): error TS2304: Cannot find name'element'
...

But I can run sometimes my tests because Intellj create js for me

My tsconfig.js:

{
 "compilerOptions": {
  "allowSyntheticDefaultImports": true,
  "declaration": false,
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true,
  "lib": [
    "dom",
    "es2015"
  ],
  "module": "commonjs",
  "moduleResolution": "node",
  "sourceMap": true,
  "target": "es5",
  "typeRoots": [
    "./node_modules/@types/"
  ]
},
 "include": [
   "src/**/*.ts",
   "tests/**/*.ts"
  ],
 "exclude": [
  "node_modules"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}

}

Upvotes: 1

Views: 3605

Answers (1)

Maciej Treder
Maciej Treder

Reputation: 12342

You left your import statements empty.

import {by, element} from 'protractor';

Upvotes: 5

Related Questions