Completed
Push — master ( a33641...7233dc )
by San
02:42
created

Html::countElements()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 3
1
<?php
2
3
namespace Behatch;
4
5
use Behat\MinkExtension\Context\RawMinkContext;
6
7
trait Html
8
{
9
    abstract protected function getSession($name = null);
10
11 View Code Duplication
    protected function countElements($element, $index, $parent)
12
    {
13
        $page = $this->getSession()->getPage();
14
15
        $parents = $page->findAll('css', $parent);
16
        if (!isset($parents[$index - 1])) {
17
            throw new \Exception("The $index element '$parent' was not found anywhere in the page");
18
        }
19
20
        $elements = $parents[$index - 1]->findAll('css', $element);
21
        return count($elements);
22
    }
23
24 View Code Duplication
    protected function findElement($selector, $locator, $index)
25
    {
26
        $page = $this->getSession()->getPage();
27
28
        $nodes = $page->findAll($selector, $locator);
29
30
        if (!isset($nodes[$index - 1])) {
31
            throw new \Exception("The $index $selector '$locator' was not found anywhere in the page");
32
        }
33
34
        return $nodes[$index - 1];
35
    }
36
}
37