ExpectedCondition   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A elementExists() 0 14 2
A elementRemoved() 0 13 2
1
<?php
2
3
namespace Magium\WebDriver;
4
5
use Facebook\WebDriver\WebDriverElement;
6
use Facebook\WebDriver\WebDriverExpectedCondition;
7
8
class ExpectedCondition extends WebDriverExpectedCondition
9
{
10
11
    public static function elementExists($selector, $by = 'byId')
12
    {
13
        return new WebDriverExpectedCondition(
14
            function ($driver) use ($selector, $by) {
15
                try {
16
                    $element = $driver->$by($selector);
17
                    return $element instanceof WebDriverElement;
18
                } catch (\Exception $e) {
19
                    // No need to do anything.  No element == exception.
20
                }
21
                return false;
22
            }
23
        );
24
    }
25
26
    public static function elementRemoved(WebDriverElement $element)
27
    {
28
        return new WebDriverExpectedCondition(
29
            function () use ($element) {
30
                try {
31
                    $element->isDisplayed();
32
                    return false;
33
                } catch (\Exception $e) {
34
                    return true;
35
                }
36
            }
37
        );
38
    }
39
40
}