-
Bug
-
Resolution: Fixed
-
Minor
-
2.7, 2.8
-
MOODLE_27_STABLE, MOODLE_28_STABLE
-
MOODLE_28_STABLE
-
When running behat tests that involve switching the browser window with calls like
And I switch to "questionpreview" window
And I switch to "main" window
Chrome is unable to focus back on the main window and the tests fail. The reason is that the main window has no name and the selenium driver method to switch windows won't allow an empty string as a name.
The simple fix I have found is to use the selenium driver evaluateScript() method to set the window name via js. Not a perfect solution but it works.
I've added it to the pattern match question type I'm testing.
For reference I've included the details of the fix I have found.
In the background section of the behat script I add the line:
When I set the window name to "main"
The line triggers the method in the new class.
require_once(_DIR_ . '/../../../../../lib/behat/behat_base.php');
require_once(_DIR_ . '/../../../../../question/tests/behat/behat_question_base.php');
use Behat\Behat\Context\Step\Given,
Behat\Behat\Context\Step\Then,
Behat\Gherkin\Node\TableNode;
/**
- Steps definitions related to qtype_pmatch.
* - @package qtype_pmatch
- @category test
- @copyright 2014 The Open University
- @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_qtype_pmatch extends behat_question_base {
/** - Sets a form field with a given config value.
* - @When /^I set the window name to "([^"]*)"$/
- @param string $name
*/
public function i_set_window_name($name) { return $this->getSession()->evaluateScript('window.name="'.$this->escape($name).'"'); }}
The issue I haven't yet solved is pressing the close preview button. If you do this behat stops working like before. So I've commented it out for now.
I haven't tested it doesn't break other browsers like firefox. It also still means the existing switch to main window method won't work because it still passes an empty string.
A related bug is MDL-45249.
- has been marked as being related by
-
MDL-47881 Get chrome/phantomjs switching to main window in behat (backport of MDL-47588)
-
- Closed
-