Archive for multiple firefox instances

Launching a separate Firefox instance from Ant, testing php files locally

Posted in Ant, Development with tags , , , on January 17, 2011 by andkrup

Darron Schall has a post about launching Firefox via Apache Ant on mac:

http://www.darronschall.com/weblog/2007/12/launching-firefox-from-ant-on-osx.cfm

I found the post very useful, although the post was made 3 years ago, but where Darron used the task to test Swf files, I was interested in Launching Firefox in order to test php files locally and this had some unfortunate consequences.

My test-task includes copying all relevant project php-files to the local web servers www-location, then opening Firefox as described in above link. Last, a clean-up task can be invoked to remove the test files.

The problem is that Apache will lock the php-files when you test them because your request will require Apache to execute the php scripts, which means that the clean-up task cannot remove the files, because Apache has a lock on them.

Closing the tab in Firefox doesn’t help – you have to close the browser instance (I assume that Firefox somehow sends a ‘end-session’ signal that will make Apache release its file locks – I don’t really have an understand in this regard, but it works if you close the browser).

But if you do not want to close Firefox because you don’t want to close other tabs, you can combine the tips from this post:

http://devongovett.wordpress.com/2009/04/14/multiple-firefox-mac/

By creating multiple Firefox profiles, you can open as many Firefox instances as you have profiles. This way you can open and close a separate ‘test’ Firefox instance that will allow Apache to release your test files from memory on closing the ‘test’-profile Firefox instance without requiring you to close your other tabs in your normal profile Firefox instance.

The arguments for ‘open’ should look like this:

open -n -a /Applications/Firefox.app/Contents/MacOS/firefox-bin http://localhost/${ant.project.name}/ --args -P developer

, where ‘http://localhost/${ant.project.name}/’ is the web directory that just has been created and enabled for testing by a prior Ant task.

My ‘Test on localhost’ target looks like this:

<target name="Test on localhost" depends="Deploy to localhost">
 <property name="browser" value="open" />
<property name="browser.args" value=" -n -a /Applications/Firefox.app/Contents/MacOS/firefox-bin http://localhost/${ant.project.name}/ --args -P developer" />
 <property name="browser" value="open" />
 <exec executable="${browser}" spawn="yes">
 <arg line="${browser.args}" />
</exec>
 </target>

, where the depending task ‘Deploy to localhost’ is the task that copies all files that I want to test to the localhost web directory, and the ‘–args -P developer’ part is the magic that enables Ant to launch Firefox as a separate application instance. The ‘developer’ argument indicates that I have created a new Firefox profile named ‘developer’