04 First Test - biswajitsundara/Protractor GitHub Wiki

Update Package.json

The best practice is to install all dependencies at project level. Now configure the below three commands in package.json file.

"scripts": {
    "test": "./node_modules/.bin/protractor conf.js",
    "update": "./node_modules/.bin/webdriver-manager update",
    "start": "./node_modules/.bin/webdriver-manager start"
  },

Update WebDriver Manager

The first step is to update the webdriver manager. Execute the command npm run update

Create spec.js

The below test will simply open the website and print the heading text.

const { browser, element } = require("protractor");

describe('Protractor Demo App', function () {
  it('should have a title', function () {
    browser.get('http://juliemr.github.io/protractor-demo/');

    element(by.css('h3')).getText().then((text) => {
      console.log('text--->' + text);
    })

  });
});

Update conf.js

In the conf.js file, provide the spec file name to run.

exports.config = {
    framework: 'jasmine',
    seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: ['spec.js']
  }

Start the WebDriver

To start the webdriver execute the command npm run start

Execute Test

To execute the test execute the command npm run test

⚠️ **GitHub.com Fallback** ⚠️