Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

'Error: This driver instance does not have a valid session ID' when accessing ElementFinder in JasmineReporter #2007

Closed
aeisenberg opened this issue Apr 6, 2015 · 1 comment

Comments

@aeisenberg
Copy link

Using Protractor 2.0.0, I am getting an error when accessing the DOM in a JasmineReporter after the last test. It looks like WebDriver.quit() is being called before the specDone event is called.

To reproduce, try the following code:

protractor.conf.js

'use strict';

var fs = require('fs');

exports.config = {

    onPrepare: function () {
        jasmine.getEnv().addReporter({
            specDone: function(result) {
                if (result.failedExpectations.length > 0) {
                    var filename = 'failed-' + result.description + '-' + Date.now() + '.html';
                    browser.findElement(by.css('html')).getOuterHtml().then(function(html) {
                        fs.writeFile(filename + '.html', html);
                    });
                }
            }
        });
    },

    framework: 'jasmine2',

    capabilities: {
        'browserName': 'chrome'
    },

    specs: ['*.spec.js'],

    baseUrl: 'https://docs.angularjs.org/'
};

bad-test.spec.js

describe('Home Page', function () {
    beforeEach(function() {
        browser.get(browser.baseUrl);
    });

    it('should fail', function () {
        expect(true).toBe(false);
    });
    // it('should pass', function () {
    //     expect(true).toBe(true);
    // });
});

When running protractor as above, you will get an exception and protractor will crash. If you uncomment the last test, the first test fails as expected and the html is saved to a file.

In case it's not obvious, my goal is to grab the full html of the page when a spec fails, but that's not possible if the last test fails.

@juliemr
Copy link
Member

juliemr commented Apr 6, 2015

Duplicate of #1938

@juliemr juliemr closed this as completed Apr 6, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants