How to write Protractor test scripts using Typescript along with Jasmine framework in Visual studio Code?
I use Visual Studio Code everyday to write my scripts, it's my current favourite editor for Protractor because of its built in support for TypeScript!
Here are the following things which can come into my mind which could help you setup your framework-
- Download the latest VS Code version - https://code.visualstudio.com/download
- Install typescript globally
npm install -g typescript
- Install protractor globally
npm install -g protractor
- Create your project folder
Setup you project folder for git, node and typescript -
npm init -f // will create default package.json stating its nodejs project git init // will create .git file, you project is now git project tsc --init // will create tsconfig.json stating its typescript project
Install typings and dev dependencies-
npm install --save-dev protractor // this will install protractor as a dev dependency npm install --save-dev typescript // this will install typescript as a dev dependency npm install --save-dev @types/jasmine // jasmine typings npm install --save-dev @types/node // node typings
- At this point you have setup your basic
protractor-typescript
project and you can see all the typings and dependencies inpackage.json
. Now you are good to write your typed scripts :). Now compile your scripts by running -
tsc or tsc -w
- After successfull compilation all your javascript files would be generated.
The run protractor
protractor config.js
- You can also setup your vs code for debugging with protractor which I have mentioned here - Protractor -VS Code Debugging
For more details pls refer the TypeScript Tutorial, Protractor API
The Typescript error you are observing this is due to VS Code not recognizing global typescript 2.0 version.
To solve this open vscode go to preferences--> user settings --> settings.json will be opened and enter the highlighted path as shown
Save your file and restart VSCode now you are good to go :)