public function testFindAll() { $xpath = 'h3[a]'; $css = 'h3 > a'; $this->driver->expects($this->exactly(2))->method('find')->will($this->returnValueMap(array(array('//html/' . $xpath, array(2, 3, 4)), array('//html/' . $css, array(1, 2))))); $this->selectors->expects($this->exactly(2))->method('selectorToXpath')->will($this->returnValueMap(array(array('xpath', $xpath, $xpath), array('css', $css, $css)))); $this->assertEquals(3, count($this->document->findAll('xpath', $xpath))); $this->assertEquals(2, count($this->document->findAll('css', $css))); }
/** * 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(); }
/** * 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)); }
/** * Select value in choice list * * @param DocumentElement $page * @param string $field * @param string $value * @throws \Exception */ private function selectValue(DocumentElement $page, $field, $value) { $chosenResults = $page->findAll('css', '.select2-results li'); foreach ($chosenResults as $result) { if ($result->getText() == $value) { $result->click(); return; } } throw new \Exception(sprintf('Value "%s" not found for "%s"', $value, $field)); }