Using Different Web Browsers with Coded UI Tests

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Coded UI tests can automate testing for web applications by recording your tests using Internet Explorer. You can then customize your test and play it back using either Internet Explorer or other browser types for these web applications.

Requirements

Why should I use coded UI tests across multiple web browser types?

By testing your web application using a variety of web browser types, you better emulate the UI experience of your users who may run different browsers. For example, your application might include a control or code in Internet Explorer that is not compatible with other web browsers. By running your coded UI tests across other browsers, you can discover and correct any issue before it impacts your customers.

How do I record and play back coded UI tests on web applications using the supported web browsers?

Recording: You must use the Coded UI Test Builder to record your web application test using Internet Explorer. You can optionally add validation and custom code for the tested controls using a predefined set of properties as you would normally do for coded UI tests. For more information, see Use UI Automation To Test Your Code.

Note

You cannot record coded UI tests using Google Chrome or Mozilla Firefox browsers.

Play back with Internet Explorer: When no browser is explicitly specified, tests will run on Internet Explorer by default. You can explicitly state the browser to be used by setting the BrowserWindow.CurrentBrowser property in your test code. For Internet Explorer, this property should be set to IE or Internet Explorer.

Play back with non-Internet Explorer web browsers: To play back on non-Internet Explorer web browsers, change BrowserWindow.CurrentBrowser property in your test code to either Firefox or Chrome.

To play back tests on non-IE web browsers, you must install the Selenium components for Coded UI Cross Browser Testing.

Installing Selenium components

  1. On the Tools menu, choose Extensions and Updates.

  2. In the Extension and Updates dialog box, search for Selenium components for Cross Browser Testing.

  3. Highlight the extension and choose Download.

    Tip

    You can also download the Selenium components for Coded UI Cross Browser Testing from here.

    For more information about creating and using coded UI tests, see Creating Coded UI Tests.

Enable debugging

To enable debugging your web application, you must complete the following configuration options:

  1. Enable Just My Code:

    1. On the Tools menu, choose Options and then choose Debugging.

    2. Select Enable Just My Code.

  2. Disable CLR exceptions:

    1. On the Debug menu, choose Exceptions.

    2. For Common Language Runtime Exceptions, uncheck User-unhandled.

I don't see the option to change BrowserWindow.CurrentBrowser in the coded UI test.

You might be using a version of Microsoft Visual Studio 2012 that does not support coded UI tests using various web browsers. To use such coded UI tests, you must use Visual Studio Enterprise.

What else should I know? Notes

  • Prerequsite Apple Safari web browser is not supported.

  • Prerequsite The action of starting the web browser must be part of the coded UI test.

    If you have a web browser already open and you want to run steps on it, the playback will fail unless you are using Internet Explorer. Therefore, it is a best practice to include the startup of your web browser as part of your coded UI tests.

  • Prerequsite Automating browser specific based UI actions such as maximize, minimize and restore is not supported.

    Tips

  • Tip You can configure the output to include screenshots in the coded UI logs. To do so, you need to set some configuration settings in the QTAgent32.exe.config file. By default, this file is installed in the following location:

    C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE

    Set the following values:

    • EqtTraceLevel in the system.diagnostics section.

    • <add name="EqtTraceLevel" value="4" />

      By setting the value to be 3 or higher, screenshots are taken for each action. When the value is set to either 1 or 2, screenshots are taken for error actions only.

      For more information, see Analyzing Coded UI Tests Using Coded UI Test Logs.

External Resources

Videos

Record on IE and Playback everywhere

Author cross browser tests with Coded UI Test Builder

Author cross browser tests using plain hand coding without UI Map

Run cross browser tests sequentially on multiple browsers

Troubleshoot cross browser test failures

Guidance

Testing for Continuous Delivery with Visual Studio 2012 – Chapter 2: Unit Testing: Testing the Inside

Testing for Continuous Delivery with Visual Studio 2012 – Chapter 5: Automating System Tests

FAQ

Coded UI Tests FAQ - 1

Coded UI Tests FAQ -2

Forum

Visual Studio UI Automation Testing (includes Coded UI)

See Also

Use UI Automation To Test Your Code Supported Configurations and Platforms for Coded UI Tests and Action Recordings Analyzing Coded UI Tests Using Coded UI Test Logs