Skip to content

Instantly share code, notes, and snippets.

@alnutile
Created September 30, 2014 14:13
Show Gist options
  • Save alnutile/303988993403aee1fb45 to your computer and use it in GitHub Desktop.
Save alnutile/303988993403aee1fb45 to your computer and use it in GitHub Desktop.
function behat_editor_saucelabs_behat_editor_yml_array_alter(&$behat_yml, $context1, $settings) {
if( $context1 == 'generate_yml' ) {
//@TODO clean up this double if statement just may need to rethink the best way to alter this proecess
if ( isset($settings['context']) && ( $settings['context'] == 'behat_run_saucelabs' || $settings['context'] == 'behat_run_batch') ) {
/**
* needed to set some things for these but not android
*/
$mobile_devices = array('iPad', 'iPhone', 'ipad', 'iphone', 'iPad|landscape', 'iPhone|landscape');
if(variable_get('behat_debug_mode') == 1) {
watchdog('behat_editor_sauce_settings', print_r($settings, 1));
}
$reponame = '';
if(isset($settings['repo'])) { $reponame = $settings['repo']; }
$filename = (isset($settings['filename'])) ? $settings['filename'] : $context1;
$module = (isset($settings['module'])) ? $settings['module'] : $context1 ;
$name = 'Behat Tests Module:' . $module . ' ' . $reponame . ' ' . 'Filename: ' . $filename ;
$username = variable_get('behat_editor_saucelabs_username', '');
$token = variable_get('behat_editor_saucelabs_api', '');
list($browser, $version) = explode("|", $settings['browser_version']);
$os = $settings['os_version'];
$behat_yml['saucelabs']['context']['class'] = 'FeatureContext';
$behat_yml['saucelabs']['extensions']['Behat\MinkExtension\Extension']['default_session'] = 'selenium2';
$behat_yml['saucelabs']['extensions']['Behat\MinkExtension\Extension']['selenium2'] = array(
'browser' => $browser,
'wd_host' => "{$username}:{$token}@ondemand.saucelabs.com/wd/hub",
'capabilities' => array(
"platform" => "$os",
'browser' => "$browser",
'version' => "$version",
'name' => "$name",
"disable-popup-handler" => true
)
);
$behat_yml['saucelabs']['extensions']['Behat\MinkExtension\Extension']['selenium2']['capabilities']['selenium-version'] = '2.39.0';
/**
* Setup some duration
*/
$behat_yml['saucelabs']['extensions']['Behat\MinkExtension\Extension']['selenium2']['capabilities']['command-timeout'] = '600';
$behat_yml['saucelabs']['extensions']['Behat\MinkExtension\Extension']['selenium2']['capabilities']['max-duration'] = '600';
/**
* Setup some mobile defaults
*/
if (in_array($browser, $mobile_devices)) {
$behat_yml['saucelabs']['extensions']['Behat\MinkExtension\Extension']['selenium2']['capabilities']['selenium-version'] = '';
}
//Loops through settings and make a new section in the yml file for each settings
// later in the exec the same loop and key combination will run each test
//@todo this will be used for batch work only coming later
if(isset($settings['multi_browser_os'])) {
foreach($settings['multi_browser_os'] as $key => $value) {
$os = $value[0]['os'];
list($browser, $version) = explode("|", $value[0]['version']);
$browser_version = str_replace(array(' ', '.'), '_', "{$browser}_{$version}");
$behat_yml[$browser_version]['context']['class'] = 'FeatureContext';
$behat_yml[$browser_version]['extensions']['Behat\MinkExtension\Extension']['default_session'] = 'selenium2';
$behat_yml[$browser_version]['extensions']['Behat\MinkExtension\Extension']['selenium2'] = array(
'browser' => $browser,
'wd_host' => "{$username}:{$token}@ondemand.saucelabs.com/wd/hub",
'capabilities' => array(
"platform" => "$os",
'browser' => "$browser",
'version' => "$version",
'name' => "$name"
)
);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment