Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Component content

Mikołaj Mański edited this page Aug 1, 2016 · 2 revisions

Getting contents of a component

To test our components against multiple test cases we need to be able to get their inner content as HTML. Bobcat provides an easy way to do this. Take a look at this example test case:

//...
  private AuthorPage page;
//..
  @Test
  public void shouldContainEnteredText() {
    page.configureComponent(parsys, TEXT_COMP_NAME, "plain_text");
    String contents = page.getContent(TextComponent.class).getOuterHTML();
    assertThat(contents, containsString("<p>test test test</p>"));
  }

If you don't know how to get AuthorPage please refer to the Adding a new page tutorial.

The AuthorPage#getContent method returns instance of desired component class from a parsys defined in the pages.yml configuration file for this particular page. In this case the getOuterHTML method is invoked. You can find TextComponent class implementation below:

import com.cognifide.qa.bb.constants.HtmlTags;
import com.cognifide.qa.bb.qualifier.CurrentScope;
import com.cognifide.qa.bb.qualifier.PageObject;
import com.google.inject.Inject;

import org.openqa.selenium.WebElement;

@PageObject
public class TextComponent {
  //...
  @Inject
  @CurrentScope
  private WebElement component;

  public String getOuterHTML() {
    return component.getAttribute(HtmlTags.Properties.OUTER_HTML);
  }

  //...

}

Since the TextComponent is a PageObject - it's referring to the existing element in the DOM. This allows you to get HTML attributes from it like outerHTML as in this example. It returns markup of the component which can be put against any test case.

Notice

There is one important thing when using AuthorPage#getContent - it implicitly changes mode from Edit to Preview mode to be able to get it's markup and doesn't return to the Edit mode after that due to performance reasons. If you would want to test multiple components it is better to change the mode once, then return to the edit mode manually. Below you can find example snippet which is responsible for that:

import com.cognifide.qa.bb.aem.touch.pageobjects.touchui.GlobalBar;

//..
  @Inject
  private GlobalBar globalBar;
//...
  @After
  public void cleanUp() {
    globalBar.switchToEditMode();
    parsys = pages.getParsys(PAGE_TITLE);
    page.deleteComponent(parsys, TEXT_COMP_NAME);
  }

This method removes previously inserted component but at first it ensures that the actual mode is the Edit mode.

Getting started with Bobcat

  1. Getting started

AEM Related Features

  1. Authoring tutorial - Classic
  1. AEM Classic Authoring Advanced usage
  1. Authoring tutorial - Touch UI
Clone this wiki locally