Forum Discussion

nastester's avatar
nastester
Regular Contributor
14 days ago

How to launch clean browser

How can I, in TestComplete, open a clean browser session? Meaning no cache, no history, no profile signed in, just a clean blank slate.  I would think this would be a very common scenario but I cannot figure out how to do this...

 

7 Replies

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    To launch a clean Chrome using JavaScript,

    function LaunchChrome()
    {
        var URL = "https://www.w3schools.com/html/default.asp";
        Browsers.Item("chrome").RunOptions = "--user-data-dir=C:\\Temp\\User1";
        Browsers.Item("chrome").Run(URL);
    }

    Note, this will create a new profile called User1, and you need to install SmartBear Test Extension within this user profile.

    You can also try with the following options,

    --aggressive-cache-discard
    --disable-cache
    --disable-application-cache
    --incognito

    But you still need to install the SmartBear Test Extension, for TestComplete to actually work!

    This is a functionality of the Chromium browser.

    • nastester's avatar
      nastester
      Regular Contributor

      Cool this seems to work for me. Need to find an Edge equivalent and I haven't tried with the bottom run options yet. 
      Regarding the extension, it seems like TC automatically installed it so I don't need to worry about that

      • Hassan_Ballan's avatar
        Hassan_Ballan
        Icon for Champion Level 1 rankChampion Level 1

        rraghvani example is overwriting RunOptions each time. To set multiple options, you need to concatenate them into a single string.

        That example should do it for Edge

        Browsers.Item("edge").RunOptions = "--aggressive-cache-discard --disable-cache --disable-application-cache --incognito";

         

  • scot1967's avatar
    scot1967
    Icon for Champion Level 1 rankChampion Level 1

    Have you reviewed command line options?  The solution will be different for each browser such as specifying an empty profile folder in Chrome...

    --user-data-dir="/path/to/empty/folder"

    https://support.smartbear.com/testcomplete/docs/reference/test-objects/controls/web/general/browserinfo/runoptions.html

    ... If you find my posts helpful drop me a like! 👍  Be sure to mark the best answer you get to help others out and to credit the one who helped you.  😎

  • Hassan_Ballan's avatar
    Hassan_Ballan
    Icon for Champion Level 1 rankChampion Level 1

    That is a very common simple scenario, yet an involved topic based on what you are trying to avoid or accomplish, and there are two aspects to consider.

    Usually with well developed web applications, session and cache are well managed by the application. The first thing testers will do when expecting an odd situation example after I log out I can continue with the session, is to run the Chrome browser in "Incognito" mode or the Edge browser in "InPrivate" mode. This can also be accomplished by running the browser with a command line option.
    Launch Browser in Incognito/Private Mode | SmartBear Community

    Sometimes a reboot solves the issue and that is due to a browser bad state process. When you close the browser all instances of the process would close and sometimes they stay behind and starting browser revert back to the same state. You will need to check and terminate processes. Edge by design does not close the processes.
    https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/window-and-process/terminate-method-process-object.html