Forum Discussion

SarahEdwards's avatar
SarahEdwards
Contributor
8 years ago

TC runs browser on monitor left of main display

On my PC where I'm developing my tests, TC always opens the browser window on the monitor to the left of the "main display" (as defined by Windows). Is there any way to specify another monitor? My left-most monitor is portrait instead of landscape, and this can cause some tests to fail, due to width issues.

  • In addition to what tristaanogre said, you can use .Position() to change the window position.

    function Test()
    {
    Browsers.Item(btChrome).Run();
    var bw = Sys.Browser().BrowserWindow(0);

    // Move the browser window to (0, 0) and maximize
    bw.Restore();
    bw.Position(0, 0, bw.Width, bw.Height);
    bw.Maximize();
    }

     

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    In addition to what tristaanogre said, you can use .Position() to change the window position.

    function Test()
    {
    Browsers.Item(btChrome).Run();
    var bw = Sys.Browser().BrowserWindow(0);

    // Move the browser window to (0, 0) and maximize
    bw.Restore();
    bw.Position(0, 0, bw.Width, bw.Height);
    bw.Maximize();
    }

     

    • Colin_McCrae's avatar
      Colin_McCrae
      Community Hero

      Yep. Most modern browsers will open at the same size, and in the same position, as when you last closed them. (If it was a clean exit. Killed it via task manager won't retain last position.)

       

      But, as HKosova says, you are better to use "position" and locate and size the browser yourself. I can't guarantee the size of monitor/browser window my tests will run on. So I tend to:

       

      1. Always start in a set position.

      2. Always maximise the browser if you want to make use of as much screen as possible.

      3. If using multiple browsers, I check the available screen resolution/size, and then split it in 4 and resize my browsers accordingly. So they always take up a quarter of the screen (and smaller than that and it become pointless) and never overflow it.

      4. Ensure any of my functions that interact with controls are always able to scroll things into view if they need to.

       

      Makes things nice and robust and portable. :)

    • SarahEdwards's avatar
      SarahEdwards
      Contributor

      HKosova wrote:

      In addition to what tristaanogre said, you can use .Position() to change the window position.

      function Test()
      {
      Browsers.Item(btChrome).Run();
      var bw = Sys.Browser().BrowserWindow(0);

      // Move the browser window to (0, 0) and maximize
      bw.Restore();
      bw.Position(0, 0, bw.Width, bw.Height);
      bw.Maximize();
      }

       


      This is perfect. Because I use an incognito session in Chrome, my browser won't save any defaults. Thank you!

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Did a bit of playing around...

    I simply executed the following code:

     

    function lah() {
        Browsers.Item(btIExplorer).Run();
    }

    And when the browser opened, before I closed it, I moved it to another one of my 3 monitors.  

    When I re-ran the code, the browser window opened on that NEW monitor, not the original.

    So... behavior appears to be that the browser will open on whatever monitor it was last opened on.

    Solution: When your browser opens, move it to the monitor you want, then close it... that should fix your issue.