Forum Discussion

mboyce's avatar
mboyce
Contributor
5 years ago

Change Default Web Browser

Has anyone scripted a way to change the default web browser in Windows10 during a test run? I am able to open the Default apps window, but can't access the various browser options by name, only through keyboard strokes (ie [Tab] and [Enter]), which won't work as it seems the order of the browsers can vary from one machine to another.

 

I've been using Object Browser and Spy Tool to try to figure out what I need to add to my project's UI Automation list of accepted windows (at least I think this is what I need to do) but haven't come across the correct combination yet.

 

This is my initial JavaScript function that works, but relies on the browser options being in a specific order:

function TESTsetDefaultBrowser(){

  Sys.Desktop.Keys("[Win]choose a default web browser");
  Sys.Desktop.Keys("[Enter]");
  Aliases.WaitAliasChild("ApplicationFrameHost");
  // select web browser
  Sys.Desktop.Keys("[Enter]");
  Delay(1000);
  // tab to desired browser
  Sys.Desktop.Keys("[Tab][Tab][Enter]");
}

I want to replace the last line with something like Object.ClickItem("Chrome");

 

Here's the Default Apps window in the Object Browser:

 

 

And here's the items I've added to the project's list of UIAutomation accepted windows:

 

Any insight is appreciated. Thanks!

  • cunderw's avatar
    cunderw
    Community Hero

    There is likely a commandline way to do this, but my question is what is the end goal for this? Are you testing Windows, or are you testing your application? Why do you need to set the default browser in a Test Complete test?

    • mboyce's avatar
      mboyce
      Contributor

      I have not been able to find a command line way to do this, so I was hoping someone out there had or had automated this process through the UI successfully.

       

      No, I am not testing Windows. My tested desktop app launches web apps (which is what's under test here) to the default browser. Previously, running Windows 7, I had automated the process of changing the default browser through the UI in order to test all supported browsers. Now, with Windows 10, the UI window has changed and this code does not work.

      • cunderw's avatar
        cunderw
        Community Hero

        I haven't tested this personally, but you might try something like this in powershell. 

         

        function Set-ChromeAsDefaultBrowser {
            Add-Type -AssemblyName 'System.Windows.Forms'
            Start-Process $env:windir\system32\control.exe -ArgumentList '/name Microsoft.DefaultPrograms /page pageDefaultProgram\pageAdvancedSettings?pszAppName=google%20chrome'
            Sleep 2
            [System.Windows.Forms.SendKeys]::SendWait("{TAB} {TAB}{TAB} ")
        }