Set up multiple browser testing

This task describes some of the techniques you can use to enable effective cross-browser testing for your application or Web page.

Tip: For a use-case scenario related to this task, see Use descriptive programming for multiple browser testing - Use-case scenario.

Prerequisite- turn off auto updates for the browsers

To ensure that you are testing on the specific browser version you want, turn off the automatic update feature for your browser.

Back to top

Configure the Record and Run settings to launch a browser

Using the Record and Run settings, change the browser on which you run the test for each test run.

  1. Select Record > Record and Run Settings.

  2. In the Record and Run Settings dialog box, select the Web tab.

  3. In the Web tab, select the Open the following address when a record or run session begins: option.

  4. In the web address drop-down list, enter a Web address to open or select a Web address from the drop-down list.

  5. In the Open the following browser when a record or run session beings: drop-down list, select the browser on which you want to run your test.

    Note: If you choose Apple Safari, you must provide additional connection information. For details, see Connect to a remote Mac computer

    When you start the test run, the specified browser opens the Web address entered.

Back to top

Use the BROWSER_ENV environment variable to launch a browser

Using the BROWSER_ENV environment value, change the browser to launch each test run, and in some cases specify a specific browser version (if installed).

  1. Select File > Settings.

  2. In the Settings dialog box, select the Environment node.

  3. In the Environment node, from the Variable type drop-down list, select User-defined.

  4. In the user-defined variables list, click the Add button .

  5. In the Add New Environment Parameter dialog box, in the Name field, enter BROWSER_ENV (case-sensitive).

  6. In the Value field, enter the value (case-sensitive) for the browser to open.

    IE Opens the installed version of Internet Explorer.
    IE64 Opens the installed 64-bit version of Internet Explorer.
    CHROME Opens the installed version of Google Chrome.
    CHROMIUMEDGE

    Opens the installed version of Microsoft Chromium Edge.

    CHROME_HEADLESS

    Opens the locally installed version of Headless Chrome.

    Supported for Chrome versions 60 and higher.

    FIREFOX Opens the installed version of Firefox.

    FIREFOX64

    Opens the latest version of 64-bit Mozilla Firefox that is both installed on the computer and supported by UFT One.
    SAFARI Opens Safari on the remote Mac computer connected to UFT One.
    EDGE

    Opens the installed version of Microsoft Edge Legacy with the Edge Agent for UFT already enabled.

    CHROME_EMULATOR Opens Chrome in emulated mode with the specified device.
    PHANTOMJS Opens the locally installed version of the PhantomJS web toolkit.
  7. Click OK to save the Name and Value of the variable.

  8. In the Test Settings dialog box, click Apply and OK to save the variable and close the dialog box.

Back to top

Launch a browser with a test parameter

Instruct UFT One to automatically launch a specific browser for a test run using the Record and Run Settings:

  1. Select Record > Record and Run Settings.

  2. In the Record and Run Settings dialog box, select the Web tab.

  3. In the Web tab, select the Open the following when a record and run session begins: option.

  4. (Optional) In the Address field, enter the address to which to open the browser.

    You can leave the Browser drop-down list as the default value.

  5. In the Parameter type drop-down list, select the parameter type: Global Data Table or Test Parameter.

  6. In the Parameter Name field, enter the parameter name. (The default parameter name is Browser.)

  7. Click Apply to save the changes and OK to close the dialog box.

    UFT automatically adds a column to the Global tab in the Data pane or a test parameter.

  8. Before running the test, do one of the following, depending on the parameter type selected:

    For a Global Data Table parameter In the Global tab of the Data pane, set the value of the parameter.

    Value to use:

    • IE. Opens Internet Explorer.

    • IE64. Opens a 64-bit version of Internet Explorer.

    • CHROME. Opens Google Chrome.

    • CHROME_HEADLESS. Opens Headless Chrome.
    • FIREFOX. Opens Mozilla Firefox.

    • FIREFOX64. Opens the latest version of 64-bit Mozilla Firefox that is both installed on the computer and supported by UFT One.

    • SAFARI. Opens Safari on the remote Mac computer connected to UFT One (defined in the Web tab of the Record and Run Settings dialog box or in the REMOTE_HOST environment variable).

    • EDGE. Opens the installed version of Microsoft Edge Legacy with the Edge Agent for UFT already enabled.

    • CHROME_EMULATOR. Opens Chrome in emulated mode with the specified device.

    • PHANTOMJS: Opens the locally installed version of the PhantomJS web toolkit.

    For details on adding mobile-relevant parameters, see Define Mobile Record and Run Settings.

    For a Test Parameter
    1. In the toolbar, click the Run button .

    2. In the Run dialog box, expand the Options section and select the Input Parameters tab.

    3. In the Value column for the parameter, enter the value of the parameter

Back to top

Launch a browser using a data table parameter

  1. (Optional) Create a reusable action to use in all your tests for launching the browsers.

  2. In the Data pane, open the Global tab.

  3. In the Global tab, click the first row of the column where you want to store the parameter.

  4. Enter the name for the parameter and click OK.

    For example, you could name this parameter BrowserName (to identify it as the name of the browser to open).

  5. In the data table, enter the .exe names for the browsers you want to open.

    For example, if you need to run the test on Internet Explorer, Firefox, and Chrome, you would enter iexplore.exe, firefox.exe, and chrome.exe in the first three rows of the column, respectively:

  6. Add a test step with the following format:

    SystemUtil.Run DataTable("<parameter name>", dtGlobalSheet), "<address to open the browser to>"

    For example, if you wanted to open up to the AdvantageDEMO site, you could enter the following:

    SystemUtil.Run DataTable("BrowserName", dtGlobalSheet), "https://www.advantageonlineshopping.com/#/"

Note: If you add this step to a reusable action which is then called by other tests, the relevant rows must be added in the Global tab of all tests that call that action.

Back to top

Launch a Browser using a WebUtil.LaunchBrowser step

If you are using Business Process Testing to test your web applications, add use a WebUtil.LaunchBrowser step to launch the appropriate browsers as needed within each component.

Provide an argument for the Browser parameter, which is the same as the environment variables for Web- based environments:

  • CHROME

  • CHROME_EMULATOR

  • CHROME_HEADLESS
  • EDGE

  • FIREFOX

  • FIREFOX64

  • IE

  • IE64

  • PHANTOMJS

  • SAFARI

Note: If you are using business process tests created from UFT One versions 12.53 and earlier, the Web.txt function library (found in your test's application area) does not contain the LaunchBrowser function. As a result, you will not be able to use the LaunchBrowser method in keyword GUI components.

To use this function, copy the following code into the Web.txt function library:

Public Function LaunchBrowser(Browser, device_model, device_manufacturer, device_ostype, device_osversion)
    WebUtil.LaunchBrowser Browser, device_model, device_manufacturer, device_ostype, device_osversion
End Function

Back to top

Dynamically load an object repository during the test run

If your test requires you to have different object repositories for each browser type, load the relevant object repositories as part of the test run without having to manually configure anything before the test run:

  1. In the Data pane, open the Global tab.

  2. In the Global tab, click the first row of the column where you want to store the parameter.

  3. Enter the name for the parameter and click OK.

    For example, you could name this parameter Browser (to identify it as the name of the browser on which to run the test).

  4. In the data table, enter the names for the browsers on which you want to run the test.

  5. Add a test step with the following format:

    If DataTable("<data table parameter>") = <Browser 1> Then
    	RepositoriesCollection.Add "<location to object repository>"
    ElseIf DataTable("<data table parameter>") = <Browser 2> Then
    	RepositoriesCollection.Add "<location to object repository>"
    End If
  6. Add the additional steps for the application/Web page.

    When the test runs, the appropriate object repository loads, and the test steps use the objects in the loaded object repository.

Back to top

Add steps for browser specific behavior

If you need to add steps to perform browser specific behavior in the course of the test, use test parameters to create steps for this behavior.

  1. In the canvas, select an action.

  2. In the Properties pane, select the Parameters tab.

  3. In the Parameters tab, click the Add button.

  4. In the parameters grid, provide a name for the parameter. For example, you could name the parameter ActiveBrowser to show that the value of the parameter represents the browser currently in use.

  5. Add steps to the test. You can use the value of the parameter by using the Parameter object:

    Select Case Parameter("<parameter name>")
    	Case "<Browser 1>"
    	'Do something specific for browser 1
    	Case "<Browser 2>"
    	'Do something specific for browser 2
    End Select

    Note: Add additional Case statement as needed for each browser type.

When the test runs, the test steps run as specified in the necessary Case statement.

Back to top