Steps to Setup Protractor using JS/Jasmine- Automation Test

Gurpreet Hanspal
3 min readMay 17, 2021

--

Protractor is a sort of wrap on selenium webdriver. It interact with selenium webdriver to call AngularJS (Ng-model).

  1. Firstly we need to Install Node.js. To install node.js please refer this link HERE
  2. To install Protractor run this command in terminal.
    npm install -g protractor
  3. Java installation is must and make sure Environment variable Path should also setup. To install java you can refer this link HERE
  4. To install Webdriver manager we need to run following command in terminal

webdriver-manager update

To Start webdriver manager from command line.
webdriver-manager start

In Terminal, if it shows ‘Selenium server is up and running on port 4444’. It means server is running.

  1. To check Webdriver manager is up and running open “http://localhost:4444/" on browser. You will see a selenium standalone.
  2. To ensure console is working . Click on console. You will see Session window now. It shows selenium server is running perfectly.(http://localhost:4444/wd/hub/static/resource/hub.html)
  3. Make sure don’t close the terminal in the case when we are running the test cases. If terminal get close you can run the command again as we did in step 5.
    Eventually, we need selenium server up to run the test cases.

To initializing the directory before Code. Install VSCode.

  1. Create a folder in you local system with your project name.
  2. Open terminal at same location where we have created project folder in local.
  3. Now run this command npm init
    npm init

enter following details:
— enter package name: test, description: test,

package name: test

description: test

rest we can leave and By following steps package.json file created in directory.

3. Now we will set up dependencies in package.json file. Just paste following code snippet in file.

{
"name": "test",
"version": "1.0.0",
"description": "test",
"main": "index.js",
"dependencies":
{
"protractor": "^7.0.0",
"jasmine": "^3.7.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1" },
"author": "gurpreet",
"license": "ISC"
}

Here we are using protractor as a selenium webdriver wrapper and we are using jasmine framework just like a pytest to write test cases and assertion. Now save the file .

To Install Packages in VSCode:

  1. run following command in vscode terminal (make sure you run this command in project directory where package.json file placed)
  2. 1npm install
  3. Now Create two files in directory in VScode:

conf.js — configuration holds details of selenium address, where exactly its running, chrome browser configuration

spec.js — we will mention our first test code here

To Setup Selenium and packages in selenium:

  1. go to config file and define the selenium address. Paste following code in the file.
  2. exports.config = { framework: 'jasmine', seleniumAddress: 'http://localhost:4444/wd/hub', specs: ['edgepayvalidlogin.js'], capabilities: { browserName: 'chrome', chromeOptions: { args: [ "--headless", "--disable-gpu", "--window-size=800,600" ] } } };
  3. To run the test cases use command following command

protractor conf.js

( to run any file/command make sure your selenium server is up)

Install “Protractor snippet” from Extension Menu in VS code.

Install “Angular v 11 snippet”.

Install “Javascript es6 snippet”

Install “npm By egamma”

Install “npm intellisense by christian kohler”

Install “ jasmine code snippet” and “jasmine ES5 Code Snippets”.

--

--