protractor: Protractor is throwing an error when executing more than two tests with restartBrowserBetweenTests set to true
I am using Protractor 2.0.0 and Chrome 41.0.2272.101.
config.js:
exports.config = {
directConnect: true,
specs: ['testCases/**.js'],
allScriptsTimeout: 10000,
restartBrowserBetweenTests: true,
capabilities: {'browserName': 'chrome'},
baseUrl: 'http://angularjs.org',
jasmineNodeOpts: {showColors: true,isVerbose: true,includeStackTrace: true},onPrepare: function() {require('jasmine-reporters');jasmine.getEnv().addReporter(new jasmine.JUnitXmlReporter('./xmloutput', true, true));
}
};
pageObjects/generalObjects.js:
var m2testWebGeneralObjects = function() {
this.text1 = by.xpath('/html/body/div[1]/div[2]/div/div[2]/p');
};
module.exports = new m2testWebGeneralObjects();
testCases/test1.js (same as test2.js and test3.js):
var m2generalObjects = require('../pageObjects/generalObjects.js');
describe('Test Error', function() {
var ptor;
browser.driver.manage().window().maximize();
beforeEach(function () {
ptor = browser;
});
it('Should display correct content', function() {
ptor.manage().deleteAllCookies();
ptor.get(ptor.baseUrl);
expect(element(m2generalObjects.text1).getText()).toContain('address');
});
});
When I run protractor config.js, after the test1.js is executed I get following error message:
c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:392
throw new Error('This driver instance does not have a valid session ID ' +
^
Error: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.
at checkHasNotQuit (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:392:13)
at flow.execute.then.value (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:365:5)
at [object Object].promise.ControlFlow.runInFrame_ (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1877:20)
at [object Object].promise.ControlFlow.runEventLoop_ (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1755:8)
at [object Object].<anonymous> (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2056:12)
at [object Object].goog.async.run.processWorkQueue [as _onTimeout] (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)From: Task: WebDriver.manage().window().maximize()
at [object Object].webdriver.WebDriver.schedule (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:360:15)
at [object Object].webdriver.WebDriver.Window.maximize (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:1474:23)
at [object Object].<anonymous> (d:\protractor\protractorIssue\testCases\test3.js:6:38)
at [object Object].jasmine.Env.describe_ (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:913:21)
at [object Object].jasmine.Env.describe (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:898:15)
at describe (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:658:27)
at Object.<anonymous> (d:\protractor\protractorIssue\testCases\test3.js:4:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
From: Task: WebDriver.manage().timeouts().setScriptTimeout(10000)
at [object Object].webdriver.WebDriver.schedule (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:360:15)
at [object Object].webdriver.WebDriver.Timeouts.setScriptTimeout (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:1367:23)
at [object Object].Runner.createBrowser (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\lib\runner.js:181:30)
at c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\lib\runner.js:257:21
at _fulfilled (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:797:54)
at self.promiseDispatch.done (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:826:30)
at Promise.promise.promiseDispatch (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:759:13)
at c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:573:44
at flush (c:\Users\pcuser\AppData\Roaming\npm\node_modules\protractor\node_modules\q\q.js:108:17)
at process._tickCallback (node.js:419:13)
[launcher] Process exited with error code 1
For only two files, everything works fine. For 3 files or more the error is thrown.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 31 (10 by maintainers)
@fescobar, respectfully, I’m not sure being snarky is productive.
I have the solution, just remove Protractor from your project. I don’t understand what is the benefit to use this “framework” when you can use directly selenium webdriver. I have to deal with multiple issues only because one of my current projects implement this thing. I think the committers need to learn more about software architecture before starting to build any tool. Good luck!
Is there any update on this issue? Occurring for me as well
I dunno if it helps, but this one below works for me:
If I change the code like:
Protractor (Selenium) throws
UnsupportedOperationError: This driver instance does not have a valid session ID
My conf.ts:
Using protractor 4.0.3, tested on both el capitan and ubuntu 14.04 TLS.
Again, same problem with Protractor 4.0.4. Is there anything we can do to help resolve this issue? Being able to restart the browser between tests is quite important… Thanks!
Update: @marcincharezinski’s approach helped: I replaced any reference to
browser
withprotractor.browser
and it works fine withrestartBrowserBetweenTests
set to true.I’m not really sure what the difference between
browser
andprotractor.browser
is? Could it be that the clean up logic only applies to the latter?