Exemplo n.º 1
0
 public function testFind()
 {
     $this->driver->expects($this->exactly(3))->method('find')->with('//html/h3[a]')->will($this->onConsecutiveCalls(array(2, 3, 4), array(1, 2), array()));
     $xpath = 'h3[a]';
     $css = 'h3 > a';
     $this->selectors->expects($this->exactly(3))->method('selectorToXpath')->will($this->returnValueMap(array(array('xpath', $xpath, $xpath), array('xpath', $xpath, $xpath), array('css', $css, $xpath))));
     $this->assertEquals(2, $this->document->find('xpath', $xpath));
     $this->assertEquals(1, $this->document->find('css', $css));
     $this->assertNull($this->document->find('xpath', $xpath));
 }
 /**
  * Upload file inside entity browser.
  *
  * NOTE: It will search for first tab with upload widget and file will be
  * uploaded there. Upload is done over input file field and it has to be
  * visible for selenium to work.
  *
  * @param \Behat\Mink\Element\DocumentElement $page
  *   Current active page.
  * @param string $filePath
  *   Path to file that should be uploaded.
  *
  * @throws \Exception
  */
 public function uploadFile(DocumentElement $page, $filePath)
 {
     // Click all tabs until we find upload Tab.
     $tabLinks = $page->findAll('css', '.eb-tabs a');
     if (empty($tabLinks)) {
         throw new \Exception(sprintf('Unable to find tabs in entity browser iframe on page %s', $this->getSession()->getCurrentUrl()));
     }
     // Click all tabs until input file field for upload is found.
     $fileFieldSelector = "input[type='file'].dz-hidden-input";
     $fileField = NULL;
     foreach ($tabLinks as $tabLink) {
         /* @var \Behat\Mink\Element\NodeElement $tabLink */
         $tabLink->click();
         $this->assertSession()->assertWaitOnAjaxRequest();
         $fileField = $page->find('css', $fileFieldSelector);
         if (!empty($fileField)) {
             break;
         }
     }
     if (empty($fileField)) {
         throw new \Exception(sprintf('The drop-down file field was not found on the page %s', $this->getSession()->getCurrentUrl()));
     }
     // Make file field visible and isolate possible problems with "multiple".
     $this->getSession()->executeScript('jQuery("' . $fileFieldSelector . '").show(0).css("visibility","visible").width(200).height(30).removeAttr("multiple");');
     $fileField->attachFile($filePath);
     $this->assertSession()->assertWaitOnAjaxRequest();
     // Wait up to 10 sec that "Use selected" button is active.
     $this->getSession()->wait(10000, '(typeof jQuery === "undefined" || !jQuery(\'input[name="op"]\').is(":disabled"))');
     $this->assertSession()->assertWaitOnAjaxRequest();
 }
Exemplo n.º 3
0
 /**
  * Get a html element by css selector notation
  * @param string $cssSelector the css selector path
  * @return mixed
  * @throws Behat\Mink\Exception\ElementNotFoundException
  */
 public function objectByCssSelector($cssSelector)
 {
     $element = $this->page->find('css', $cssSelector);
     try {
         if ($element == null) {
             // @todo: add cloudrexx exception
             throw new \Behat\Mink\Exception\ElementNotFoundException($this->session, 'input', 'css', 'input[type="submit"]');
         }
     } catch (Exception $e) {
         echo $e->getLine();
     }
     return $element;
 }
 /**
  * Select value in choice list
  *
  * @param DocumentElement $page
  * @param string          $component
  * @param string          $field
  * @param string          $value
  * @throws \Exception
  */
 private function selectComponentValue(DocumentElement $page, $component, $field, $value)
 {
     $select = $page->find('css', sprintf('#%s', $field));
     if (!$select) {
         throw new \Exception(sprintf('No select "%s" found', $field));
     }
     $selector = sprintf('.fs-%1$s button.fs-%1$s-item', $component);
     $choices = $page->findAll('css', $selector);
     foreach ($choices as $choice) {
         if ($choice->getText() == $value) {
             $choice->click();
             return;
         }
     }
     throw new \Exception(sprintf('Value "%s" not found for "%s"', $value, $field));
 }
 /**
  * Fill CKEditor field.
  *
  * @param \Behat\Mink\Element\DocumentElement $page
  *   Current active page.
  * @param string $ckEditorCssSelector
  *   CSS selector for CKEditor.
  * @param string $text
  *   Text that will be filled into CKEditor.
  */
 public function fillCkEditor(DocumentElement $page, $ckEditorCssSelector, $text)
 {
     $ckEditor = $page->find('css', $ckEditorCssSelector);
     $ckEditorId = $ckEditor->getAttribute('id');
     $this->getSession()->getDriver()->executeScript("CKEDITOR.instances[\"{$ckEditorId}\"].setData(\"{$text}\");");
 }
Exemplo n.º 6
0
 /**
  * @param DocumentElement $page
  * @param string $collectionName
  *
  * @return NodeElement
  */
 protected function getFormCollectionDiv(DocumentElement $page, $collectionName)
 {
     return $page->find('css', 'div[data-form-type="collection"][id*="' . $collectionName . '"]');
 }
 /**
  * Fill Select2 search field
  *
  * @param DocumentElement $page
  * @param string          $field
  * @param string          $value
  * @throws \Exception
  */
 private function fillSearchField(DocumentElement $page, $field, $value)
 {
     $driver = $this->getSession()->getDriver();
     if ('Behat\\Mink\\Driver\\Selenium2Driver' === get_class($driver)) {
         // Can't use `$this->getSession()->getPage()->find()` because of https://github.com/minkphp/MinkSelenium2Driver/issues/188
         $select2Input = $this->getSession()->getDriver()->getWebDriverSession()->element('xpath', "//html/descendant-or-self::*[@class and contains(concat(' ', normalize-space(@class), ' '), ' select2-search__field ')]");
         if (!$select2Input) {
             throw new \Exception(sprintf('No field "%s" found', $field));
         }
         $select2Input->postValue(['value' => [$value]]);
     } else {
         $select2Input = $page->find('css', '.select2-search__field');
         if (!$select2Input) {
             throw new \Exception(sprintf('No input found for "%s"', $field));
         }
         $select2Input->setValue($value);
     }
     $this->getSession()->wait(10000, '(0 === jQuery.active)');
 }