Skip to content

Commit

Permalink
MDL-72874 behat: Allow behat window sizes to be modified during run
Browse files Browse the repository at this point in the history
In some situations it is useful to modify the requested screensize by a
modifier. This allows for failing tests to be rerun at a different
screensize, where the original screensize triggered a failure for some
size-related reason.
  • Loading branch information
andrewnicols committed Oct 21, 2021
1 parent 261bc97 commit babe07e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config-dist.php
Expand Up @@ -954,6 +954,12 @@
// Example:
// $CFG->behat_increasetimeout = 3;
//
// Yon can specify a window size modifier for Behat, which is applied to any window szie changes.
// For example, if a window size of 640x768 is specified, with a modifier of 2, then the final size is 1280x1536.
// This is particularly useful for behat reruns to eliminate issues with window sizing.
// Example:
// $CFG->behat_window_size_modifier = 1;
//
// Including feature files from directories outside the dirroot is possible if required. The setting
// requires that the running user has executable permissions on all parent directories in the paths.
// Example:
Expand Down
8 changes: 8 additions & 0 deletions lib/behat/classes/behat_session_trait.php
Expand Up @@ -748,6 +748,8 @@ public function has_tag(string $tag) : bool {
* @throws ExpectationException
*/
protected function resize_window($windowsize, $viewport = false) {
global $CFG;

// Non JS don't support resize window.
if (!$this->running_javascript()) {
return;
Expand Down Expand Up @@ -775,6 +777,12 @@ protected function resize_window($windowsize, $viewport = false) {
$width = (int) $size[0];
$height = (int) $size[1];
}

if (isset($CFG->behat_window_size_modifier) && is_numeric($CFG->behat_window_size_modifier)) {
$width *= $CFG->behat_window_size_modifier;
$height *= $CFG->behat_window_size_modifier;
}

if ($viewport) {
// When setting viewport size, we set it so that the document width will be exactly
// as specified, assuming that there is a vertical scrollbar. (In cases where there is
Expand Down

0 comments on commit babe07e

Please sign in to comment.