Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Getting the ERROR "This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used." When I try to use restart() or close() method #5552

Open
Avijoy7 opened this issue May 28, 2022 · 2 comments

Comments

@Avijoy7
Copy link

Avijoy7 commented May 28, 2022

Hi there!

I am trying to execute an extremely simple code. No page object, no method calling from different classes , no customizing configuration file. I am just trying to open a browser, then close it and then open a new browser instance.
#My Conf.js file is :

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

#My spec file is:

const { browser, protractor } = require("protractor");
describe('abcd',  () => {
    it('Restart the browser', () => {
        browser.get('https://material.angular.io/')
        .then(()=>(browser.restart()))
        .then(()=>(browser.get('https://material.angular.io/')));
    });
       it ('2', async  () => {
        await browser.waitForAngularEnabled(false);
        await browser.get('https://www.google.com');
        await element(by.xpath("//input[@name='q']")).sendKeys('asdaf');
        await browser.close();
    });`
});

I want to close the browser after each It block and open a new instance of a browser in the next It block. I know that we can use restartAfterEachTest in the configuration file to restart browsers, but I am not looking for that, I want to close and open browsers from my Spec file.

If I use browser.restart() it shows me the is error "This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used." and the IT block is failed.

If I use browser.close() , the first It block is passing but all subsequent It blocks are getting failed immediately and the error is "Invalid Session ID".

Looking for a solution, thanks in advance

@sopansagorkar
Copy link

@Avijoy7 : You can use afterEach function to achieve this

afterEach (function(){
        driver.close();
    });

@Avijoy7
Copy link
Author

Avijoy7 commented Jul 15, 2022

@Avijoy7 : You can use afterEach function to achieve this

afterEach (function(){
        driver.close();
    });

I have already mentioned in the description that methods like, restart(), close(), quit() are not working. It's not about creating another block of afterEach. anyways, thanks for your help

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants