Forum Discussion

MyG0t's avatar
MyG0t
Occasional Contributor
8 years ago

Q: Browser Loop // Data Driven Browser Loop

Hi,

 

I'm setting up my project as a hybrid style that uses scripts and keyword tests.  Basically, the scripts are modular code or single function, which I drop into a Keyword test.  A Keyword tests consists of one or many 'Run Script Routine' functions.  This allows me to re-use scripts across multiple Keyword tests, leverage Keyword operations, and looks cleaner for any non-code savvy team members who want to create new tests (via drag and dropping script routines into a keyword test).  

 

Ideally, I'd like to create a "Browser Loop" script that runs through all installed browsers and virtual browsers.  TestComplete has a 'Browser Loop' operation and a 'Virtual Browser Loop' operation.  I'm not able to convert these operations to script.  

 

The reason I want to have a scripted browser loop, is so that I can maintain all my code in one place. For example; we stop supporting IE, I don't want to go into 100+ test cases and remove IE from the Browser Loop operation.  If I had a script, I could maintain our supported browsers in one spot and update all Keyword tests that use that script routine.

 

 

Does anyone have recommendations for accomplishing this?

What I'm looking for is a scripted function where I can identify all the browsers that will be tested (installed or virtual).  I want to be able to drag this script into the top of a keyword test, just as you would use the Browser Loop/Virtual Browser operation, and run through the rest of script - one browser at a time until the test has been run on every browser.

 

Is there a way to combine the Browser Loop and Virtual Browser Loop?  

Right now, if I wanted to run both loops I'd need to have a browser loop operation followed by my script routines, then a virtual browser loop operation followed by the same routines from above - it's pretty redundant.  

 

 

 

Project

+Keyword Tests

--Test 1  (Run script routine ABC, Run script routine DEF)

--Test 2  (Run script rountine ABC, Run script routine JKL)

+Scripts

--Script ABC

--Script DEF

--Script GHI

--Script JKL

 

When running the automated tests, you would run the Keyword Tests. See attachment for example. 

 

 

 

 

  • Unfortunately, there's not a way to do precisely what you want.  The Browser Loop operation is like a for loop or while loop operation.  It's just the start of the loop.  You then need to add "child" operations under it that execute within the loop.  So, you can't drop a "Run Script Routine" operation and have it operate as the top end of a loop operation.

     

    To do EXACTLY what you want, you'd have to restructure your project where you would have a single script as a test item in your project.  That script would include your script equivalent of the browser loop which could be coded to include your list of regular and virtual browsers.  Within the loop, you would call your Keyword tests in the desired order, those keyword tests would then, in turn, call your script routines.

     

    Just a rough idea, let's say you keep your list of browsers to run in a CSV file with the browser name and a boolean for if it's a regular or virtual browser.  So, I'd do this kind of thing:

     

    function runAllTests(){
        var browserLoopData;
        browserLoopData = DDT.CSVDriver('C:\test\loopdata.csv');
        while (!browserLoopData.EOF){
            if (browserLoopData.Value('IsVirtual') == 'Y') {
                VirtualBrowsers.Item(browserLoopData.Value('BrowserName').Run();
            }
            else {
                Browsers.Item(browserLoopData.Value('BrowserName').Run();
            }
            KeywordTests.Test1.Run();
            KeywordTests.Test2.Run();
            browserLoopData.Next();
            
        }
    
    
    }

    And then make this your only test item in your project.

     

     

  • cunderw's avatar
    cunderw
    8 years ago

    Another option for this would be to have all Projects have a table variable with the names of the browsers to run and each KWT always loops this this table from start to end, passing the browser name to an open browser function (if you're testing responsiveness you could also set your browser sizes with this).

     

    Then at run time (use an on test start event handler) you can update the table variable to only include the browsers (and / or sizes) that you would like to run. 

     

    With this option, you still have all of the test cases in KWT format for the formating and ease of use for non-scripters and you do not have to add new KWTs to your loop function every time, and each test will loop through browsers as opposed to each browser looping through all tests (personal preference for setup). 

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Unfortunately, there's not a way to do precisely what you want.  The Browser Loop operation is like a for loop or while loop operation.  It's just the start of the loop.  You then need to add "child" operations under it that execute within the loop.  So, you can't drop a "Run Script Routine" operation and have it operate as the top end of a loop operation.

     

    To do EXACTLY what you want, you'd have to restructure your project where you would have a single script as a test item in your project.  That script would include your script equivalent of the browser loop which could be coded to include your list of regular and virtual browsers.  Within the loop, you would call your Keyword tests in the desired order, those keyword tests would then, in turn, call your script routines.

     

    Just a rough idea, let's say you keep your list of browsers to run in a CSV file with the browser name and a boolean for if it's a regular or virtual browser.  So, I'd do this kind of thing:

     

    function runAllTests(){
        var browserLoopData;
        browserLoopData = DDT.CSVDriver('C:\test\loopdata.csv');
        while (!browserLoopData.EOF){
            if (browserLoopData.Value('IsVirtual') == 'Y') {
                VirtualBrowsers.Item(browserLoopData.Value('BrowserName').Run();
            }
            else {
                Browsers.Item(browserLoopData.Value('BrowserName').Run();
            }
            KeywordTests.Test1.Run();
            KeywordTests.Test2.Run();
            browserLoopData.Next();
            
        }
    
    
    }

    And then make this your only test item in your project.

     

     

    • cunderw's avatar
      cunderw
      Community Hero

      Another option for this would be to have all Projects have a table variable with the names of the browsers to run and each KWT always loops this this table from start to end, passing the browser name to an open browser function (if you're testing responsiveness you could also set your browser sizes with this).

       

      Then at run time (use an on test start event handler) you can update the table variable to only include the browsers (and / or sizes) that you would like to run. 

       

      With this option, you still have all of the test cases in KWT format for the formating and ease of use for non-scripters and you do not have to add new KWTs to your loop function every time, and each test will loop through browsers as opposed to each browser looping through all tests (personal preference for setup). 

      • MyG0t's avatar
        MyG0t
        Occasional Contributor

        This aligns better with how I want to have my project setup. 

         

        I see I can create a Table as a 'Temporary Variable'.  How would you loop a keyword test through this table?

         

    • MyG0t's avatar
      MyG0t
      Occasional Contributor

      Thank you for the response.  I'll give this a shot, as it's very close to what I want to do.  +1