angular / protractor

E2E test framework for Angular apps

Home Page:http://www.protractortest.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Avijoy7 opened this issue · comments

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

@Avijoy7 : You can use afterEach function to achieve this

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

@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