Ok, so I worked this out. Should anyone else have the same issue, here's how I resolved it.
In the ANT script that Jenkins runs, which runs PHPUnit in turn, I included a config.xml file. This sets a config (environment) variable called sauce
to true
<phpunit>
<php>
<env name="sauce" value="true" />
</php>
</phpunit>
Now the trick is to not actually use the $browsers static array, but instead to use the setupSpecificBrowser
method. So , now in my setUp() function of my tests, I just switch on the sauce env variable and if it exists then I know we are running from Jenkins and so I use the supplied variables from it.
if( getenv('sauce') == true) {
$browser = array(
'browserName' => getenv('SELENIUM_BROWSER'),
'desiredCapabilities' => array(
'version' => getenv('SELENIUM_VERSION'),
'platform' => getenv('SELENIUM_PLATFORM'),
)
);
} else {
$browser = array(
'browserName' => 'firefox',
'local' => true,
'sessionStrategy' => 'isolated'
);
}
$this->setupSpecificBrowser($browser);
AFAIK there doesn't seem to be any documentation for this, I just worked it from from looking at the code. Fun.