function it_does_not_report_screenshot_taking_not_supported_errors_on_screen(OutputInterface $output, Session $session, DriverInterface $driver)
 {
     $output->writeln(Argument::cetera())->shouldNotBeCalled();
     $driverInstance = $driver->getWrappedObject();
     $session->getScreenshot()->willThrow(new UnsupportedDriverActionException('Message.', $driverInstance));
     $this->takeScreenshot();
 }
Пример #2
0
 /**
  * Initializes session.
  *
  * @param DriverInterface  $driver
  * @param SelectorsHandler $selectorsHandler
  */
 public function __construct(DriverInterface $driver, SelectorsHandler $selectorsHandler = null)
 {
     $driver->setSession($this);
     if (null === $selectorsHandler) {
         $selectorsHandler = new SelectorsHandler();
     }
     $this->driver = $driver;
     $this->selectorsHandler = $selectorsHandler;
     $this->page = new DocumentElement($this);
 }
Пример #3
0
 /**
  * Initializes exception.
  *
  * @param string                  $message   optional message
  * @param DriverInterface|Session $driver    driver instance (or session for BC)
  * @param \Exception|null         $exception expectation exception
  */
 public function __construct($message, $driver, \Exception $exception = null)
 {
     if ($driver instanceof Session) {
         @trigger_error('Passing a Session object to the ExpectationException constructor is deprecated as of Mink 1.7. Pass the driver instead.', E_USER_DEPRECATED);
         $this->session = $driver;
         $this->driver = $driver->getDriver();
     } elseif (!$driver instanceof DriverInterface) {
         // Trigger an exception as we cannot typehint a disjunction
         throw new \InvalidArgumentException('The ExpectationException constructor expects a DriverInterface or a Session.');
     } else {
         $this->driver = $driver;
     }
     if (!$message && null !== $exception) {
         $message = $exception->getMessage();
     }
     parent::__construct($message, 0, $exception);
 }
Пример #4
0
 protected function mockNamedFinder($xpath, array $results, $locator, $times = 2)
 {
     if (!is_array($results[0])) {
         $results = array($results, array());
     }
     // In case of empty results, a second call will be done using the partial selector
     $processedResults = array();
     foreach ($results as $result) {
         $processedResults[] = $result;
         if (empty($result)) {
             $processedResults[] = $result;
             $times++;
         }
     }
     $returnValue = call_user_func_array(array($this, 'onConsecutiveCalls'), $processedResults);
     $this->driver->expects($this->exactly($times))->method('find')->with('//html' . $xpath)->will($returnValue);
     $this->selectors->expects($this->exactly($times))->method('selectorToXpath')->with($this->logicalOr('named_exact', 'named_partial'), $locator)->will($this->returnValue($xpath));
 }
Пример #5
0
 /**
  * @param string               $filterName The name of the filter
  * @param string               $value      The value to filter by
  * @param bool|string          $operator   If false, no operator will be selected
  * @param DriverInterface|null $driver     Required to filter by multiple choices
  *
  * @throws \Behat\Mink\Exception\ElementNotFoundException
  */
 public function filterBy($filterName, $value, $operator = false, DriverInterface $driver = null)
 {
     $filter = $this->getFilter($filterName);
     $this->openFilter($filter);
     if ($elt = $filter->find('css', 'select')) {
         if ($elt->getText() === "between not between more than less than is empty") {
             $this->filterByDate($filter, $value, $operator);
         } elseif ($elt->getParent()->find('css', 'button.ui-multiselect')) {
             if (!$driver || !$driver instanceof Selenium2Driver) {
                 throw new \InvalidArgumentException('Selenium2Driver is required to filter by a choice filter');
             }
             $values = explode(',', $value);
             foreach ($values as $value) {
                 $driver->executeScript(sprintf("\$('.ui-multiselect-menu:visible input[title=\"%s\"]').click().trigger('click');", $value));
                 sleep(1);
             }
             // Uncheck the 'All' option
             if (!in_array('All', $values)) {
                 $driver->executeScript("var all = \$('.ui-multiselect-menu:visible input[title=\"All\"]');" . "if (all.length && all.is(':checked')) { all.click().trigger('click'); }");
             }
         }
     } elseif ($elt = $filter->find('css', 'div.filter-criteria')) {
         $results = $this->getElement('Select2 results');
         $select2 = $filter->find('css', '.select2-input');
         if (false !== $operator) {
             $filter->find('css', 'button.dropdown-toggle')->click();
             $filter->find('css', sprintf('[data-value="%s"]', $operator))->click();
         }
         if (null !== $results && null !== $select2) {
             if (in_array($value, ['empty', 'is empty'])) {
                 // Allow passing 'empty' as value too (for backwards compability with existing scenarios)
                 $filter->find('css', 'button.dropdown-toggle')->click();
                 $filter->find('css', '[data-value="empty"]')->click();
             } else {
                 $values = explode(',', $value);
                 foreach ($values as $value) {
                     $driver->getWebDriverSession()->element('xpath', $select2->getXpath())->postValue(['value' => [$value]]);
                     sleep(2);
                     $results->find('css', 'li')->click();
                     sleep(2);
                 }
             }
         } elseif ($value !== false) {
             $elt->fillField('value', $value);
         }
         $filter->find('css', 'button.filter-update')->click();
     } else {
         throw new \InvalidArgumentException(sprintf('Filtering by "%s" is not yet implemented"', $filterName));
     }
 }
Пример #6
0
 /**
  * Resize window to mobile size
  *
  * @param DriverInterface $driver
  */
 public function resizeToMobileWindow(DriverInterface $driver)
 {
     $driver->resizeWindow($this->desktopWidth, $this->desktopHeight);
 }
Пример #7
0
 /**
  * @param string               $filterName The name of the filter
  * @param string               $value      The value to filter by
  * @param string               $operator   If false, no operator will be selected
  * @param DriverInterface|null $driver     Required to filter by multiple choices
  */
 public function filterBy($filterName, $value, $operator = false, DriverInterface $driver = null)
 {
     $filter = $this->getFilter($filterName);
     $this->openFilter($filter);
     if ($elt = $filter->find('css', 'select')) {
         if ($elt->getText() === "between not between more than less than is empty") {
             $this->filterByDate($filter, $value, $operator);
         } elseif ($elt->getParent()->find('css', 'button.ui-multiselect')) {
             if (!$driver || !$driver instanceof Selenium2Driver) {
                 throw new \InvalidArgumentException('Selenium2Driver is required to filter by a choice filter');
             }
             $values = explode(',', $value);
             foreach ($values as $value) {
                 $driver->executeScript(sprintf("\$('.ui-multiselect-menu:visible input[title=\"%s\"]').click().trigger('click');", $value));
                 sleep(1);
             }
             // Uncheck the 'All' option
             if (!in_array('All', $values)) {
                 $driver->executeScript("var all = \$('.ui-multiselect-menu:visible input[title=\"All\"]');" . "if (all.length && all.is(':checked')) { all.click().trigger('click'); }");
             }
         }
     } elseif ($elt = $filter->find('css', 'div.filter-criteria')) {
         if ($operator !== false) {
             $filter->find('css', 'button.dropdown-toggle')->click();
             $filter->find('css', '[data-value="' . $operator . '"]')->click();
         }
         if ($value !== false) {
             $elt->fillField('value', $value);
         }
         $filter->find('css', 'button.filter-update')->click();
     } else {
         throw new \InvalidArgumentException(sprintf('Filtering by "%s" is not yet implemented"', $filterName));
     }
 }