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

This driver instance does not have a valid session ID after browser.restart() #3648

Closed
romario333 opened this issue Oct 18, 2016 · 6 comments · Fixed by #3658
Closed

This driver instance does not have a valid session ID after browser.restart() #3648

romario333 opened this issue Oct 18, 2016 · 6 comments · Fixed by #3658
Assignees
Milestone

Comments

@romario333
Copy link

Bug report

  • Node Version: 6.7.0
  • Protractor Version: 4.0.9
  • Browser(s): chromedriver_2.24
  • Operating System and Version OS X 10.11.6

Clone browser-restart-bug to reproduce the bug.

Similar issue has been reported here: #2001 (note that I still see the bug with the latest protractor).

I use protractor together with typescript. My test looks like this:

import {browser} from 'protractor';

describe('Test', () => {
  afterEach( () => {
    browser.restart();
  });

  it('Go to angular', () => {
    browser.get('https://angularjs.org/');
  });

  it('Go to angular-tutorial', () => {
    browser.get('https://docs.angularjs.org/tutorial');
  });
});

This fails with:

Failures:
1) Test Go to angular-tutorial
  Message:
    Failed: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.
  Stack:
    NoSuchSessionError: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.
        at WebDriverError (/Users/romario/tmp/browser-restart-bug/node_modules/selenium-webdriver/lib/error.js:27:5)
        at NoSuchSessionError (/Users/romario/tmp/browser-restart-bug/node_modules/selenium-webdriver/lib/error.js:170:5)
        at checkHasNotQuit (/Users/romario/tmp/browser-restart-bug/node_modules/selenium-webdriver/lib/webdriver.js:395:15)
        at Driver.schedule (/Users/romario/tmp/browser-restart-bug/node_modules/selenium-webdriver/lib/webdriver.js:356:5)
        at Navigation.to (/Users/romario/tmp/browser-restart-bug/node_modules/selenium-webdriver/lib/webdriver.js:1027:25)
        at Driver.get (/Users/romario/tmp/browser-restart-bug/node_modules/selenium-webdriver/lib/webdriver.js:795:28)
        at ProtractorBrowser.get (/Users/romario/tmp/browser-restart-bug/node_modules/protractor/built/browser.js:482:21)
        at Object.it (/Users/romario/tmp/browser-restart-bug/build/browser-restart-spec.js:11:30)
        at /Users/romario/tmp/browser-restart-bug/node_modules/jasminewd2/index.js:94:23
        at new ManagedPromise (/Users/romario/tmp/browser-restart-bug/node_modules/selenium-webdriver/lib/promise.js:1082:7)
    From: Task: Run it("Go to angular-tutorial") in control flow
        at Object.<anonymous> (/Users/romario/tmp/browser-restart-bug/node_modules/jasminewd2/index.js:79:14)
    From asynchronous test:
    Error
        at Suite.describe (/Users/romario/tmp/browser-restart-bug/build/browser-restart-spec.js:10:5)
        at Object.<anonymous> (/Users/romario/tmp/browser-restart-bug/build/browser-restart-spec.js:3:1)
        at Module._compile (module.js:556:32)
        at Object.Module._extensions..js (module.js:565:10)
        at Module.load (module.js:473:32)
        at tryModuleLoad (module.js:432:12)

If I don't import browser at the first line, test works (tsc fails, but test itself passes). If I use protractor.browser instead of browser test passes as well.

@cnishina
Copy link
Member

So after investigation, I also tried a few things. This is what I think is happening... the browser object is not being reassigned after we attempt to replace the browser object on a restart.

First experiment, run the existing test and verify sessions:

Running your test, webdriver creates a new session ac882d3ce7c0d99292439bf3405780058fcca0a6:

12:42:42.115 INFO - Selenium Server is up and running
12:42:47.378 INFO - Executing: org.openqa.selenium.remote.server.handler.GetAllSessions@59d40c84)
12:42:47.380 INFO - Done: org.openqa.selenium.remote.server.handler.GetAllSessions@59d40c84
12:42:47.492 INFO - Executing: [new session: Capabilities [{count=1, browserName=chrome}]])
12:42:47.507 INFO - Creating a new session for Capabilities [{count=1, browserName=chrome}]
Starting ChromeDriver 2.24.417412 (ac882d3ce7c0d99292439bf3405780058fcca0a6) on port 22871

After that, we call restart. We are still looking for this session: ac882d3ce7c0d99292439bf3405780058fcca0a6:

    Failed: no such session
      (Driver info: chromedriver=2.24.417412 (ac882d3ce7c0d99292439bf3405780058fcca0a6),platform=Mac OS X 10.11.6 x86_64) (WARNING: The server did not provide any stacktrace information)

But when I navigate to http://localhost:4444/wd/hub, the sessions that are still open are reported as 07091879-cd2e-45c0-a35f-ab830e049756.

Second experiment, report sessions based on browser and protractor.browser:

afterEach( () => {
    protractor.browser.restart();
  });

  it('Go to angular', () => {
    // console.log(browser);
    protractor.browser.get('https://angularjs.org/');

  });

  it('Go to angular-tutorial', () => {
    console.log(browser.driver);
    // browser.driver.getSession().then((session) => {
    //   console.log(session);
    // })
    protractor.browser.driver.getSession().then((session) => {
      console.log(session);
    });
    protractor.browser.get('https://docs.angularjs.org/tutorial');
  });
  • browser.driver.getSession() did not work. console logging the browser.driver showed that there were no sessions available on the object
  • protractor.driver.getSession() does work. console logging shows that there is a session object:
Session {
  id_: '512b1a79-61a4-4c07-be81-4b270538aa7b',
  caps_:
   Capabilities {
     'applicationCacheEnabled' => false,
     'rotatable' => false,
     'mobileEmulationEnabled' => false,
     'networkConnectionEnabled' => false,
     'chrome' => { chromedriverVersion: '2.24.417412 (ac882d3ce7c0d99292439bf3405780058fcca0a6)',
     userDataDir: '/var/folders/gx/4cw5vsyj4lx332w66xwdxwpm00b14w/T/.org.chromium.Chromium.vvxDmC' },
     'takesHeapSnapshot' => true,
     'pageLoadStrategy' => 'normal',
     'databaseEnabled' => false,
     'handlesAlerts' => true,
     'hasTouchScreen' => false,
     'version' => '54.0.2840.59',
     'platform' => 'MAC',
     'browserConnectionEnabled' => false,
     'nativeEvents' => true,
     'acceptSslCerts' => true,
     'webdriver.remote.sessionid' => '512b1a79-61a4-4c07-be81-4b270538aa7b',
     'locationContextEnabled' => true,
     'webStorageEnabled' => true,
     'browserName' => 'chrome',
     'takesScreenshot' => true,
     'javascriptEnabled' => true,
     'cssSelectorsEnabled' => true } }

@cnishina
Copy link
Member

cnishina commented Oct 20, 2016

This appears to be a TypeScript bug when importing browser and calling browser.restart or when a user sets the restartBrowserBetweenTests flag in their config.

@cnishina
Copy link
Member

Attempts to fix:

Since the global protractor worked, possibly using the global browser will also work. I changed thelib/index.ts and lib/runner.ts to always use the global browser variable. After running the tests again, the results were the same. My guess is that the exports.browser is not a reference to the global['browser'] but just the returned object. This is unfortunate.

cnishina added a commit to cnishina/protractor that referenced this issue Oct 20, 2016
@cnishina cnishina self-assigned this Oct 22, 2016
cnishina added a commit to cnishina/protractor that referenced this issue Oct 25, 2016
cnishina added a commit to cnishina/protractor that referenced this issue Oct 25, 2016
cnishina added a commit to cnishina/protractor that referenced this issue Oct 25, 2016
cnishina added a commit to cnishina/protractor that referenced this issue Oct 25, 2016
cnishina added a commit to cnishina/protractor that referenced this issue Oct 25, 2016
@heathkit heathkit added this to the 4.0.11 milestone Nov 9, 2016
@monkpit
Copy link
Contributor

monkpit commented Jan 19, 2018

I am still seeing this issue. Protractor 5.2.2, node 7.10.1, typescript 2.6.1. After browser.restart() I either get no such session errors, or I get 1 browser instance that never gets closed, and a new instance gets created after restart.

EDIT: I attempted to create a minimal test case to reproduce this issue, and I discovered it was being caused by the protractor-timeline-plugin plugin being included in my protractor.conf. When I removed the plugin from my original project, the issue was resolved. Mystery solved.

@oliamb
Copy link

oliamb commented Feb 27, 2018

Isn't it that the import of browser is static, so if your browser restart, you must instead use protractor.browser?

@shivangi4796
Copy link

restart browser works fine for me but when I run scripts on Jenkins I see the same issue.
This driver instance does not have a valid session ID

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

Successfully merging a pull request may close this issue.

6 participants