2


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:

  1. 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.
  2. 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');
    >       });   });
    
    1. 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.

    2. 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'   } };
pelican
  • 5,846
  • 9
  • 43
  • 67
  • What if you would upgrade to the latest cucumber and protractor? Still reproducible? (also run `webdriver-manager update` please). – alecxe Dec 23 '15 at 14:53
  • Thanks but webdriver-manager udpate was already up to date; protractor which was 2.5.1 is now "_id": "protractor@3.0.0" and cucumber which was 0.6.0 is now "_id": "cucumber@0.9.2", but now the browser won't even open and navigate to URL; I'll run npm update and see what happens. I have an issue with msbuild failing on my windows 10 machine when updating cucumber, but that's probably another question in itself for later. – pelican Dec 23 '15 at 15:33
  • Yeah updating npm doesn't do it; I updated both protractor and cucumber; I also deleted my node_modules folder and ran `npm install` which brought in all the updated modules but still same problem. Any other idea you may think of? – pelican Dec 23 '15 at 15:47

0 Answers0