Protractor setup with jasmine & typescript in VScode

Refer protractor intro to get some insights, if you are new to protractor.

We will use typescript as our language to write protractor tests with jasmine framework.

Let’s see one by one all the libraries needed to run protractor tests.

Typescript in visual studio code

Typescript is super set of java script with advantages like

  • Purely OOPs – makes easier to work with class and modules
  • Static type checking
  • enum  and const support
  • Provides compilation error which makes easy correction before run
  • Offers a compiler that converts to java script code
  • Several IDEs [like VSCode] supports code Intellisense

Refer setup and run typescript in VScode  and try to run a .ts file in VScode.

Note

Create a folder under C:\ drive, let’s say C:\Protractor\Test and open the folder in VSCode to get started with. – this process needs to be done first, from here we will install all libraries.

Install Protractor

As we know protractor is a node.js program, so we can install protractor using npm command

To install protractor globally and access from any folder location, Go to Start > Run > cmd and type

this above statement downloads protractor package,and also installs 2 command line tools (like npm), protractor and webdriver-manager

Note: protractor package / folder will be downloaded and viewed under %appdata%\npm\protractor

protractor command is used to run the *.js file i.e conf.js

webdriver-manager command is used to update or start the selenium server and related browser drivers

Install Jasmine

To run tests in typescript, need to install type definitions for jasmine

on VSCode key press ctrl+ and type

and

Install ts-node

package.json

To create a sample package.json, key press ctrl + to open terminal and type

or you can create a new file package.json and the content should be something like below

dependencies section is for global installation.
devDependencies section is for local installation,

Either you can install individual libraries by using npm [as mentioned before] or mention in json file [ when we do npm install, will download all the libraries with specified versions].

Follow package.json docs for more format and options.

tsconfig.json

Note:
tsc is used to compile / transpile *.ts (typescript file) and convert to *.js file (.js file will be created under the folder specified under tsconfig.json i.e ConvertedJSfiles)

npm test will execute the value (protractor ConvertedJSfiles/conf.js) as mentioned under “test” (from package.json)

Content posted is based on learning or working experience, please leave comments if anything needs to be added or updated, discuss your queries on our facebook:qavalidation.com, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: