Challenges with record and playback: Screen Size
Changing screen sizes.
This challenge is interesting because there's this modern testing practice that is biting us during automated test creation and that is responsive web. In order to make a website that works for both mobile and desktop, Smart developers create responsive websites that will change the way that they look depending on the screen size. They do this instead of having to find out whether the user is on a mobile device, tablet or desktop on page load or creating a completely separate mobile site. You might've seen this before when you resize a window and the UI completely changes. Imagine what that does to an automated test. Let's say you recorded in a maximized window and it plays back in a half-size window, here are a few specific things that can affect your test automation:
- Due to screen size, Elements could be hidden or obscured
- The resolution on your playback machine could be different than your recording machine causing the layout to be different
Here is how to make that less painful
Set your screen size to maximum on playback. You can use selenium commands to set your screen size to maximum through the following commands.
Using Selenium WebDriver API
Using Chrome Options
Using the Selenium WebDriver method above will work in all browsers, but I mention this one for chrome because it will save you a step in your test
Other useful browser size commands
This ensures that the page is full size, and elements are arranged on the page for that configuration. Assuming you recorded with the screen size at maximum the elements will generally be consistent between record and playback even if the machine doing playback is using a different resolution