Completed
Push — master ( 311854...50994d )
by Andrii
20:37 queued 05:34
created

CountHelper::indexOf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
/**
3
 * HiPanel core package
4
 *
5
 * @link      https://hipanel.com/
6
 * @package   hipanel-core
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\tests\_support\Helper;
12
13
class CountHelper extends \Codeception\Module
14
{
15
    /**
16
     * @param string $cssOrXpath
17
     * @throws \Codeception\Exception\ModuleException
18
     * @return int
19
     */
20
    public function countElements(string $cssOrXpath): int
21
    {
22
        $I = $this->getModule('WebDriver');
23
24
        return count($I->grabMultiple($cssOrXpath));
25
    }
26
27
    /**
28
     * Returns position of the element in the set of elements.
29
     *
30
     * The position counts from 0.
31
     * If the element is not found in the set -1 will be returned.
32
     *
33
     * ```html
34
     *  <ul>
35
     *      <li></li>
36
     *      <li></li>
37
     *      <li class="target"></li>
38
     *      <li></li>
39
     *  </ul>
40
     *  <img />
41
     * '''
42
     *
43
     * ```php
44
     *  indexOf('li.target', 'li')  => 2
45
     *  indexOf('img', 'li')        => -1
46
     * ```
47
     * @param string $elementSelector
48
     * @param string $setSelector
49
     * @return int
50
     * @throws \Codeception\Exception\ModuleException
51
     */
52
    public function indexOf(string $elementSelector, string $setSelector): int
53
    {
54
        $I = $this->getModule('WebDriver');
55
56
        return  $I->executeJS(<<<JS
57
return $('{$setSelector}').index($("{$elementSelector}"));
58
JS
59
        );
60
    }
61
}
62