Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling Unknown Errors in protractor

I have a protractor setup with multiple browsers configured through multiCapabilities, running tests on browserstack.

One of my key protractor specs/tests contain the following afterEach() block:

afterEach(function() {
    browser.manage().logs().get("browser").then(function (browserLog) {
        expect(browserLog.length).toEqual(0);
    });
});

that checks that the browser console is empty (no errors on the console).

The problem is: when I run this spec against Internet Explorer, I'm getting an UnknownError:

UnknownError: Command not found: POST /session/6b838fe8-f4a6-4b31-b245-f4bf8f37537c/log

After a quick research, I've found out that IE selenium webdriver does not yet support session logs:

  • [IE] Add support for fetching logs using the webdriver.manage().logs() mechanism

The question is: how can I catch this UnknownError and let the spec pass in case of this specific error?

Or, to turn it around, is it possible to have an afterEach() block capability/browser-specific, or know which currently running capability is it?


I've tried to use try/catch and try relying on exception sender, but console.log() is not executed:

afterEach(function() {
    try {
        browser.manage().logs().get("browser").then(function (browserLog) {
            expect(browserLog.length).toEqual(0);
        });
    }
    catch (e) {
        console.log(e.sender);
    }
});

As a workaround, I'm duplicating the same spec but without that failing afterEach() block, specifically for Internet Explorer.

like image 382
alecxe Avatar asked Dec 21 '14 07:12

alecxe


1 Answers

Found one option - using getCapabilities() to retrieve the current browser name:

afterEach(function() {
    browser.driver.getCapabilities().then(function(caps) {
        var browserName = caps.caps_.browserName;

        if (browserName !== "internet explorer") {
            browser.manage().logs().get("browser").then(function (browserLog) {
                expect(browserLog.length).toEqual(0);
            });
        }
    });
});

In this case browser logs would not be checked if running against Internet Explorer.

like image 141
alecxe Avatar answered Oct 12 '22 01:10

alecxe