MDL-82782 behat: Support runtime scaling of Behat windows

This commit is contained in:
Andrew Nicols
2024-08-14 21:48:52 +08:00
parent 62c1f37d40
commit 6357e519e8
2 changed files with 30 additions and 5 deletions
+16 -1
View File
@@ -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
+14 -4
View File
@@ -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,
);
}
/**