Member-only story

How to restart the browser in protractor-cucumber framework or protractor-jasmine

Praveen David Mathew
2 min readFeb 27, 2020

--

The problem at hand:

Solution:

You are trying to access an element instance that was created using the previous browser instance. The workflow is as follow,

  1. You imported the page object instance at the start of the spec using require
  2. A browser instant is created in the onPrepare
  3. Using that instance your page object model gets the element object
  4. But on next ‘It’ the browser restarts but the page object instance remains the same
  5. So when you try to interact with the element, you are getting session ID of non-existing browser.

Solution:

As given in your code, you have your page object as a javascript property, than a function

So what you could do is, reinitiate the page object whenever you restart the browser.

This could be done using npm decahe module: https://www.npmjs.com/package/decache

So whenever, you restart the browser reinitiate the module using below command:

//import in top of the spec
var decache =

--

--

Praveen David Mathew
Praveen David Mathew

Written by Praveen David Mathew

An open source advocator/WebdriverIO Projectcommiter/Postman Supernova/Postman-html-extra contributor/Stack overflow sqa moderator/Speaker

No responses yet