How to bring a browser to the front (on a mac)

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!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>