コード例 #1
0
ファイル: behat_form_select.php プロジェクト: rushi963/moodle
 /**
  * Sets the value(s) of a select element.
  *
  * Seems an easy select, but there are lots of combinations
  * of browsers and operative systems and each one manages the
  * autosubmits and the multiple option selects in a different way.
  *
  * @param string $value plain value or comma separated values if multiple. Commas in values escaped with backslash.
  * @return void
  */
 public function set_value($value)
 {
     // Is the select multiple?
     $multiple = $this->field->hasAttribute('multiple');
     $singleselect = $this->field->hasClass('singleselect') || $this->field->hasClass('urlselect');
     // Here we select the option(s).
     if ($multiple) {
         // Split and decode values. Comma separated list of values allowed. With valuable commas escaped with backslash.
         $options = preg_replace('/\\\\,/', ',', preg_split('/(?<!\\\\),/', trim($value)));
         // This is a multiple select, let's pass the multiple flag after first option.
         $afterfirstoption = false;
         foreach ($options as $option) {
             $this->field->selectOption(trim($option), $afterfirstoption);
             $afterfirstoption = true;
         }
     } else {
         // By default, assume the passed value is a non-multiple option.
         $this->field->selectOption(trim($value));
     }
     // Wait for all the possible AJAX requests that have been
     // already triggered by selectOption() to be finished.
     if ($this->running_javascript()) {
         // Trigger change event as this is needed by some drivers (Phantomjs). Don't do it for
         // Singleselect as this will cause multiple event fire and lead to race-around condition.
         $browser = \Moodle\BehatExtension\Driver\MoodleSelenium2Driver::getBrowser();
         if (!$singleselect && $browser == 'phantomjs') {
             $script = "Syn.trigger('change', {}, {{ELEMENT}})";
             $this->session->getDriver()->triggerSynScript($this->field->getXpath(), $script);
         }
         $this->session->wait(behat_base::TIMEOUT * 1000, behat_base::PAGE_READY_JS);
     }
 }
コード例 #2
0
 /**
  * We print the site info + driver used and OS.
  *
  * At this point behat_hooks::before_suite() already
  * ran, so we have $CFG and family.
  *
  * @param SuiteEvent $event
  * @return void
  */
 public function beforeSuite(SuiteEvent $event)
 {
     global $CFG;
     require_once $CFG->dirroot . '/lib/behat/classes/util.php';
     $browser = \Moodle\BehatExtension\Driver\MoodleSelenium2Driver::getBrowser();
     // Calling all directly from here as we avoid more behat framework extensions.
     $runinfo = \behat_util::get_site_info();
     $runinfo .= 'Server OS "' . PHP_OS . '"' . ', Browser: "' . $browser . '"' . PHP_EOL;
     $runinfo .= 'Behat specific fixes have been applied. See http://docs.moodle.org/dev/Acceptance_testing#Browser_specific_fixes' . PHP_EOL;
     $runinfo .= 'Started at ' . date('d-m-Y, H:i', time());
     $this->writeln($runinfo);
 }