Resize Window РRWD Automation

As we talked about responsive web design of applications, doing test automation on a responsive web app is to be able to resize window to certain width and height and progress from there on (either checking if elements exists or menu disappears or element is not visible and so on)

The Challenge

The real challenge here is the way different browsers behave when we want to resize windows. For example reading a # of discussions on stackoverflow (I will update all the links soon here focusing on what is relevant), I realized that opening a browser with selenium webdriver and executing window resize is not really working, though the script passes. For example the below script executes fine, however the window doesn’t really resize.¬†

The current solution (works on chrome, ie and firefox)

The logic is to be able to open a new browser window from the existing webdriver instance using java script and then close the old window and switch the browser reference to the new window.

Cucumber Scenario (resize_window.feature)

Step Definitions (resize_window.rb)

Note: It is assumed that your hooks.rb already instantiated @browser using Watir. Even if you were using Selenium WebDriver instead of Watir, the switch to new window has to be done.

Introspection on specific lines of code

Open new window

This line of code with resizable=yes was required for chrome, otherwise firefox and ie were working fine without the resizable attribute

Switch to newly opened resized window

We switch here to newly opened resized window (it doesn’t matter whether we switch to first or last since there is only one window)

Resize the window

We resize the window here

Move on from here

Once we resized the window, we return back control to the newly created Watir instance.

What next?

Read the next section on user-agent