How to Debug Protractor Tests for Selenium Test Automation?

On This Page Importance of Debugging Protractor TestsMay 20, 2026 · 10 min read · Testing Guide

How to Debug Protractor Tests for Selenium Test Automation?

Debugging is crucial for reliable and accurate. Protractor, used for testing Angular application, can represent challenges when diagnosing issues in Selenium-based test suites.

Overview

Debugging Protractor test is crucial to place and fix common failures that can disrupt test stability and accuracy.

Types of Failures You Need To Debug In Protractor Tests

  • Expectation Failure:Happens when the actual coating demeanour does not match the expected value in assertions.
  • WebDriver Failure:Occurs when WebDriver can not locate or interact with an element on the page.
  • WebDriver Unexpected Failure:Results from unexpected issues like browser crashes or driver communication error.
  • Protractor Angular Failure:Arises when Protractor fails to find or sync with the Angular application.
  • Protractor Timeout Failure:Triggered when an operation guide longer than the configured timeout limit.

Some democratic methods to debug in Protractor include:

  • Using console.log ()
  • Debugging protractor trial in chrome inspector
  • Debug Protractor tests expend Visual Studio Code
  • Debug protractor test occupy screenshots dynamically

This article cover mutual problems when debug Protractor tests, type of test failure, the importance of debugging, and efficient ways to debug Protractor Selenium tests.

Note:Protractor was officially deprecated on August 31, 2023, and is no longer recommended for new test automation projects. Consider exploring the.

Importance of Debugging Protractor Tests

Protractor tests can sometimes be flaky or fail due to synchronization issues, timeouts, or unexpected UI change. Here ’ s why debugging Protractor test is a critical part of maintaining a reliable:

  • Helps name the theme cause of exam failure quickly and accurately.
  • Reduces false positives and negatives, improving.
  • Minimizes time spent on maintaining or rerunning.
  • Ensures muse actual user demeanour and app functionality.
  • Supports stable pipeline by preventing unexpected test breakdowns.
  • Improves overall and automation calibre.

Common Problems When Debugging Protractor Tests

Debugging Protractor tests can be challenging due to diverse matter during test performance. Some of the most common problems include:

  • Flaky Tests:Tests that pass or betray inconsistently due to clock issues, asynchronous conduct, or unstable environments.
  • Synchronization Issues:Protractor may fail to wait for Angular to brace before executing the succeeding command.
  • Element Not Found Errors:Occur when selectors are wrong or element occupy time to load and aren ’ t nowadays when the test runs.
  • Timeout Errors:Happen when an factor or condition isn ’ t met within the configured delay time.
  • Stale Element Reference:Happens when the DOM updates and the referenced element is no longer valid.
  • Browser Compatibility Issues:Tests might carry differently across browsers if not handled properly.
  • Improper Use of Waits:Using motionless waiting (browser.sleep) instead of dynamic waits can lead to essay instability.
  • Environment-Specific Failures:Tests may surpass locally but miscarry in CI due to differences in configuration, information, or performance.

Types Of Failures You Need To Debug In Protractor Tests

When running Protractor exam, you may encounter different types of failures. Each failure type points to a specific issue in your test setup, application behavior, or. Understanding these class helps streamline your debugging process.

1. Expectation Failure

Expectation failures happen when the actual result of your application does not match the expected result defined in your tryout assertions. This much occurs due to incorrect assumptions, data mismatches, or UI alteration.

How to debug:

  • Cross-check expected values against the current coating state.
  • Log the actual values during runtime for proof.
  • Confirm that the factor or datum are loaded before assertions are evaluated.

2. WebDriver Unexpected Failure

These failure originate from the underlying WebDriver and are often irregular. They may be have by browser clangoring, session timeouts, or infrastructure-level disruptions.

How to debug:

  • Investigate browser and system logs for crash details.
  • Ensure browser and WebDriver versions are compatible.
  • Re-run tests in different environments or browsers to identify patterns.

3. WebDriver Failure

This type of failure occurs when WebDriver can not locate or interact with a page ingredient. Common causes include lose component, DOM changes, or elements not being ready for interaction.

How to debug:

  • Double-check the selectors expend in your tests.
  • Add waits to ensure the elements are usable before interacting with them.
  • Review application changes that may have affect element profile or structure.

4. Protractor Timeout Failure

Timeout failures happen when an action or condition takes too long to dispatch and exceeds the set timeout limits. These can be due to performance matter, heavy page loads, or slow living.

How to debug:

  • Increase timeout scope if the default limit is insufficient.
  • Use explicit hold to handle expected delays.
  • Review app execution and load behavior to identify bottlenecks.

5. Protractor Angular Failure

These failure occur when Protractor can not detect or sync with Angular on the page. It typically happens in non-Angular or, or when Angular hasn & # 8217; t finished initializing.

How to debug:

  • Check if your app is fully Angular-based.
  • For non-Angular pages, disable Angular synchronization.
  • Ensure that Angular has fully bootstrapped before interaction begin.

Why is Debugging Important in Protractor Tests?

Debugging is critical in maintaining the dependableness and accuracy of Protractor. It involves identifying the root cause of exam failures, canvas the underlying issues, and secure them to ensure the tests reflect the real behavior of the covering.

Protractor examination may fail due to a variety of ground, including:

  • Elements not being found on the page
  • Protractor require failing to fulfill in the browser
  • Elements conduct too long to freight, resulting in timeout errors
  • Failures arising from WebDriver-related issues
  • Other unexpected errors in the test flow or application behavior

In many instance, failures can be false negative, where the application is work as expected but the test betray due to poor synchronization, wrong selectors, or outdated test logic. Debugging helps distinguish real issue from false ones.

By thoroughly debugging fail test causa, you can:

  • Pinpoint the exact extraction and type of the error
  • Eliminate flaky tests and better test stability
  • Save clip by direct the right number instead of making arbitrary alteration
  • Ensure your automated tests provide accurate, actionable feedback on application quality

Ultimately, debug ensures that your Protractor test suite remains dependable and meditate the true health of your web application.

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

To streamline the debugging process and insure precise test results, it ’ s all-important to run your Protractor tests in a stable, real-device environment. proffer cloud-based access to a wide range of real browsers and devices, allowing you to reproduce issues easily, test in different surround, and debug faster with puppet like alive logarithm, picture recordings, and screenshots, all without complex local frame-up.

Talk to an Expert

How to debug Protractor Selenium tests?

Protractor provides assorted options to debug, which makes it developer friendly. Since debugging Protractor Selenium Tests can be desegregate with Visual Code, you can also utilize the VSCode debugging features.

Some popular methods to debug in Protractor include:

  1. Using console.log ()
  2. Debugging protractor tests in chrome inspector
  3. Debug Protractor tests using Optic Studio Code
  4. Debug protractor tests direct screenshots dynamically

Prerequisites:

Debug Protractor Tests using console.log ()

This is the most favorite option for javascript developers. The console.log () outputs the specified value in the console or terminal while executing.

For instance, if you need to know the text revert by the element you can use the console log as shown below.

//demo.spec.js const {browser} = require ('protractor '); describe ('Protractor Test Demo ', () = & gt; {it ('Navigate to BrowserStack Homepage ', async () = & gt; {await browser.waitForAngularEnabled (mistaken); await browser.get ('https: //www.browserstack.com '); const product_menu_text = await browser.element (by.id ('product-menu-toggle ')) .getText (); console.log (`` The production menu textbook is: `` + product_menu_text) expect (product_menu_text) .toEqual ('Products ')});});

In the above code, the console.log (& # 8220; The product menu text is: & # 8221; + product_menu_text) line has been used to display the & # 8216; product-menu-toggle & # 8217; inner text in the pole.

When you fulfill the protractor test you will see the yield as shown below

Debug Protractor Tests using Chrome Inspector

Protractor also supports debugging the test habituate the Chrome debugger or chrome inspector tool. Here & # 8217; s how to debug Protractor tests expend the Chrome inspector

Step 1: Add the debugger statement to your test

You need to add thedebugger;statement at the desired place in your protractor scripts.

//demo.spec.js const {browser} = require ('protractor '); describe ('Protractor Test Demo ', () = & gt; {it ('Navigate to BrowserStack Homepage ', async () = & gt; {await browser.waitForAngularEnabled (false); await browser.get ('https: //www.browserstack.com '); debugger; const product_menu_text = await browser.element (by.id ('product-menu-toggle ')) .getText (); console.log (`` The product carte text is: `` + product_menu_text) expect (product_menu_text) .toEqual ('Products ')});});

In the above example, thedebugger;statement has been added after the browser.get() command.

Step 2: Launch the protractor test using the below dictation

node -- inspect-brk node_modules\protractor\bin\protractor protractor.conf.js

Step 3: Navigate to Chrome and launch the inspect instrument

Open the chrome and enter the below line

chrome: //inspect/ # devices

Step 4: Click on inspect

Step 5: The Node DevTools window outdoors

The NodeJS DevTools window Opens

Click on theResume handwriting executionbutton as shown in the below image

Step 6: Debug the Protractor exam

Once you hit theResume script executingpush, the protractor examination starts executing and halts at the line where you experience placed thedebugger; line.

You can hover over the commands or fulfill lines to check, analyze or debug your playscript.

Click on Resume script execution to continuethe test performance.

Also-Read:

Debug Protractor Tests using Visual Studio Code

The Visual Studio code is the most flexible and advanced IDE, providing many developer-friendly tools to debug.

How to debug Protractor tryout to debug in Visual Studio Code

Step 1: Configure launch.json

From the Runcard Click onAdd Configuration

Step 2: Add the configuration to launch.json

Once you click on Add configuration thelaunch.jsonfile opens automatically add the below configurations

{'' variation '': `` 0.2.0 '', '' constellation '': [{'' type '': `` node '', '' request '': `` launch '', '' name '': `` Launch Program '', '' skipFiles '': ['' & lt; node_internals & gt; / * * ''], '' broadcast '': `` $ {workspaceFolder} \\node_modules\\protractor\\bin\\protractor '', '' args '': [`` $ {workspaceFolder} \\protractor.conf.js '']}]}

In the above code, the program option specifies the itinerary to the Protractor binary.

The argsoption value isyour protractor constellation file path

Step 3: Add the fault point in VSCode and debug the test

You can use the debugger menu to Continue, Step Into, Step Over, Step Out, Restart or Stop options to debug your test. Hovering on the executed line provides values of variables/objects

Debug Protractor Tests taking the Screenshot

Taking the screenshot helps to debug the tryout by identifying the web pages which are causing the error. This selection is helpful when your tests are lead in CI/CD pipelines.

Step 1: Add the function to indite the screenshot to register

var fs = require ('fs '); function writeScreenShot (data, filename) {var stream = fs.createWriteStream (filename); stream.write (new Buffer (data, 'base64 ')); stream.end ();}

The above codification writes the base64 datum to the specified file name

Step 2: Call the writeScreenShot function

Once you define thewriteScreenShotmap you can call it from anyplace in your trial to save the screenshot to file

describe ('Protractor Test Demo ', () = & gt; {it ('Navigate to BrowserStack Homepage ', async () = & gt; {await browser.waitForAngularEnabled (false); await browser.get ('https: //www.browserstack.com '); const product_menu_text = await browser.element (by.id ('product-menu-toggle ')) .getText (); console.log (`` The product card text is: `` + product_menu_text) png = await browser.takeScreenshot (); wait writeScreenShot (png, 'exception.png '); expect (product_menu_text) .toEqual ('Products ')});});

As you can see in the above codification

png = await browser.takeScreenshot (): returns the base64 encode png for screenshot

await writeScreenShot (png, & # 8216; exception.png & # 8217;): writes the base64 encoded png to file

Step 3: Put everything together in Protractor tests

Combining both Step 1 and Step 2 code ply the complete test and captures the screenshot

//demo.spec.js const {browser} = require ('protractor '); var fs = require ('fs '); part writeScreenShot (datum, filename) {var stream = fs.createWriteStream (filename); stream.write (new Buffer (data, 'base64 ')); stream.end ();} describe ('Protractor Test Demo ', () = & gt; {it ('Navigate to BrowserStack Homepage ', async () = & gt; {await browser.waitForAngularEnabled (false); await browser.get ('https: //www.browserstack.com '); const product_menu_text = await browser.element (by.id ('product-menu-toggle ')) .getText (); console.log (`` The ware menu text is: `` + product_menu_text) png = await browser.takeScreenshot (); await writeScreenShot (png, 'exception.png '); expect (product_menu_text) .toEqual ('Products ')});});

Conclusion

The Protractor framework is one of the democratic tools, however, it will be vilipend. As theAngular squad citation, to update Protractor with the late Selenium changes, they need to rewrite the codification, similar to building a new framework.

  • The good alternate puppet to Protractor, which shares like architecture and features, isNightwatchJS.
  • It is up to date with the late technology and progress with modern architecture as it uses the Selenium W3C protocol under the punk, which means you can do almost everything you do with Selenium and Protractor.
  • It provides a powerfuldebug lineamentthat get the developer & # 8217; s living easy.
  • You can easilymigrate your Protractor tests to NightwatchJSand make your new try model up and lead in a short period.

Tags
79,000+ Views

# Ask-and-Contributeabout this topic with our Discord community.

Related Guides

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free