The viewport is the visible area of an application within the application window. The viewport size can impact the layout of a page. For example, changing the width of the browser might change the way a paragraph of text is rendered. If the page is designed to be responsive, elements such as menus may be displayed in different ways, fonts size may change, and images may be scaled. Note that the notion viewport is platform specific. For example, on mobile phones the user does not control the size of the browser window.
Since the visual look of a page can be dependent on the viewport size, Eyes maintains an independent baseline (i.e. a sequence of baseline images) for every viewport size.
On platforms that allow control over the window size, such as desktop browsers, if the viewport size is defined explicitly in the test using the SDK, then when the test calls the open() method, Eyes calculates and adjusts the operating window size so that the viewport size will be the dimensions requested. On platforms where the user can't control the viewport size, for example on mobile phones, you should not set the viewport size explicitly.
On the first run of a test, Eyes stores the viewport size, along with the operating system and application platform, as the execution environment of the baseline. By default, on subsequent test runs, Eyes compares the checkpoint images to the baselines images taken from the baseline whose execution environment matches the execution environment of the current run.
Setting the viewport size is optional. If you do not set a viewport size, then Eyes will work with whatever viewport size is set by the application or by the underlying infrastructure.
The Eyes SDK provides two ways to set the viewport size. One way is to pass the size as a parameter to the open method. This parameter is optional.
You can also set the size using the SDK method setViewportSize.
In this case, you should not pass a viewport size to the open call (the parameter is optional).
To set the viewport size attribute of the baseline, you should call this method before calling the Eyes open method.
If you call setViewportSize after calling the open method, then this will only change the physical window size and will not impact the baseline definition. However, it may change the layout, and hence the content of the screenshot captured, so you should do this consistently in all test runs, otherwise you might get mismatches.
The call to open will abort the test and throw an exception if the viewport size is set to a size that results in an operating system window that is larger than the desktop. This can happen if the browser and operating system window add extra toolbars or panels. It can also happen if your operating system scales the display. For example, if the display is scaled by 200%, then setting a viewport size of 800x600 would imply a minimal window size of 1600x1200. To avoid problems related to browser differences, it is advisable to use a viewport size that is smaller ( about 50 pixels less) than the maximum value.
You can obtain the current viewport size using the SDK method.