One of the sad realities of browser testing is that for some functions to work the browser just has to be on top. If it’s not on top, tests will fail. There has to be a way to bring browsers to the front…
Well, if you’re running your tests on a Mac, you can easily bring any application to the front using AppleScript. If you’ve never heard of AppleScript, there’s a reason: it’s awful and no one uses it. But in this instance it does the job.
The following code shows you (in ruby) how to bring Chrome to the front and then resize the window:
Here’s the same thing for Firefox:
It took me a while to hunt around for a solution and then a little while more to figure out the AppleScript required to do the job. Hope it helps!