MDL-44557 behat: Allow nehat to resize window

Run all behat with medium (1024x768) screen size to
avoid failures with small screen size. Also, added
feature to let scenario chnage screen size if need be.
This commit is contained in:
Rajesh Taneja
2014-03-26 13:59:14 +08:00
parent bfb6e97eae
commit 3b0b5e570d
3 changed files with 49 additions and 1 deletions
+34
View File
@@ -643,4 +643,38 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext {
);
}
/**
* Change browser window size.
* - small: 640x480
* - medium: 1024x768
* - large: 2560x1600
*
* @param string $windowsize size of window.
* @throws ExpectationException
*/
protected function resize_window($windowsize) {
switch ($windowsize) {
case "small":
$width = 640;
$height = 480;
break;
case "medium":
$width = 1024;
$height = 768;
break;
case "large":
$width = 2560;
$height = 1600;
break;
default:
preg_match('/^(small|medium|large|\d+x\d+)$/', $windowsize, $matches);
if (empty($matches) || (count($matches) != 2)) {
throw new ExpectationException("Invalid screen size, can't resize", $this->getSession());
}
$size = explode('x', $windowsize);
$width = (int) $size[0];
$height = (int) $size[1];
}
$this->getSession()->getDriver()->resizeWindow($width, $height);
}
}
+13
View File
@@ -891,4 +891,17 @@ class behat_general extends behat_base {
return;
}
}
/**
* Change browser window size small: 640x480, medium: 1024x768, large: 2560x1600, custom: widthxheight
*
* Example: I change window size to "small" or I change window size to "1024x768"
*
* @throws ExpectationException
* @Then /^I change window size to "([^"](small|medium|large|\d+x\d+))"$/
* @param string $windowsize size of the window (small|medium|large|wxh).
*/
public function i_change_window_size_to($windowsize) {
$this->resize_window($windowsize);
}
}
+2 -1
View File
@@ -230,7 +230,8 @@ class behat_hooks extends behat_base {
self::$initprocessesfinished = true;
}
// Run all test with medium (1024x768) screen size, to avoid responsive problems.
$this->resize_window('medium');
}
/**