In order to get consistent results on your visual automated test it is important that the size of your browser is the same on each of your tests.
In some cases, you might encounter an error when setting the viewport size. The cause of the issue could be the fact that the viewport size you are trying to set is too large, since the machine that runs the test should have a larger screen resolution than the browser's viewport size.
One way you can handle this is by specifying a smaller viewport size as in the following article.
Another way to approach this issue, which is available solely for Sauce Labs customers, is by adjusting screen resolution in Sauce Labs:
Sauce Labs users can explicitly specify the desired resolution.
In order to do so, you simply need to add an additional entry to your DesiredCapabilies object, called "screenResolution". For example, in Java:
Note that using the first approach will not ensure consistency, as the screen resolution might vary between the test runs.