Forum Discussion

Lagencie's avatar
Lagencie
Frequent Contributor
7 years ago
Solved

Resizing Window

Hello,   how exactly should I resize the browser window in test complete?   I tried it with BrowserWindow.Position(0,0,width,1000) in a function where I give the width as parameter ... But it set...
  • AlexKaras's avatar
    AlexKaras
    7 years ago

    Hi,

     

    So far I ended-up with this code. Hopefully it will work for you as well...

    //----------------------------------------------------------------------------
    
    // Sets the size of browser's viewport
    function BrowserViewportSizeSet(page, iWidth, iHeight)
    {
      var wnd;
      var iBorderWidth, iBorderHeight;
      var iWinWidth, iWinHeight;
      var res;
    
      wnd = BrowserWindowByPageGet(page);
    
      iBorderWidth = wnd.Width - page.Width;
      iBorderHeight = wnd.Height - page.Height;
    
      iWinWidth = iWidth + iBorderWidth;
      iWinHeight = iHeight + iBorderHeight;
    
      Log.Message(aqString.Format("Set browser\'s viewport size to %ix%i (window size is %ix%i)", iWidth, iHeight, iWinWidth, iWinHeight),
          aqString.Format("%ix%i\n%ix%i", iWidth, iHeight, iWinWidth, iWinHeight));
    
      res = (iWinWidth > Sys.Desktop.Width) || (iWinHeight > Sys.Desktop.Height);
      if (res)
        Log.Warning(aqString.Format("Viewport size was not changed as it exceeds current size of the desktop (%ix%i)",
            Sys.Desktop.Width, Sys.Desktop.Height));
      else
      {
        if ((wnd.Width != iWinWidth) || (wnd.Height != iWinHeight))
          wnd.Position(0, 0, iWinWidth, iWinHeight);
      }
    
      return res;
    }
    //----------------------------------------------------------------------------
    
    // Returns BrowserWindow object that corresponds to the given page object
    // From: http://smartbear.com/forums/f75/t83264/how-to-match-a-page-object-to-its-browserwindow
    function BrowserWindowByPageGet(Page)
    {
      var title;
      var wnd;
    
    //  wnd = Utils.CreateStubObject(); // Utils is not accessible from Script Extension
      wnd = null;
      if (Page.Exists)
        if ("Page" == Page.ObjectType)
        {
          if ('edge' == Page.Parent.ObjectIdentifier)
            wnd = Page.Parent.BrowserWindow(0); // quick crutch
          else
          {
            title = Page.contentDocument.title;
            wnd = Page.Parent.FindChild("WndCaption", title + "*");
          }
        }
    
      return wnd;
    }
    //----------------------------------------------------------------------------