I am new at using Protractor and just started using it a month or so ago. I am using Protractor 2.5.1 and cucumber NOT Jasmine; I have been running into session ID issues with my tests lately.
Sometimes my tests pass and sometimes they fail with this error: (This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used.)
The only suggestion I found online was that this happens when you do not use callback()
but that doesn't seem to be true as I used callbacks in my cucumber tests and that didn't prevent it. Another solution suggested was to set a max width to the window size, that didn't cut it either
.
Here's what I tried:
- I know that the driver wouldn't quit if there was one more step after the last one, like a 'stall or no-op' so I added one more step just to give time to the driver to complete last operation but that didn't work.
I use callbacks like this
> this.When(/^I "([^"]*)" and do something with this"([^"]*)"$/, > function (action, result, callback) { > return app.takeAction(action).then(function (res) { > return res === result; //passed in up there > }).then(callback) //notice callback here as suggested //to avoid this invalid session id issue > .then(null, function () { //handle error here > console.log('An error occured'); > }); });
Notice the processing pipiline in code right above, if the callback throws an error for whatever reason, it'll be caught by the last error handler.
Because you have to login to our application, I make sure to log you off before every feature file i.e test. This should destroy previous cookie/session but all of these attempts were unseccussful at resolving this problem.
Oh all my tests run successfully, but then at the very end, fail with that invalid session id error. 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:\
Has anyone run into this issue and what was your fix to it? Any help would be greatly appreciated.
BTW here's my config file:
> exports.config = { framework: 'cucumber', capabilities: {
> 'browserName': 'chrome',
> loggingPrefs: {
> driver: 'DEBUG',
> server: 'INFO',
> browser: 'ALL'
> } },
>
> resultJsonOutputFile: conf.paths.e2e + '/out/test-report.json',
> specs: [
> conf.paths.e2e + '/**/*.feature' ],
>
> selenium server baseUrl: 'http://localhost:3000/application/',
>
> onPrepare: function() {
> console.log('Getting:'+exports.config.baseUrl);
> browser.get(exports.config.baseUrl);
> browser.driver.manage().window().maximize();
> browser.manage().timeouts().setScriptTimeout(15000);
>
> var tmpDir = path.resolve(__dirname, './e2e/screenshots');
> console.log('Clearing tmp dir: ' + tmpDir);
> rimraf(tmpDir, function(error) {
> if (error) {
> console.error('Error clearing tmp dir: ', error)
> }
> }); },
>
> cucumberOpts: {
> require: conf.paths.e2e + '/steps/**/*Steps.js',
> tags: [ '~@wip', '~@manual' ],
> format: 'pretty' } };