Skip to main content

AngularJS Test Automation: Perform AngularJS Automated Testing using Cloud Selenium Grid

Developed by AngularJS team, Karma is a Javascript test runner that helps to evaluate your source code across different browsers on the basis of your test code. The results are displayed using CLI to represent the test’s pass/fail status on various browsers. To know more refer to the Karma’s official website.


LambdaTest Selenium Automation Grid is a cloud-based, scalable Selenium testing platform which enables you to run your automation scripts on 2000+ different browsers and operating systems. You can now run your JavaScript Selenium automated test cases on a scalable Selenium infrastructure that is running real browsers and real operating systems.

This topic will help you demonstrate:

  • How to perform AngularJS automated testing on Lambdatest Selenium grid with Karma test runner?
  • How to test your locally hosted pages using AngularJS test automation?
  • How to run your test cases in parallel using AngularJS test automation to reduce build times?
  • How to leverage LambdaTest’s Advanced capabilities for AngularJS test automation?

Prerequisites For Running Karma With Our Online Selenium Grid#

All the code samples in this documentation can be found in the AngularJS LambdaTest Repository on GitHub. You can either download or clone the repository to quickly run your tests.

In order to perform your karma tests with LambdaTest, you would need the below things to be already set up:

  1. Global Dependencies

To install node.js with homebrew use the below command.

$ brew install node

  • If you have npm already installed, you may want to upgrade it to latest version. Here the code you can run in your terminal to upgrade npm.

npm install [email protected] -g

  1. LambdaTest Authentication Credentials

Be aware of your LambdaTest authentication credentials i.e. your LambdaTest username, access key and HubURL. You need to set them up as your environment variables. You can retrieve them from your LambdaTest automation dashboard by clicking on the key icon near the help button.

  • For Linux/Mac:
  • For Windows:

Setting Up The Environment For AngularJS Test Automation#

You need to clone our GitHub repository which demonstrates a sample of Karma-Angular.

After cloning, you need to navigate to the cloned directory and install project dependencies using the below command:

$ npm install

The example mentioned below would help you to execute your AngularJS automation testing on Google Chrome.

import { AppPage } from './app.po';import { browser, logging } from 'protractor'; describe('workspace-project App', () => {  let page: AppPage;   beforeEach(() => {    page = new AppPage();  });   it('should display welcome message', () => {    page.navigateTo();    expect(page.getTitleText()).toEqual('Welcome to karma-sample!');  });   afterEach(async () => {    // Assert that there are no errors emitted from the browser    const logs = await browser.manage().logs().get(logging.Type.BROWSER);    expect(logs).not.toContain(jasmine.objectContaining({      level: logging.Level.SEVERE,    } as logging.Entry));  });});

Perform AngularJS Automated Testing With Karma Test Runner#

Navigate to the directory where you cloned the sample of Karma-Angular and run the following command.

$ karma start karma.conf.js

or you could also run the test using:

$ npm test

Browser Launcher Configuration#

If you look at karma.conf.js file you will find that we are passing browser, browser version, and operating system information, along with LambdaTest Selenium Grid capabilities via capabilities object. The capabilities object in the above code is defined as:

customLaunchers: {        chrome: {             base: 'WebDriver',             config: webdriverConfig,             browserName: 'chrome',             platform: 'windows 10',             version: '71.0',             name: 'Karma With Heartbeat',             tunnel: true, // In case karma is running on local machine             video: true, // capture video for your test             user: process.env.LT_USERNAME,             accessKey: process.env.LT_ACCESS_KEY,             pseudoActivityInterval: 15000 // 15000 ms heartbeat to avoid timeouts        }    }

The most important capabilities to understand here are ‘browserName’, ‘version’, and ‘platform’. They define which browser environment you wish to run the test on. Rest of the capabilities are important in test management and debugging. We have an inbuilt Capabilities Generator tool as well that you use to generate capabilities code for your test suite.

Testing Locally Hosted Projects Using Angular Test Automation#

To help you perform cross browser testing of your locally stored web pages, LambdaTest provides an SSH(Secure Shell) tunnel connection with the name LambdaTest tunnel. With LambdaTest tunnel, you can perform AngularJS automated testing with Karma test runner to perform automated cross browser testing on browsers offered by online Selenium Grid at LambdaTest. So you make sure how well your changes look, even before your customers. Curious to know more about LambdaTest tunnel?

Follow our documentation on LambdaTest tunnel to know it all. OS specific instructions to download and setup tunnel binary can be found at the following links.

Download the binary file of:

Once, the tunnel is successfully set up. You can add the below code to your capabilities for testing internal servers on your network.

customLaunchers: { chrome: {        tunnel: true, // In case karma is running on local machine    }   }

Important Note: Some Safari & IE browsers don’t support automatic resolution of the URL string “localhost”. Therefore if you test on URLs like "http://localhost/" or "http://localhost:8080" etc, you would get an error in these browsers. A possible solution is to use "" or replace the string “localhost” with machine IP address. For example, if you wanted to test "http://localhost/dashboard" or, and your machine IP is you can instead test on "" or "".

Avoid Timeouts With psuedoActivityInternal#

To make sure our machines are not holding for long due to some incorrect test, we have come up with a restriction on the number of seconds that our machine is kept reserved for you. In cases, where our servers fail to retrieve a request from your local machine for more than 90 seconds, then your tests are aborted from the queue with the error message related to Timeouts.

If you wish to avoid such timeouts, you need to make use of the below parameter:

customLaunchers: { chrome: { pseudoActivityInterval: 5000 // 5000 ms heartbeat to avoid timeouts } }

Note: psuedoActivityInternal is presented as a default parameter with a value set to 0. Make sure to provide a value more than 0 in order to avoid the timeouts.

Perform AngularJS automation testing with Karma test runner & increase your test coverage using LambdaTest’s online Selenium Grid. Happy Testing!

Last updated on