Ask a Question

Resizing Window

SOLVED
Lagencie
Frequent Contributor

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 sets the window size to idk 1697 or something rather than my 1710 I sent to the function.

 

Is there a better way to resize the BrowserWindow during runtime?

14 REPLIES 14
socaltester
Contributor

I interested in this as well.

tristaanogre
Esteemed Contributor

Question: Are you trying to set it to a particular size? Or are you trying to maximize it?  Trying to determine the purpose for altering the browser window size because there may be other options than setting to a particular size.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Lagencie
Frequent Contributor

We are testing a web application with ~20 breakpoints at different px width sizes.

 

therefore I need to set it to specific sizes 15 exactly.

 

The height I just took fixed on 1000 but the width changes depending on the test.

 

So maximizing is no option, I even need to restore it before as it sometimes opens the browser maximized, which doesnt allow .Position

kaiiii
Regular Contributor

Browsers.Item(bws).Run(url)

Sys.Browser.BrowserWindow(0).Maximize

Lagencie
Frequent Contributor

sadly i cant remove answers ... 

 


@kaiiii wrote:

Browsers.Item(bws).Run(url)

Sys.Browser.BrowserWindow(0).Maximize


thx for not reading the question, still looking for an answer

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;
}
//----------------------------------------------------------------------------
Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
Lagencie
Frequent Contributor

In the end your solution uses .Position

 

and for me it doesnt set the real resolutions when i set 1710 width the screen is ~1690-1700 

 

Not sure why, tho - the screen size is definitely bigger than the width i want to set

Hi,

 

.Position() is the only way to change the size of the window according to my knowledge.

The general approach is that .Page is one of the objects within the Window container. So you need to count the width and height of all other objects within the same Window and set Window's size so that after resizing the size of Page (because it is my understanding that you are interested exactly in the viewport size, but not in the size of the window) is exactly as you need.

Depending on the target browser, you may need to use Object Browser to investigate what other objects need to be considered.

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
Lagencie
Frequent Contributor

Ok ... I guess thats really what I need, as i just saw, that it is the border problem...

 

I will try it out with the script (trying to migrate it to python ^^) and test if it works

cancel
Showing results for 
Search instead for 
Did you mean: