• 25-Jan-2023
Lightrun Team
Author Lightrun Team
Share
This article is about fixing Bug: DevToolsActivePort File doesn't exist in Angular Protractor

Bug: DevToolsActivePort File doesn’t exist in Angular Protractor

Lightrun Team
Lightrun Team
25-Jan-2023

Explanation of the problem

The issue being reported is related to running chrome directconnect in the browser. The error message that is displayed is “WebDriverError: unknown error: DevToolsActivePort file doesn’t exist.”. This issue is similar to the one reported in the log on the SeleniumHQ/selenium GitHub repository at https://github.com/SeleniumHQ/selenium/issues/5964.

The environment in which the issue is occurring includes the following:

  • Node Version: 6
  • Protractor Version: 5.3.1
  • Angular Version: N/A
  • Browser: chrome
  • Operating System and Version: windows 10

The following is the protractor configuration file, which is provided in the report:

let config = {
    allScriptsTimeout: 11000,
    specs: [
        './specs/**.spec.ts'
    ],
    capabilities: {
        'browserName': 'chrome',
        'useAutomationExtension': false,
        'args': ['--disable-gpu','-disable-dev-shm-usage','--no-sandbox','-disable-popup-blocking','--start-maximized','--disable-web-security','--allow-running-insecure-content','--disable-infobars']
    },
    params: {
        basePath
    },
    directConnect: true,
    baseUrl:  basePath,
    framework: 'jasmine',
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 30000,
        print: function () { }
    },
    useAllAngular2AppRoots: true,
    beforeLaunch: function () {
        require('ts-node').register({
            lazy: true
        });
    }
};

This config file specifies that the browser used is chrome, and the directConnect is set to true. It also specifies several capabilities and arguments passed to the browser when it starts. Additionally, it uses the ‘jasmine’ framework and it has a beforeLaunch function that uses ‘ts-node’ to register the code.

The issue is related to an error that occurs when attempting to run chrome directconnect, specifically an error related to the DevToolsActivePort file. It appears that this issue is similar to one that has been previously reported on the SeleniumHQ/selenium GitHub repository. Based on the provided environment and configuration, it is likely that the issue is caused by a problem with the DevToolsActivePort file or the configuration of the directConnect feature.

Troubleshooting with the Lightrun Developer Observability Platform

Getting a sense of what’s actually happening inside a live application is a frustrating experience, one that relies mostly on querying and observing whatever logs were written during development.
Lightrun is a Developer Observability Platform, allowing developers to add telemetry to live applications in real-time, on-demand, and right from the IDE.

  • Instantly add logs to, set metrics in, and take snapshots of live applications
  • Insights delivered straight to your IDE or CLI
  • Works where you do: dev, QA, staging, CI/CD, and production

Start for free today

Problem solution for Bug: DevToolsActivePort File doesn’t exist in Angular Protractor

The problem that is being described seems to be related to the configuration of the webdriver and the versions of the tools being used. The first answer suggests that the problem might be related to the version of Puppeteer and Chrome and that using certain flags might help to resolve the issue. Specifically, the user has tried using different versions of Puppeteer, Puppeteer@1.1.1 (Chrome 66) and Puppeteer@1.5.0 (Chrome 69), and they have also used flags such as [‘–headless’, ‘–disable-gpu’, ‘–no-sandbox’, ‘–disable-extensions’, ‘–disable-dev-shm-usage’] to try and resolve the issue.

Puppeteer is a Node library that provides a high-level API to control Chrome or Chromium over the DevTools Protocol. This means that it allows users to automate various tasks in the browser, such as generating screenshots, crawling web pages, and more. The version of Puppeteer that you are using determines the version of Chrome or Chromium it will be using. It’s possible that the problem is related to compatibility issues between the versions of Puppeteer, Chrome and the flags used. The user should check the compatibility of these versions and the flags used, and if needed, try different versions or flags.

The second answer suggests that the problem might be related to the way the webdriver is started and that changing the permissions used to start the webdriver might help to resolve the issue. The user solved the issue by using “webdriver-manager start” instead of “sudo webdriver-manager start”. This implies that the problem might be related to the permissions that are being used to start the webdriver. When using ‘sudo’, it’s running the command as the superuser (root) and it can have access to more system resources and files than a regular user. However, it also means that it can potentially cause more problems if something goes wrong. So, by running the command without ‘sudo’, the user is running it with the permissions of the current user and might avoid some issues that the superuser permissions might cause.

In general, the problem seems to be related to the configuration of the webdriver and the versions of the tools being used. The user needs to adjust the versions of the tools and the way the webdriver is started to resolve the issue. They might also need to adjust some flags related to the headless mode and permissions of the webdriver-manager. It’s possible that the problem is a combination of both, and the user needs to try different solutions and configurations to resolve the issue. They could also check the documentation of the tools they are using to get more information on the issue and potential solutions.

Other popular problems with Angular Protractor

Problem: Stale element reference exception when working with elements

When working with elements in Angular Protractor, there might be times when the test script is unable to interact with an element that it previously located. This can be caused by the page being updated while the script is running, which can cause the element to become stale and no longer match the previously located element. This can result in the error message “stale element reference: element is not attached to the page document” being thrown.

Solution:

To resolve this issue, one solution is to use the ExpectedConditions class in Protractor to wait for the element to become present and interactable before attempting to interact with it. Another solution is to use the browser.wait() function with a condition that checks if the element is present, and if it is not, the script will retry finding the element.

Problem: Asynchronous nature of Angular causing issues with test execution

Angular applications are built using a heavily asynchronous architecture, which means that many operations are performed asynchronously and may not be completed when the script is executed. This can lead to issues with test execution, such as tests passing or failing incorrectly due to elements not being fully loaded or actions not being completed.

Solution:

To resolve this issue, one solution is to use the browser.wait() function with a condition that checks if the element is present, and if it is not, the script will retry finding the element. Another solution is to use the browser.sleep() function to pause the script for a specified amount of time, allowing for the asynchronous operations to complete before continuing with the test.

Problem: Issues with handling multiple browser windows or tabs

When working with Angular Protractor, it is common for applications to open multiple browser windows or tabs. This can be caused by various actions such as button clicks, links or pop-ups. Handling multiple windows or tabs can be difficult and lead to issues with test execution.

Solution:

To resolve this issue, one solution is to use browser.getAllWindowHandles() function to switch between different windows or tabs. It can also use browser.switchTo().window() method to switch to a specific window or tab based on its handle.

A brief introduction to Angular Protractor

Angular Protractor is an end-to-end testing framework for Angular applications. It is built on top of WebDriverJS, which is a JavaScript implementation of the W3C WebDriver specification, and allows users to automate various tasks in the browser, such as interacting with elements, navigating to different pages, and more. It is specifically designed to work with Angular applications, and provides additional functionality and APIs to make testing Angular applications easier.

Angular Protractor uses a concept called “element finders” to locate elements on the page. These element finders are used to locate elements by their CSS selectors, ID, name, and more. Once an element is located, it can be interacted with using various methods such as .click(), .sendKeys(), .getText(), etc. Angular Protractor also provides an ExpectedConditions class that can be used to wait for specific conditions to be met before interacting with elements. This allows for more robust and reliable tests, as it ensures that elements are present and interactable before attempting to interact with them.

Most popular use cases for Angular Protractor

  1. Angular Protractor can be used to automate end-to-end testing of Angular applications. This includes automating various tasks such as navigating to different pages, interacting with elements, and asserting that the application behaves as expected. This can be done by writing test scripts that use the Protractor API to interact with the application, and using Jasmine or Mocha as the testing framework.
  2. Angular Protractor can be used to test the behavior of the application when it is running in a real browser. This allows for more accurate testing, as it allows for testing of features such as browser compatibility, and allows for the testing of the application as it will be used by end-users. This can be done by using the browser.get() method to navigate to the application under test and use the various methods provided by Protractor such as element() and by.css() to interact with the application.
  3. Angular Protractor can be used to test the performance of Angular application. This can include testing the time it takes for the application to load, testing the time it takes for specific elements to be rendered, and testing the time it takes for specific actions to be completed. This can be done by using browser.executeScript() method to measure the time it takes for a specific action to be completed.
browser.executeScript('return window.performance.timing.loadEventEnd -
window.performance.timing.navigationStart;').then(function(loadTime) {
    console.log('Page load time is ' + loadTime + 'ms');
})
Share

It’s Really not that Complicated.

You can actually understand what’s going on inside your live applications. It’s a registration form away.

Get Lightrun

Lets Talk!

Looking for more information about Lightrun and debugging?
We’d love to hear from you!
Drop us a line and we’ll get back to you shortly.

By submitting this form, I agree to Lightrun’s Privacy Policy and Terms of Use.