Skip to main content

Jasmine Test Runner: Run Jasmine Testing on LambdaTest Selenium Grid


LambdaTest Selenium Automation Grid is a cloud-based, scalable Selenium testing platform which enables you to run your automation scripts on 3000+ different browsers and operating systems. You can now run your java 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 run a Jasmine testing and Selenium testing script on LambdaTest Selenium Cloud with Karma test runner for Angular?
  • How to test your locally hosted pages using Jasmine test runner?
  • How to run your test cases in parallel to reduce build times?
  • How to leverage LambdaTest’s Advanced capabilities?

Jasmine Testing Using Jasmine Test Runner


Jasmine test runner is a BDD test automation framework which helps you to write clean and powerful test cases for JavaScript. It executes independently with respect to DOM or other JavaScript frameworks.

Karma Test Runner


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.

Prerequisites For Running Karma With LambdaTest Selenium Grid


All the code samples in this documentation can be found in the Jasmine LambdaTest Repository on Image 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

  • Make sure to use the latest version of JavaScript.
  • A Git or GitHub repository
  • Download and install node.js and node package manager or npm.
  • 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 npm@latest -g

2. 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:
$ export LT_USERNAME=<YOUR_LAMBDATEST_USERNAME> 
$ export LT_ACCESS_KEY=<YOUR_LAMBDATEST_ACCESS_KEY>
  • For Windows:
$ set LT_ACCESS_KEY=<YOUR_LAMBDATEST_ACCESS_KEY>
$ set LT_ACCESS_KEY=<YOUR_LAMBDATEST_ACCESS_KEY>

Setting Up The Environment For Jasmine Testing Using Selenium


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

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 perform Jasmine testing in Google Chrome.

describe('add', function () {
it('should add two numbers and return the result', function () {
expect(window.add(1, 2)).toBe(3);
});
});

describe('subtract', function () {
it('should subtract two numbers', function () {
expect(window.subtract(2, 1)).toBe(1);
});
});

describe('updateAppState', function () {
it('should push a new state into the browser history', function () {
window.updateAppState({
message: 'Getting Started with LambdaTest'
});
expect(window.history.state).toEqual({
message: 'Getting Started with LambdaTest'
})
});
});

Running Jasmine Tests Using Karma


Navigate to the directory where you cloned the sample of Karma-Jasmine 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',
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 Jasmine Test Runner


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 run your Jasmine tests using Karma 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.

//Test Websites Using Localhost
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 "localhost.lambdatest.com" 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 192.168.2.6 you can instead test on "http://192.168.2.6/dashboard" or "http://localhost.lambdatest.com/dashboard".

Avoid Timeouts With psuedoActivityInternal


To make sure our machines are not hold 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.

Execute Jasmine testing using Karma & increase your test coverage using LambdaTest’s online Selenium Grid. Happy Testing!

Test across 3000+ combinations of browsers, real devices & OS.

Book Demo

Help and Support

Related Articles