/**
  * Locates elements using the locator.
  *
  * @return NodeElement[]
  * @throws ElementNotFoundException When element wasn't found on the page.
  */
 protected function locateElements()
 {
     $elements = $this->locator->findAll();
     if (empty($elements)) {
         throw new ElementNotFoundException('No elements found by selector: ' . (string) $this->locator);
     }
     return $elements;
 }
 /**
  * @return WebElementProxy
  * @dataProvider proxyDataProvider
  */
 public function testProxyWebElement($element_class, $proxy_class)
 {
     $search_context = m::mock('\\QATools\\QATools\\PageObject\\ISearchContext');
     $this->locator->shouldReceive('getSearchContext')->andReturn($search_context);
     $node_element = $this->createNodeElement();
     $this->locator->shouldReceive('findAll')->andReturn(array($node_element));
     $this->property->shouldReceive('isSimpleDataType')->andReturn(false);
     $this->property->shouldReceive('getDataType')->andReturn($element_class);
     $proxy = $this->decorator->decorate($this->property);
     $this->assertProxy($proxy, $proxy_class, $element_class);
     $this->assertEquals($node_element->getXpath(), $proxy->getXpath());
     return $proxy;
 }
 /**
  * @return WebElementProxy
  * @dataProvider proxyDataProvider
  */
 public function testProxyWebElement($element_class, $proxy_class)
 {
     $search_context = m::mock('\\QATools\\QATools\\PageObject\\ISearchContext');
     $this->locator->shouldReceive('getSearchContext')->andReturn($search_context);
     $node_elements = array($this->createNodeElement('xpath1'), $this->createNodeElement('xpath2'));
     $this->locator->shouldReceive('findAll')->andReturn($node_elements);
     $this->property->shouldReceive('isSimpleDataType')->andReturn(false);
     $this->property->shouldReceive('getDataType')->andReturn($element_class);
     $proxy = $this->decorator->decorate($this->property);
     $this->assertProxy($proxy, $proxy_class, $element_class);
     if (strpos($proxy_class, 'Collection') !== false) {
         foreach ($proxy->getObject() as $index => $proxied_element) {
             $this->assertEquals($node_elements[$index]->getXpath(), $proxied_element->getXpath(), 'The method call is proxied to collection element.');
         }
     } else {
         $this->assertEquals($node_elements[0]->getXpath(), $proxy->getXpath(), 'The method call is proxied.');
     }
     return $proxy;
 }
 /**
  * Verifies, that annotations are being correctly used.
  *
  * @param array           $annotations Annotations.
  * @param IElementLocator $locator     Locator.
  *
  * @return void
  * @throws AnnotationException When annotation is being used incorrectly.
  */
 private function _assertAnnotationUsage(array $annotations, IElementLocator $locator)
 {
     if (!$annotations || !$annotations[0] instanceof BEMAnnotation) {
         throw new AnnotationException('BEM block/element must be specified as annotation', AnnotationException::TYPE_REQUIRED);
     }
     /** @var BEMAnnotation $annotation */
     $annotation = $annotations[0];
     if ($annotation->element && $annotation->block || !$annotation->element && !$annotation->block) {
         throw new AnnotationException("Either 'block' or 'element' key with non-empty value must be specified in the annotation", AnnotationException::TYPE_INCORRECT_USAGE);
     } elseif ($annotation->element && !$locator->getSearchContext() instanceof IBlock) {
         throw new AnnotationException('BEM element can only be used in Block sub-class (or any class, implementing IBlock interface) property', AnnotationException::TYPE_INCORRECT_USAGE);
     } elseif ($annotation->block && !$locator->getSearchContext() instanceof BEMPage) {
         throw new AnnotationException('BEM block can only be used in BEMPage sub-class property', AnnotationException::TYPE_INCORRECT_USAGE);
     }
 }