views:

122

answers:

2

I want to use selenium/JUnit to do some mobile emulator testing using the FireMobileSimulator plugin. Given that the plugin can emulate a number of different phones, I'd like to be able to cycle through testsswapping out devices as required.

The device being emulated is controlled by two config options. Being able to manipulate these programatically at runtime would be handy, but I'm not sure of how to go about it. My google-fu is failing me. Can anyone offer a solution?

A: 

You could use firefox profiles and run selenium with different profiles(in profiles you can enable plugins and specific configuration for them and for firefox).

01
I considered this, as well as dynamically updating a user.js file on startup. While this would probably work, I'd like to find a solution that isn't quite so much of a pain in the arse to maintain. Seems like using a sledgehammer to crack a very small nut.
Ben Kelly
Adam Goucher suggested seeing if accessing the extension through its chrome urls would work. There was nothing useful that I could see, but I suppose I could hack something into the app that might do the trick.
Ben Kelly
A: 

I wanted to be able to test an application without cookies enabled without having to maintain firefox profiles. I found out that firefox accepts a minimal profile, containing only prefs.js, which only contains the setting user_pref(\"network.cookie.cookieBehavior\", 2);. So I came up with a small script to start the selenium server. This still is not ideal because test preconditions should not be in server start, but a script at least reduces the effort to maintain one or more complete firefox profiles. It runs with firefox 3.6 / linux and probably with older firefox versions too.

Still the plugin you need is not integrated. I don't know at all which steps would be neccessary to "install" and configure a plugin using a script, but maybe there is a chance initializing extensions.ini and the extensions/ directory and probably something more.

The script assumes there is a "lib" directory in the current directory which contains selenium-server.jar.

#!/bin/sh
set -x

# create firefox profile, cookies disabled
d=`mktemp -d -t ffp.XXXXX`
trap "rm -rf \"$d\"; exit" 0 1 2 3 15
echo "user_pref(\"network.cookie.cookieBehavior\", 2);" > "$d/prefs.js"

java -jar lib/selenium-server.jar -firefoxProfileTemplate "$d"
Moritz Both
I have a profile set up with the extensions I need and starting up with one kind of device enabled is something I can do now (setting prefs with user.js). I could switch device types by restarting firefox each time and updating this file using something similar to the script you posted (thanks very much, btw). That would be one solution. It would be nice to have the option of changing it without having to restart FF however. At this point I think adding a new xul file with a dropdown to the existing plugin looks like the next option I'll try.
Ben Kelly