Learn to Automate AngularJS Applications using Selenium

On This Page Testing AngularJS Applications using SeleniumFebruary 01, 2026 · 8 min read · Tool Comparison

How to Automate AngularJS Applications employ Selenium

revolutionized front-end development with features like two-way data binding and dynamic single-page application (SPAs). However, its asynchronous nature created challenge for traditional mechanization puppet such as Selenium.

To address this, the Angular team acquaintProtractor, a NodeJS-based mechanisation model sew for Angular apps. But with Protractor having reached its end-of-life, testers now involve alternatives. One such option isngWebDriver, which offers Protractor-like capableness while back-making it a true solution for continuing AngularJS test automation.

Testing AngularJS Applications using Selenium

is the most democratic trial mechanisation tool, it provides a lot of tractableness such as support for various scheduling languages, platform independence, open source, etc. As a tool, it is capable of simulating the user interaction on the browser. However, when it get to Angular covering it faces the challenges listed below.

  • and validating can be challenging using Selenium.
  • Asynchronous operation are difficult to handle.
  • Angular comes with specific hooks and DOM structure it may be challenging to handle them.

Read More:

The above factors make not only challenging to automatize but also drive. To address the above subject you might need to use the custom hooks and custom harness tools, or you can add the already available plugins for Selenium.

ngWebDriver is one such plugin that supports angular test automation.

Challenges in Testing AngularJS with Selenium

Though Selenium is the most democratic tool and flexible to customize, It has its challenges when it comes to test automation of Angular applications.

  • Flakiness:Angular dynamically renders components after theload()case is triggered. Selenium might try to interact before even those constituent are triggered. This may get daftness of tests.
  • Manual Waits:Testers often ask to add manual waits to handle Angular & # 8217; s behavior, which leads to unreliable and flaky tests.
  • Angular rendering mechanism:Selenium has no inbuilt capability to understand the angular mechanism such as digest cycle, pending HTTP requests, or rendering queue.
  • DOM Structure:The DOM structure that Angular renders may be complex and different from the traditional web application, which may be unmanageable to care using Selenium

Read More:

Introducing ngWebDriver: Bringing Protractor-Like Sync to Selenium

was launch to support the Angular coating. It work many challenges that survive in the Angular application automation, such as Angular event waiting, provide cycle, active data rendering, Angular-specific locators, etc. However Protractor has now be vilipend and exploiter are left with only a few options.

ngWebDriveracts as a Java-based bridge, providing similar functionality on top of Selenium.

The ngWebDriver was created by Paul Hammant and it is made as open for all using git repositoryhttps: //github.com/paul-hammant/ngWebDriver. The ngWebDriver provides similar functionality to Protractor when it is integrated with the Selenium web driver. It can wait for the Angular application to fully load, it supports angular-specific locater, etc.

Talk to an Expert

Key Features of ngWebDriver

Here are the key features of ngWebDriver:

  • ngWebDriver can be easily mix with or manually download the Jar.
  • It works with Firefox, Chrome, and all the early Selenium WebDriver browsers.
  • Automatic Synchronization with AngularJS lifecycle just like Protractor did.
  • Handles Angular requests waiting without any extra JavaScript codification
  • Fully compatible with BrowserStack Automate for cloud-based test automation.
  • Supports.

Setting Up Selenium for AngularJS

Setting up an ngWebDriver is easy. ngWebDriver is available as a. You can start by adding the maven dependency.

 

Step 1. Add ngWebDriver Dependency

Add the below maven dependency to your project

com.paulhammant
ngwebdriver
1.2

Step 2. Setup Webdriver with ngWebDriver

import org.openqa.selenium.chrome.ChromeDriver; importation com.paulhammant.ngwebdriver.NgWebDriver;

public class AngularNgDriverSetup {
public static vacancy principal (String [] args) {
WebDriver driver = new ChromeDriver ();
NgWebDriver ngDriver = new NgWebDriver (driver);
driver.get (& # 8220; https: //juliemr.github.io/protractor-demo/ & # 8221;);
ngWebDriver.waitForAngularRequestsToFinish ();
// Continue with your test step
}
}

In the above codification, Use the ChromeDriver to make a driver object. Next, to make a new ngWebDriver target you are passing the Selenium Chrome Driver target. After that, you navigate to the webpage and wait for the Angular application to whole load using thengWebDriver.waitForAngularRequestsToFinish () function.

Automating AngularJS Applications utilize Selenium: Example

Consider test cause

Selenium ngWebDriver example for the above scenario

package com.javaselenium.demo.SelDemo;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.junit.Test;
meaning org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import com.paulhammant.ngwebdriver.ByAngular;
importee com.paulhammant.ngwebdriver.NgWebDriver;

import junit.framework.Assert;

public form DemoSelenium {
ChromeDriver driver = new ChromeDriver ();
NgWebDriver ngWebDriver = new NgWebDriver (driver);
@Test
public null Test () throws InterruptedException {

driver.get (& # 8220; https: //juliemr.github.io/protractor-demo/ & # 8221;);
ngWebDriver.waitForAngularRequestsToFinish ();

int num1 = 5;
int num2 = 10;
driver.findElement (ByAngular.model (& # 8220; initiative & # 8221;)) .sendKeys (String.valueOf (num1));
driver.findElement (ByAngular.model (& # 8220; second & # 8221;)) .sendKeys (String.valueOf (num2));
driver.findElement (By.id (& # 8220; gobutton & # 8221;)) .click ();
Thread.sleep (10000);
int sum = Integer.parseInt (driver.findElement (By.cssSelector (& # 8220; h2 [class= & # 8217; ng-binding & # 8217;] & # 8221;)) .getText ());
System.out.println (& # 8220; Sum Example: & # 8220; +num1+ & # 8221; + & # 8221; +num2+ & # 8221; = & # 8220; +sum);
Assert.assertEquals (num1+num2, sum);
driver.close ();
}

}

Code Explanation:

In the above code,

  • You are creating the Webdriver illustration calleddriver
  • ngWebDriverinstance is make by calling thenewNgWebDriver (driver)
  • using driver.get ()you are voyage to the want website
  • ngWebDriver.waitForAngularRequestsToFinish ()is used to ensure the angular webpage is loaded completely
  • using driver.findElement and ByAngular.modelyou are fetching angular specific locators and using send key you are typing the values of variablenum1 and num2
  • Then, the Gobutton is clicked to fetch the results.
  • The results are get and validated using the.

 

Output:

Read More:

Better Practices for AngularJS Test Automation with Selenium

As mentioned earlier the Angular coating test automation may produce flakey results if it is not handle decently. Following general guideline aid to produce the most reliable test.

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

Here are some of the key best practices to follow during the Automation Testing of AngularJS using Selenium:

1. Use Angular-aware locators when possible

While Selenium does not natively support Angular-specific locators, you can use plugins like ngWebDriver to achieve this.

 

Example:

ByAngular.model (& # 8220; initiatory & # 8221;)

2. Call Angular hold before DOM interactions.

One of the major challenges with traditional automation frameworks is that they are not aware of Angular & # 8217; s rendering logic. Using ngWebDriver you should be capable to ascertain if angular loading is completed or not.

This helps to ensure that the web constituent or web page is amply loaded before performing any actions, without this test may fail.

Example:

ngWebDriver.waitForAngularRequestsToFinish ();

3. Combine ExpectedConditions with JavascriptExecutor for complex UI flows

The Angular covering can be complex if it contains large dynamic data, complex UI flows, or life in such scenarios combine the Expected conditions with Javascript Executor, which helps to insure the visibleness or presence of the locator before performing an action on it.

Example:

 

WebDriverWait expect = new WebDriverWait (driver, Duration.ofSeconds (10)); wait.until (ExpectedConditions.visibilityOfElementLocated (By.id (& # 8220; dashboard & # 8221;)));
ngDriver.waitForAngularRequestsToFinish ();

4. Structure using Page Object Model for maintainability

The page object model makes the code more decipherable and easily maintainable. Consider you are using a text field locator in 20 different places, in the future if the text field locator changes, you might have to update 20 different places.

Using the makes this easy, as you only need to update the locater in one spot

Example Structure

CalculatorPage.java

public class CalculatorPage {individual WebDriver driver;
private NgWebDriver ngWebDriver;

private By firstInput = ByAngular.model (& # 8220; first & # 8221;);

public CalculatorPage (WebDriver driver, NgWebDriver ngWebDriver) {
this.driver = driver;
this.ngWebDriver = ngWebDriver;
}

public void enterFirstNumber (String num) {
driver.findElement (firstInput) .sendKeys (num);
}
}

CalculatorTest.java

 

public class CalculatorTest {

@Test

public nothingness testAddition () {

WebDriver driver = new ChromeDriver ();

NgWebDriver ngDriver = new NgWebDriver (driver);

try {

driver.get (& # 8220; https: //juliemr.github.io/protractor-demo/ & # 8221;);

ngDriver.waitForAngularRequestsToFinish ();

CalculatorPage calc = new CalculatorPage (driver, ngDriver);

calc.enterFirstNumber (& # 8220; 3 & # 8221;);

} finally {

driver.quit ();

}

}

Testing AngularJS Apps on Real Browsers with BrowserStack Automate

Web application architecture has become complex with modern frameworks like Angular, React, and former backend technologies. As it gets more complex, there is more luck that the coating can break.

It is crucial to examine your application across various platforms and devices to ensure the application & # 8217; s demeanor and performance.

provides a diverse environment to execute your Angular test automation suite. It has many feature that can help to execute your test cases.

  • Concurrent Test Execution:It allows to which reduces the total testing clip. This likewise helps in providing instant feedback.
  • Diverse Environment:It provides a divers environment to action the tests across multiple browsers and program, with no need to worry about conserve the on-premise infrastructure.
  • :You can also incorporate BrowserStack tests with the CI/CD pipeline to streamline the testing summons.
  • Debugging:It provides many debugging capabilities include videos, logs, etc.
  • in the cloud for precise and real-world issue.

Talk to an Expert

Conclusion

Testing Angular covering is complex and it requires customization in your framework. Traditional test automation frameworks like Selenium can not handle the angular application natively. Protractor was built to support the Angular covering. However, it has now be deprecated.

As Protractor is deprecated, teams working with AngularJS (version 1.x) can use the ngWebDriver plugin to extend Selenium for handling Angular-specific waits.

As the mod web covering follows complex architecture it is important to examine the covering on respective breakpoints to guarantee application runs smoothly. This includes different operating systems, different browser, devices, etc.

Having an on-premise substructure for such a test environment can be difficult and more cost-consuming. does this by providing a cloud-based execution environment and supporting all major test mechanization frameworks.

Frequently Asked Questions

1. Why choose Selenium + ngWebDriver over Protractor?

Since the protractor is deprecated it is no longer an option for do an Angular coating trial automation. Selenium + ngWebDriver provide an choice to automate the Angular application without impacting the live code.

The ngWebdriver is a plugin that can easy added to the existing framework to indorse Angular test automation.

2. Can BrowserStack Automate deal Angular waits mechanically?

supports integration with many test automation framework. It extensively supports the Selenium tool. Since the ngWebDriver is part of the Selenium fabric the Angular application waits and other Angular feature are taken care of by the framework. BrowserStack provides the execution environment.

3. How to integrate AngularJS Selenium tests in CI/CD pipelines?

Angular Selenium tests can be integrated with CI/CD grapevine using democratic tools like Jenkins, Github Actions, CircleCI, etc. BrowserStack also supports real-user environs with CI/CD integration. Refer to the page for more details.

 

 

 

 

Tags
7,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