You are here

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

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

#varbase : To Find an image with the title text attribute under a custom iframe.

Example 1: Then I should see image with the "Flag Earth" title text in the rich text editor field "Body"

@Then /^I should see image with the "([^"]*)" title text in the rich text editor field "([^"]*)"$/

File

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

Class

VarbaseContext
Defines application features from the specific context.

Code

public function iShouldSeeImageWithTheTitleTextInTheRichTextEditorField($titleText, $locator) {
  $el = $this
    ->getSession()
    ->getPage()
    ->findField($locator);
  $fieldId = $el
    ->getAttribute('id');
  if (empty($fieldId)) {
    throw new Exception('Could not find an id for the rich text editor field : ' . $locator);
  }
  $CKEditorContent = $this
    ->getSession()
    ->executeScript("return CKEDITOR.instances[\"{$fieldId}\"].getData();");

  // Switch to the iframe.
  $iFreamID = $this
    ->_getAttributeByOtherAttributeValue('id', 'title', $filedName, 'iframe');
  $this
    ->getSession()
    ->switchToIFrame($iFreamID);

  // Find an image with the title.
  $element = $this
    ->getSession()
    ->getPage()
    ->findAll('xpath', "//img[contains(@title, '{$titleText}')]");
  if (empty($element)) {
    throw new Exception('The page dose not have an image with the [ ' . $titleText . ' ] title text under [ ' . $filedName . ' ].');
  }

  // Switch back too the page from the iframe.
  $this
    ->getSession()
    ->switchToIFrame(null);
}