Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-47588

Get chrome/phantomjs switching to main window in behat

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Run

      behatcore --tags _switch_window

      in all browsers that we try to support through Behat.

      (Be careful if you have profiles set for different browsers which automatically disable the _switch_window tag for Chrome. There should be 136 steps executed.)

      Show
      Run behatcore --tags _switch_window in all browsers that we try to support through Behat. (Be careful if you have profiles set for different browsers which automatically disable the _switch_window tag for Chrome. There should be 136 steps executed.)
    • Affected Branches:
      MOODLE_27_STABLE, MOODLE_28_STABLE
    • Fixed Branches:
      MOODLE_28_STABLE
    • Pull from Repository:
    • Pull Master Branch:

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              timhunt Tim Hunt
              Reporter:
              colchambers Colin Chambers
              Peer reviewer:
              Sam Marshall
              Integrator:
              Dan Poltawski
              Tester:
              Zachary Durber
              Participants:
              Component watchers:
              Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
              Votes:
              1 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                10/Nov/14