You are here

public function VarbaseContext::iShouldSeeValueInTheInputElement in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.7

Same name and namespace in other branches
  1. 8.8 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iShouldSeeValueInTheInputElement()
  2. 8.4 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iShouldSeeValueInTheInputElement()
  3. 8.5 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iShouldSeeValueInTheInputElement()
  4. 8.6 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iShouldSeeValueInTheInputElement()
  5. 9.0.x tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iShouldSeeValueInTheInputElement()

#varbase: To check if we do have a text in the input element.

Example 1: And I should see "your text" value in the "edit-items-2-target-id" input element Example 2: And I should see "Location property" value in the "edit-name" input element

@Then /^I should see "(?P<text>[^"]*)" value in the "(?P<selector>[^"]*)" input element$/

File

tests/features/bootstrap/VarbaseContext.php, line 911

Class

VarbaseContext
Defines application features from the specific context.

Code

public function iShouldSeeValueInTheInputElement($text, $selector) {
  $elements = $this
    ->getSession()
    ->getPage()
    ->findAll('xpath', "//input[@id='{$selector}']");
  if (empty($elements)) {
    throw new \Exception(sprintf('The input element "%s" was not found in the page', $selector));
  }
  $found = FALSE;
  foreach ($elements as $element) {
    $elementTextValue = $element
      ->getValue();
    $actual = preg_replace('/\\s+/u', ' ', $elementTextValue);
    $regex = "/" . preg_quote($text, '/') . "/";
    if (preg_match($regex, $actual)) {
      $found = TRUE;
      break;
    }
  }
  if (!$found) {
    throw new \Exception(sprintf('"%s" value was not found in the "%s" input element', $text, $selector));
  }
}