Code Duplication    Length = 17-17 lines in 2 locations

src/DrupalExtension/Context/VisibilityContext.php 2 locations

@@ 19-35 (lines=17) @@
16
   *
17
   * @Then I should see the field :field
18
   */
19
  public function iShouldSeeTheField($field) {
20
    $element = $this->getSession()->getPage();
21
    $result = $element->findField($field);
22
    try {
23
      if ($result && !$result->isVisible()) {
24
        throw new \Exception(sprintf("No field '%s' on the page %s", $field, $this->getSession()->getCurrentUrl()));
25
      }
26
    }
27
    catch (UnsupportedDriverActionException $e) {
28
      // We catch the UnsupportedDriverActionException exception in case
29
      // this step is not being performed by a driver that supports javascript.
30
      // All other exceptions are valid.
31
    }
32
    if (empty($result)) {
33
      throw new \Exception(sprintf("No field '%s' on the page %s", $field, $this->getSession()->getCurrentUrl()));
34
    }
35
  }
36
37
  /**
38
   * Assert absence of given field.
@@ 42-58 (lines=17) @@
39
   *
40
   * @Then I should not see the field :field
41
   */
42
  public function iShouldNotSeeTheField($field) {
43
    $element = $this->getSession()->getPage();
44
    $result = $element->findField($field);
45
    try {
46
      if ($result && $result->isVisible()) {
47
        throw new \Exception(sprintf("The field '%s' was present on the page %s and was not supposed to be", $field, $this->getSession()->getCurrentUrl()));
48
      }
49
    }
50
    catch (UnsupportedDriverActionException $e) {
51
      // We catch the UnsupportedDriverActionException exception in case
52
      // this step is not being performed by a driver that supports javascript.
53
      // All other exceptions are valid.
54
      if ($result) {
55
        throw new \Exception(sprintf("The field '%s' was present on the page %s and was not supposed to be", $field, $this->getSession()->getCurrentUrl()));
56
      }
57
    }
58
  }
59
60
}
61