// // You can find or change your Sauce access key on your Sauce account page: // // https://saucelabs.com/account $COMPOSER_INSTALLER = "https://getcomposer.org/installer"; $DEMO_URL = "https://raw.github.com/jlipps/sausage/master/WebDriverDemo.php"; $RC_DEMO_URL = "https://raw.github.com/jlipps/sausage/master/SeleniumRCDemo.php"; $APP_DEMO_URL = "https://raw.github.com/jlipps/sausage/master/WebDriverDemoShootout.php"; $BASE = getcwd(); $WIN_UNAMES = array( 'MINGW32_NT-6.0', 'UWIN-W7', 'WIN32', 'WINNT', 'Windows', 'Windows NT' ); $IS_WIN = in_array(php_uname('s'), $WIN_UNAMES); $PHP_BIN = PHP_BINDIR.($IS_WIN ? '\\' : '/').'php'.($IS_WIN ? '.exe' : ''); $pos_args = array(); foreach ($argv as $index => $arg) { if ($index != 0 && $arg[0] != "-") { $pos_args[] = $arg; } } if (count($pos_args) == 2) { $SAUCE_USERNAME = $pos_args[0]; $SAUCE_ACCESS_KEY = $pos_args[1]; } else { $SAUCE_USERNAME = getenv('SAUCE_USERNAME'); $SAUCE_ACCESS_KEY = getenv('SAUCE_ACCESS_KEY'); } main($argv); function main($argv) { global $IS_WIN, $FIX, $TUTORIAL, $MINIMAL_RUN; $opts = getopt("m::t::"); $MINIMAL_RUN = isset($opts['m']); $TUTORIAL = isset($opts['t']); $msg1 = << $error) { $solution = isset($solutions[$err_type]) ? $solutions[$err_type] : NULL; out("- $error", 'error'); if ($solution) out(" - To fix: $solution", 'info'); } exit(1); } else { out("done", 'success'); } } function startComposer() { global $COMPOSER_INSTALLER, $BASE, $PHP_BIN; if (is_file("$BASE/composer.phar")) { out("- Composer already installed", 'success'); } else { out("- Downloading Composer install script...", NULL, false); $php = file_get_contents($COMPOSER_INSTALLER); out("done", 'success'); file_put_contents("$BASE/getcomposer.php", $php); out("- Installing Composer...", NULL, false); list($output, $exitcode) = runProcess("$PHP_BIN $BASE/getcomposer.php"); if ($exitcode !== 0) { $msg = <<=0.16.0" } } EOF; file_put_contents("$BASE/composer.json", $json); list($output, $exitcode) = runProcess("$PHP_BIN $BASE/composer.phar install"); if ($exitcode !== 0) { $msg = << ", 'info'); } } else { out('done', 'success'); } } function downloadDemo() { global $DEMO_URL, $RC_DEMO_URL, $APP_DEMO_URL, $BASE; out("- Downloading demo test files...", NULL, false); file_put_contents("$BASE/WebDriverDemo.php", file_get_contents($DEMO_URL)); file_put_contents("$BASE/SeleniumRCDemo.php", file_get_contents($RC_DEMO_URL)); file_put_contents("$BASE/WebDriverDemoShootout.php", file_get_contents($APP_DEMO_URL)); out("done", 'success'); } function out($text, $color = null, $newLine = true) { if (DIRECTORY_SEPARATOR == '\\') { $hasColorSupport = false !== getenv('ANSICON'); } else { $hasColorSupport = true; } $styles = array( 'success' => "\033[0;32m%s\033[0m", 'error' => "\033[31;31m%s\033[0m", 'info' => "\033[33;33m%s\033[0m" ); $format = '%s'; if (isset($styles[$color]) && $hasColorSupport) { $format = $styles[$color]; } if ($newLine) { $format .= PHP_EOL; } printf($format, $text); } function runProcess($cmd) { $process = proc_open($cmd, array(array("pipe", "r"), array("pipe", "w"), array("pipe", "w")), $pipes, NULL); stream_set_blocking($pipes[1], 0); stream_set_blocking($pipes[2], 0); $status = proc_get_status($process); $output = ''; while ($status['running']) { $out_streams = array($pipes[1], $pipes[2]); $e = NULL; $f = NULL; $num_changed = stream_select($out_streams, $e, $f, 0, 20000); if ($num_changed) { foreach ($out_streams as $changed_stream) { $output .= stream_get_contents($changed_stream); } } $status = proc_get_status($process); } fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); proc_close($process); return array($output, $status['exitcode']); }