Knowledge Base Article

Home Page > Knowledge Base > Rapise

Home Page > Knowledge Base > Rapise > Rapise Web

Article Web testing - Dynamically Switching the Browser in the Same Test

by Adam S on Monday, November 23, 2015

Sometimes you have a test that you want to run on Chrome, Firefox, and IE in the same script. Normally you write a browser-agnostic test and then have SpiraTest simply call Rapise with different browser names as a parameter and then you have the same test executed multiple times. However suppose you want to have a single test that by itself can run on all the necessary browsers. This article addresses this case.

The way to do this (when you don't want to use SpiraTest to perform the looping) is to create two arrays, one for the web application url, and one array with the g_browser_library type.  Then you need to tell Rapise to loop through this array of browsers and for each browser, load that browser library at runtime and execute the test.

function Test()
   * This sample demonstrates how to use the same scenario in different web browsers: IE, Chrome and Firefox.
   * This approach is useful for development stage where tests are being designed. Later it is recommended to use
   * Spira to drive cross browser execution by switching g_browserLibrary parameter (see
   * The function "Deposit" contains the set of steps requried to deposit some amount
   * on site ""
   * This function was created automatically by recording the actions in Firefox.
   * Then it was modified to load all browser libraries on the startup:
   *  g_load_libraries=["Internet Explorer HTML", "Firefox HTML", "Chrome HTML"];
   * And then we iterate through all browsers by calling Navigator.Select(name),
   * where name is "IE", "Chrome" or "FF".

  var browsers=["IE", "Chrome", "FF"];
  for(var i in browsers)
    Tester.SetReportAttribute("Browser", Navigator.current.names[0]);


// FYI
// For recording:
//g_load_libraries=["Firefox HTML"];
// For playback:
// g_load_libraries=["Internet Explorer HTML", "Firefox HTML", "Chrome HTML"];


g_load_libraries=["Internet Explorer HTML", "Firefox HTML", "Chrome HTML"];

The key is that you need to load all of the libraries during playback so that the test script can dynamically change which browser to use based on the position in the browser array. However for learning or recording you need to only have the single browser library loaded that you are using for recording. If you don't do this, Rapise will get confused and try to record using all three libraries at the same time - which doesn't work.

The full code sample is attached.
Article Info
Last Updated: 11/23/2015
Article ID: KB177
# Views: 316
Powered by KronoDesk v1.1.0.15 | © Copyright Inflectra Corporation 2011-2016 | Licensed to Inflectra Corporation.