Member-only story
How to restart the browser in protractor-cucumber framework or protractor-jasmine
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,
- You imported the page object instance at the start of the spec using require
- A browser instant is created in the onPrepare
- Using that instance your page object model gets the element object
- But on next ‘It’ the browser restarts but the page object instance remains the same
- 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 =…