Code Duplication    Length = 18-20 lines in 2 locations

lib/Assertions/Element/Clickable.php 1 location

@@ 10-27 (lines=18) @@
7
use Magium\InvalidTestTypeException;
8
use Magium\WebDriver\ExpectedCondition;
9
10
class Clickable extends AbstractSelectorAssertion
11
{
12
13
    const ASSERTION = 'Element\Clickable';
14
15
    public function assert()
16
    {
17
        $by = $this->getTestCase()->filterWebDriverAction($this->by);
18
        try {
19
            $this->webDriver->wait(1)->until(ExpectedCondition::elementToBeClickable(WebDriverBy::$by($this->selector)));
20
            // Protects against warnings that the test had no assertions.
21
            AbstractTestCase::assertTrue(true);
22
        } catch (\Exception $e) {
23
            $this->getTestCase()->fail(sprintf('The element %s, located with %s, cannot be clicked', $this->selector, $by));
24
        }
25
    }
26
27
}
28

lib/Assertions/Element/NotClickable.php 1 location

@@ 10-29 (lines=20) @@
7
use Magium\InvalidTestTypeException;
8
use Magium\WebDriver\ExpectedCondition;
9
10
class NotClickable extends AbstractSelectorAssertion
11
{
12
13
    const ASSERTION = 'Element\NotClickable';
14
15
    public function assert()
16
    {
17
        $by = $this->getTestCase()->filterWebDriverAction($this->by);
18
        try {
19
            $this->webDriver->wait(1)->until(ExpectedCondition::elementToBeClickable(WebDriverBy::$by($this->selector)));
20
            $this->getTestCase()->fail(sprintf('The element %s, located with %s, is clickable but should not be', $this->selector, $by));
21
        } catch (\Exception $e) {
22
            // A failure is what we are hoping for.  It indicates that the element is not clickable, just like what the class wants
23
24
            // Protects against warnings that the test had no assertions.
25
            AbstractTestCase::assertTrue(true);
26
        }
27
    }
28
29
}
30