Dealing with Unpredictable Errors in Protractor

In my setup for protractor, I have configured multiple browsers through multiCapabilities and am running tests on browserstack.

One of the key protractor specs/tests includes an afterEach() block that checks if the browser console is empty:

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

An issue arises when running this spec on Internet Explorer, where it throws an UnknownError:

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

Upon further investigation, it was discovered that IE selenium webdriver does not currently support session logs:

The question then arises: how can I handle this UnknownError to allow the spec to pass despite encountering this specific error?

Alternatively, is there a way to make the afterEach() block specific to certain capabilities/browsers or identify which capability/browser is currently being used?


Attempts were made using try/catch and relying on the exception sender, but console.log() did not execute as expected:

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

To work around this issue, a duplicate spec was created without the failing afterEach() block specifically for Internet Explorer.

Answer №1

One solution is to use the getCapabilities() method to determine the current browser name:

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

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

If the test is being run on Internet Explorer, the browser logs will not be checked in this scenario.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The URL is being modified, yet the page remains static in the React application

I've been working on setting up a router with react-router-dom, but I'm facing an issue where my URL gets updated without the page routing to the specified component. Here's a snippet from my App.js: import "./App.css"; import { Br ...

Encountered npm error! Issue arose while resolving: [email protected] npm error! Detected: [email protected] during npm installation

I encountered an error while trying to install a project on my new PC using npm. The same project worked perfectly on my old laptop, but now I'm facing this issue. npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While re ...

Why does Prettier choose to omit trailing commas?

After creating a brand new Angular application using ng new test-app, I added Prettier to the devDependencies and successfully installed it. I made sure to disable all extensions in VSCode except for Prettier. The issue arises when I configure VSCode to f ...

Delay the execution using Javascript/jQuery, remove the last element from the DOM

Within a jQuery AJAX call, I am using a $.each() loop. Each element in the response data triggers the addition of a portion of HTML to a container class in my index.html file. To view the code and ensure proper formatting, visit the codepen here as the pa ...

What is the best way to include headers in a jQuery.load function similar to ajax requests

I've been struggling with this issue for a couple of days. I am trying to pass some header data in jQuery.load(). However, it seems that jQuery.load does not send headers like ajax does. Can anyone clarify whether sending headers is necessary in this ...

AngularJS Pagination: Organizing Content Efficiently

Utilizing Bootstrap's Pagination directive to implement pagination in a table. Interestingly, when manually adding data to $scope.transactions (referencing the commented out code in the controller), the pagination functions flawlessly. However, attem ...

Obtain the contenteditable span's value

I'm facing an issue with a content editable span - I want to extract its value when the post button is clicked, but it's not working as expected. Please note that I am unable to convert the span to a textbox or div, I specifically need the value ...

Keep track of numerous clicks and gather all values in a single line

I have a scenario where I need to fetch values from multiple buttons on my webpage and display them together in one line. How can this be achieved? There are 3 buttons, each returning a specific value when clicked: Dark : scoop Danger : swoosh Warning ...

Angular's ng-repeat allows you to iterate over a collection and

I have 4 different product categories that I want to display in 3 separate sections using AngularJS. Is there a way to repeat ng-repeat based on the product category? Take a look at my plnkr: http://plnkr.co/edit/XdB2tv03RvYLrUsXFRbw?p=preview var produc ...

Getting nested documents from an array in Meteor and MongoDB: A step-by-step guide

This is a continuation of my previous inquiry on this topic here on stackoverflow.com. Firstly, I want to express my gratitude to @David Weldon. With his guidance, I successfully organized my update. However, upon retrieving the data from the database, I ...

The request body contains no information

I'm having trouble debugging this issue. Can anyone help me out? When using console.log(req.body), I am getting an empty object {}. I've tried multiple approaches but still can't figure out the problem. Even after attempting to use middle ...

Implementing a loop in JSON with Angular: A step-by-step guide

I have a task to generate a JSON structure that looks like the following: "combinationsData":[ { "combinationName":"2_2", "dataGroups": [ { "tableType":"2",//This value comes from HTML "twoAxisDat ...

Chrome Extension Tip: Reloading or re-executing a content script when an Ajax request is made

My goal is to run a content script on a specific website (like injecting a button or changing a link), but I want this to happen while the user is browsing the site. The issue is that the webpage is dynamically constructed with ajax requests as the user n ...

How can I create an HTML link that opens a drop-down menu with form functionality?

Feeling a bit perplexed here as I'm not entirely sure how to label this issue... If you're familiar with the Facebook interface, I'm trying to develop a feature similar to the "DOWNWARD ARROW" icon found next to the "comments" or "status" b ...

What is causing .then() to not wait for the promise to resolve?

I'm currently delving into an Angular project, and I must admit, it's all quite new to me. My confusion lies in the fact that the .then() function doesn't seem to be waiting for the promises to resolve. Could this have something to do with ...

Using the Ionic framework to transfer data from a controller variable to a page

Hey there! I'm currently working on a hybrid app using the Ionic Framework, but I believe my error lies more within Angular. Here's the code snippet that's giving me trouble: <ion-view class="back" ng-controller="webCtrl" view-title="{{ ...

Setting default parameters for TypeScript generics

Let's say I define a function like this: const myFunc = <T, > (data: T) => { return data?.map((d) => ({name: d.name}) } The TypeScript compiler throws an error saying: Property 'name' does not exist on type 'T', whic ...

Vue.js - when it comes to rounding off digits, I keep getting unexpected results

Currently, I am in the process of calculating my totals and I need to ensure that they are fixed to 2 decimal places. Here is a snippet of my code: this.selectedCompaniesDetails.forEach((company) => { if(company.id == p.compa ...

Tips for resolving a 422 error on GitHub when attempting to create a repository using an Android device

After deleting an old repository, I attempted to create a new one which led to an error. I have been using my phone for a long time to delete and create repositories without any issues, so I'm not sure what changed today. I reached out to chat GPT fo ...

Angular enables draggable and resizable components

Are there any Angular equivalents to the great draggable and resizable widgets offered by jQueryUI? I am looking for alternatives to using jQueryUI. Is it possible to make my modal draggable and resizable without relying on jQueryUI? ...