How to integrate Protractor test cases in Atom using Typescript?

爷,独闯天下 提交于 2019-11-29 08:52:31

You have to install jasmine and node typings so that typescript recognizes them. Now there is even a better approach, there is no need of typings folder and typings.json. we have @types dependencies for the same.

so you can do that by following steps-

go to your project folder and install the dependencies -

 npm install --save-dev @types/jasmine //this would install jasmine typings as a dev dependency in your package.json
 npm install --save-dev @types/node   //this would install node typings as a dev dependency in your package.json

once you have installed try compiling it with tsc or tsc -w watch mode, now you shouldn't see those TS syntax errors!

And you have to import browser from protractor/globals to use its methods, like this-

import {browser} from 'protractor/globals';

For more details you can check out my rep for initial setup of protractor with typescript it uses cucumber as well as you can check out the official protractor-typescript example

Obviously, some of these issues (require and loginPage, for example) aren't necessarily anything to do with Jasmine. However, the issue is that these are global variables and the TS compiler can't find their declaration. The easiest way to remedy this is to declare each one at the top of the file in the following way:

declare var describe: any;

This will resolve the issues with describe and it. Other problems, such as require will be because you're not using the module import syntax.

This didn't quite fix the problem for me. In addition to installing the jasmine types (above answer)

I had to open tsconfig.json and insure jasmine was in the list of types under compilerOptions. For example { "compileOnSave": false, "compilerOptions": { "outDir": "./dist/out-tsc", "baseUrl": "src", "sourceMap": true, "declaration": false, "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "allowJs": true, "target": "es5", "paths": { "environments": [ "./environments" ] }, "types": [ "node", "jasmine" ], "typeRoots": [ "node_modules/@types" ], "lib": [ "es2016", "dom" ] } } After adding "jasmine" as a type, the errors disappeared in Atom immediately.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!