Performing cross-browser testing

TestComplete provides a possibility to perform Web-applications testing in all of the popular browsers (Internet Explorer, Mozilla Firefox, Google Chrome, Apple Safari, and Opera), easily switching in-between.

In this recipe we will consider launching one script in several browsers.

Getting ready

With the help of recording means let's make a record of any test in any of the available browser at hand. In our example, Internet Explorer is used to carry out the following actions:

  1. In TestComplete go to Test | Record | Record Script menu item.
  2. Open the browser.
  3. Navigate to the following page: http://smartbear.com/.
  4. Click on the Free Trial link.
  5. In the result, the following script will be recorded:
    function Test1()
    {
      var form;
      Browsers.Item(btIExplorer).Run("http://smartbear.com/");
      browser = Aliases.browser;
      page = browser.pageAutomationTestingWebMonitori;
      page.formAspnetform.linkLookingForAFreeTrial.Click();
      browser.pageSoftwareTestingWebMonitoring.Wait();
    }

How to do it...

To launch the recorded script in several browsers, go about the following actions:

  1. Create a new test with the following code:
    function Test2()
    {
      var browsers = ["iexplore", "firefox"];
      for(var i = 0; i < browsers.length; i++)
      {
        //TODO: place code here
      }
    }
  2. Remove the //TODO comment and place the contents of the earlier written Test1 function instead.
  3. Replace the line Browsers.Item(btIExplorer) with the following: Browsers.Item(browsers[i]). In the result, we will have the next function ready:
    function Test2()
    {
      var browsers = ["iexplore", "firefox"];
      for(var i = 0; i < browsers.length; i++)
      {
        var form;
        Browsers.Item(browsers[i]).Run("http://smartbear.com/");
        browser = Aliases.browser;
        page = browser.pageAutomationTestingWebMonitori;
        page.formAspnetform.linkLookingForAFreeTrial.Click();
        browser.pageSoftwareTestingWebMonitoring.Wait();
      }
    }
  4. By launching the Test2 function, we will see that the same actions were initially executed in the Internet Explorer browser, and then in Mozilla Firefox.

How it works...

The object Browsers provides access to any installed browser via the Item property. This property takes the Index parameter, with the help of which we are able to assign the particular browser we would like to work in. The Index parameter can be any number (of a named constant value, just like the btIExplorer in our case), or the name of a process.

Since working with control elements in all the browsers is executed in a similar fashion, we can record a script in one browser to execute in another or in several others (in our example, we have used the for loop).

In a real project, it is more convenient to create tests that accept a parameter (the name of browser process), and then launch the tests by passing the name of the browser as a parameter. The resulting function will assume the following shape and form:

function Test3(browserName)
{
  var form;
  Browsers.Item(browserName).Run("http://smartbear.com/");
}

The launch of this from the test items will appear as follows:

How it works...

See also

  • Although TestComplete does provide wide possibilities for cross-browser testing in some cases, however, browsers may behave differently, thus requiring additional settings and code. If you create a lot of cross-browser tests, make sure you read up on the following article: Handling Browser Differences, located at the following address: http://support.smartbear.com/viewarticle/27716/.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.84.157