forked from sunnysideup/silverstripe-travis-support
-
Notifications
You must be signed in to change notification settings - Fork 0
/
travis_setup_selenium.php
executable file
·42 lines (35 loc) · 1.25 KB
/
travis_setup_selenium.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env php
<?php
/**
* Assumes to run in a SilverStripe webroot
*/
require_once 'lib.php';
$opts = getopt('', array(
'if-env:',
'base-url:',
));
// --if-env=BEHAT_TEST means that this script will only be executed if the given environment var is set
if(!checkenv(@$opts['if-env'])) {
echo "Apache skipped; {$opts['if-env']} wasn't set.\n";
exit(0);
}
$baseurl = (isset($opts['base-url'])) ? $opts['base-url'] : 'http://localhost:8000';
echo "Starting Selenium...\n";
run("sh -e /etc/init.d/xvfb start");
if(!putenv("DISPLAY=:99.0")) echo "ERROR: Could not set display!\n";
run("wget http://selenium.googlecode.com/files/selenium-server-standalone-2.37.0.jar");
if(!file_exists('artifacts')) mkdir('artifacts');
run("java -jar selenium-server-standalone-2.37.0.jar > artifacts/selenium.log 2>&1 &");
sleep(5);
// Write templated behat configuration
$behatTemplate = file_get_contents(dirname(__FILE__).'/behat.tmpl.yml');
$behat = str_replace(
array('$BASE_URL'),
array($baseurl),
$behatTemplate
);
echo "Writing behat.yml\n";
echo $behat . "\n";
file_put_contents("behat.yml", $behat);
if(file_exists("mysite/_config/behat.yml")) unlink("mysite/_config/behat.yml");
run("php framework/cli-script.php dev/generatesecuretoken path=mysite/_config/behat.yml");