MDL-66979 behat: Improve chromeOptions configuration

Simplify the chromeOptions configuration to improve readability.
This commit is contained in:
Andrew Nicols 2020-11-13 14:20:31 +08:00
parent ad85ffb55a
commit f11f91a1e0

View file

@ -634,20 +634,21 @@ class behat_config_util {
// We also need to disable web security, otherwise it can't make CSS requests to the server // We also need to disable web security, otherwise it can't make CSS requests to the server
// on localhost due to CORS restrictions. // on localhost due to CORS restrictions.
if (!empty($values['browser']) && $values['browser'] === 'chrome') { if (!empty($values['browser']) && $values['browser'] === 'chrome') {
if (!isset($values['capabilities'])) { $values = array_merge_recursive(
$values['capabilities'] = []; [
} 'capabilities' => [
if (!isset($values['capabilities']['extra_capabilities'])) { 'extra_capabilities' => [
$values['capabilities']['extra_capabilities'] = []; 'chromeOptions' => [
} 'args' => [
if (!isset($values['capabilities']['extra_capabilities']['chromeOptions'])) { 'unlimited-storage',
$values['capabilities']['extra_capabilities']['chromeOptions'] = []; 'disable-web-security',
} ],
if (!isset($values['capabilities']['extra_capabilities']['chromeOptions']['args'])) { ],
$values['capabilities']['extra_capabilities']['chromeOptions']['args'] = []; ],
} ],
$values['capabilities']['extra_capabilities']['chromeOptions']['args'][] = '--unlimited-storage'; ],
$values['capabilities']['extra_capabilities']['chromeOptions']['args'][] = '--disable-web-security'; $values
);
// If the mobile app is enabled, check its version and add appropriate tags. // If the mobile app is enabled, check its version and add appropriate tags.
if ($mobiletags = $this->get_mobile_version_tags()) { if ($mobiletags = $this->get_mobile_version_tags()) {
@ -657,6 +658,14 @@ class behat_config_util {
$values['tags'] = $mobiletags; $values['tags'] = $mobiletags;
} }
} }
$values['capabilities']['extra_capabilities']['chromeOptions']['args'] = array_map(function($arg): string {
if (substr($arg, 0, 2) === '--') {
return substr($arg, 2);
}
return $arg;
}, $values['capabilities']['extra_capabilities']['chromeOptions']['args']);
sort($values['capabilities']['extra_capabilities']['chromeOptions']['args']);
} }
// Fill tags information. // Fill tags information.