function SelectorsContext::selectTextInField in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.5
Same name and namespace in other branches
- 8.8 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::selectTextInField()
- 8.4 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::selectTextInField()
- 8.6 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::selectTextInField()
- 8.7 tests/features/bootstrap/SelectorsContext.php \SelectorsContext::selectTextInField()
- 9.0.x tests/features/bootstrap/SelectorsContext.php \SelectorsContext::selectTextInField()
#vardot : Select a part text in selected field input element.
Example #1: When I select "title name" text in "Title" field Example #2: And I select "some content" text in "Description" field.
@When /^(?:|I )select "(?P<selectedText>[^"]*)" text in "(?P<selectedField>[^"]*)" field$/
File
- tests/
features/ bootstrap/ SelectorsContext.php, line 351
Class
- SelectorsContext
- Defines application features from the specific context.
Code
function selectTextInField($selectedText, $selectedField) {
$field = $this
->getSession()
->getPage()
->findField($selectedField);
$fieldid = $field
->getAttribute('id');
// Get the value of the selected field.
$fieldValue = $field
->getValue();
// Have the $selectionStart.
$selectionStart = strpos($fieldValue, $selectedText);
if (empty($selectionStart)) {
throw new Exception(sprintf('We do not have "%s" in the "%s" field.', $selectedText, $selectedField));
}
// Have the selectionEnd.
$selectionEnd = $selectionStart + strlen($selectedText);
$this
->getSession()
->getDriver()
->evaluateScript('document.getElementById("' . $fieldid . '").setSelectionRange(' . $selectionStart . ',' . $selectionEnd . ');');
}