Code Duplication    Length = 15-15 lines in 2 locations

src/DrupalExtension/Context/VisibilityContext.php 2 locations

@@ 80-94 (lines=15) @@
77
   * @throws \Behat\Mink\Exception\ExpectationException
78
   *    Throws exception if element not found.
79
   */
80
  protected function assertElementVisible($element, NodeElement $node) {
81
    try {
82
      if ($node && !$node->isVisible()) {
83
        throw new ExpectationException(sprintf("The element '%s' is not present on the page %s", $element, $this->getSession()->getCurrentUrl()), $this->getSession());
84
      }
85
    }
86
    catch (UnsupportedDriverActionException $e) {
87
      // We catch the UnsupportedDriverActionException exception in case
88
      // this step is not being performed by a driver that supports javascript.
89
      // All other exceptions are valid.
90
      if (empty($node)) {
91
        throw new ExpectationException(sprintf("The element '%s' is not present on the page %s", $element, $this->getSession()->getCurrentUrl()), $this->getSession());
92
      }
93
    }
94
  }
95
96
  /**
97
   * Assert non visibility of an element.
@@ 107-121 (lines=15) @@
104
   * @throws \Behat\Mink\Exception\ExpectationException
105
   *    Throws exception if element is found.
106
   */
107
  protected function assertElementNotVisible($element, NodeElement $node) {
108
    try {
109
      if ($node && $node->isVisible()) {
110
        throw new ExpectationException(sprintf("The field '%s' was present on the page %s and was not supposed to be", $element, $this->getSession()->getCurrentUrl()), $this->getSession());
111
      }
112
    }
113
    catch (UnsupportedDriverActionException $e) {
114
      // We catch the UnsupportedDriverActionException exception in case
115
      // this step is not being performed by a driver that supports javascript.
116
      // All other exceptions are valid.
117
      if ($node) {
118
        throw new ExpectationException(sprintf("The field '%s' was present on the page %s and was not supposed to be", $element, $this->getSession()->getCurrentUrl()), $this->getSession());
119
      }
120
    }
121
  }
122
123
}
124