"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 issuePrecondition: 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:
- Created 7 years ago
- Comments:14 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ThaKing what do you mean by rewrite tests to the promises, please?
@pantherqin we started to rewrite our tests to the Promises and seems the error disappeared