-
Notifications
You must be signed in to change notification settings - Fork 40
Component content
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.
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.
- Configuring Bobcat
- Selenium enhancements
- Cucumber enhancements
- Traffic analyzer
- Email support
- Reporting
- Cloud integration
- Mobile integration
- Executing tests on different environments
- Working with multiple threads
- Tips and tricks
- Authoring tutorial - Classic
- AEM Classic Authoring Advanced usage
- Siteadmin
- Sidekick
- Aem Component
- Working with author pages
- Working with Publish pages
- Advanced component interactions
- Working with Context Menu
- Using Aem Content Tree
- Aem Content Finder
- Storing component configurations
- Working with packages
- Jcr Support
- Authoring tutorial - Touch UI
- Adding and editing a component
- Sites management tutorial