diff --git a/lib/behat/classes/behat_session_trait.php b/lib/behat/classes/behat_session_trait.php index 02e914edd8f..62b6fd6d968 100644 --- a/lib/behat/classes/behat_session_trait.php +++ b/lib/behat/classes/behat_session_trait.php @@ -761,9 +761,14 @@ trait behat_session_trait { * * @param string $windowsize size of window. * @param bool $viewport If true, changes viewport rather than window size + * @param bool $scalesize Whether to scale the size by the WINDOWSCALE environment variable * @throws ExpectationException */ - protected function resize_window($windowsize, $viewport = false) { + protected function resize_window( + string $windowsize, + bool $viewport = false, + bool $scalesize = true, + ): void { global $CFG; // Non JS don't support resize window. @@ -807,6 +812,16 @@ trait behat_session_trait { $height *= $CFG->behat_window_size_modifier; } + if ($scalesize) { + // Scale the window size by the WINDOWSCALE environment variable. + // This is intended to be used for Behat reruns to negate the impact of browser window size issues. + // This allows a per-run, runtime configuration of the scaling, unlike behat_window_size_modifier which + // typically applies to all runs. + $scalefactor = getenv('WINDOWSCALE') ? floatval(getenv('WINDOWSCALE')) : 1; + $width *= $scalefactor; + $height *= $scalefactor; + } + 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 diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index d03c42b0b40..491a5decca9 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -1331,12 +1331,22 @@ EOF; * browser window has same viewport size even when you run Behat on multiple operating systems. * * @throws ExpectationException - * @Then /^I change (window|viewport) size to "(mobile|tablet|small|medium|large|\d+x\d+)"$/ - * @Then /^I change the (window|viewport) size to "(mobile|tablet|small|medium|large|\d+x\d+)"$/ + * @Then /^I change (window|viewport) size to "(mobile|tablet|small|medium|large|\d+x\d+)"( without runtime scaling)?$/ + * @Then /^I change the (window|viewport) size to "(mobile|tablet|small|medium|large|\d+x\d+)"( without runtime scaling)?$/ + * @param string $windowviewport Whether this is a window or viewport size hcange * @param string $windowsize size of the window (mobile|tablet|small|medium|large|wxh). + * @param null|string $scale whether to lock runtime scaling (string) or to allow it (null) */ - public function i_change_window_size_to($windowviewport, $windowsize) { - $this->resize_window($windowsize, $windowviewport === 'viewport'); + public function i_change_window_size_to( + $windowviewport, + $windowsize, + ?string $scale = null, + ): void { + $this->resize_window( + $windowsize, + $windowviewport === 'viewport', + $scale === null, + ); } /**