question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Session ID is null. Using WebDriver after calling quit()?" or "NoSuchSessionError: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used." when next scenario runs

See original GitHub issue

Precondition: test.feature

Feature:  Three tests

Background:
    Given I navigate to "http://www.google.com"

Scenario: one
    When something happens     <------ failed by timeout

Scenario: two
    When something else happens

Scenario: three
    When something else happens

world.js

var pc = require('../../../lib/index.js');
var url = require('../../../lib/get.base.url.js');

var world = function () {
    this.setDefaultTimeout(30000);   <-----   default timeout
    var seleniumAddress = url.getSeleniumHubURL();
    var options = {baseUrl: url.getBaseURL()};
    this.World = pc.world(seleniumAddress, options);
    this.After(function (scenario, callback) {
        this.takeSc(scenario, callback);
    });
};
module.exports = world;

index.js

var protractor = require('protractor');
var World = (function (seleniumAddress, options) {
        var desiredCapabilities = options.desiredCapabilities || {};
        var browserOpt = options.browser || desiredCapabilities.browser || "chrome";
        var timeout = options.timeout || 100000;

        function World() {
            var capabilities = protractor.Capabilities[browserOpt]().merge(desiredCapabilities);
            var driver = new protractor.Builder()
                .usingServer(seleniumAddress)
                .withCapabilities(capabilities)
                .build();

            driver.manage().timeouts().setScriptTimeout(timeout);
            var winHandleBefore;
            driver.getWindowHandle().then(function (result) {
                winHandleBefore = result;
            });

            this.browser = protractor.wrapDriver(driver);
            this.protractor = protractor;
            this.by = new protractor.ProtractorBy;

            if (options.assert) this.assert = options.assert;
            if (options.baseUrl) this.baseUrl = options.baseUrl;
            if (options.properties) this.properties = options.properties;

            console.log("Base URL:" + this.baseUrl);

            this.takeSc = function (scenario, callback) {
                if (scenario.isFailed()) {
                    driver.takeScreenshot().then(function (png) {
                        var decodedImage = new Buffer(png, 'base64');
                        scenario.attach(decodedImage, 'image/png');
                    }).then(function () {
                        driver.quit().then(function () {
                            callback();
                        });
                    });
                }
                else {
                    driver.quit().then(function () {
                        callback();
                    });
                }
            };
        }

        return World;
    });
module.exports.world = World;

steps.js

var steps = function () {
    this.When(/^something happens$/, function (callback) {
        this.browser.sleep(13000);
        this.browser.findElement(this.by.xpath("//somexpath")).getText().then(function (result) {
            callback();
        });
    });

    this.When(/^something else happens$/, function (callback) {
        this.browser.ignoreSynchronization = false;
        this.browser.get("http://gmail.com").then(function () {
            callback();
        });
    });

    this.When(/^Given I navigate to "([^"]*)"$/, function (site, callback) {
        this.browser.ignoreSynchronization = true;
        this.browser.get(site).then(function () {
            callback();
        });
    });
};

module.exports = steps;

Steps to reproduce: 1.The First scenario has fallen by DefaultTimeout (more than 30 secs as mentioned before in world.js) 2. The second scenario starts

Actual result: The second scenario failed with “Session ID is null. Using WebDriver after calling quit()?” exception. But third one is passed.

Expected result The second scenario should passed too. The previous tests should not impact another

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
matanyoscommented, May 7, 2018

@ThaKing what do you mean by rewrite tests to the promises, please?

1reaction
ThaKingcommented, Mar 17, 2017

@pantherqin we started to rewrite our tests to the Promises and seems the error disappeared

Read more comments on GitHub >

github_iconTop Results From Across the Web

This driver instance does not have a valid session ID" when ...
The invalid session ID error is a WebDriver error that occurs when the server does not recognize the unique session identifier. This happens...
Read more >
Invalid Session Id if webdriver not used immediately in ...
“Error: This driver instance does not have a valid session ID (did you call WebDriver. quit()?) and may no longer be used.”
Read more >
Error while closing Webdriver with Google Chrome
After my tests are running i am trying to give these command to close the chrome and web driver instance. ... WebDriverException: Session...
Read more >
AMA: Why I am getting Session id is null? | by Sajitha Pathirana
Using WebDriver after calling quit ()? The session ID is null is a frequent exception that we see while executing tests using WebDriver....
Read more >
"Session ID is null. Using WebDriver after calling quit()?" or ...
or "NoSuchSessionError: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found