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

AEM Create Page

Mikołaj Mański edited this page Jul 26, 2016 · 1 revision

Create Page In AEM

Bobcat provides simple way to login into AEM and create a page

Description

@Inject
private SiteAdminPage page;

@Inject
private AemLogin aemLogin;

Using GUICE we inject SiteAdminPage which represents siteadmin page in AEM. Second object is AemLogin resposible for login into instance

@Before
public void openSiteadminPage() {
  aemLogin.authorLogin();
  page.open(BASE_PARENT_URL);
}

Before test starts we have to login into AEM (AemLogin.authorLogin() uses properties defined in instances.properties) and open siteadmin. URL in open method allows to define on which level siteadmin will be opened

if (!page.isPagePresent(CREATED_PAGE_TITLE)) {
  page.createNewPage(CREATED_PAGE_TITLE, CREATE_PAGE_TEMPLATE);
}

First we check if page we want to create already exist. Then we create new page, first argument is page title, second name of template we want to use

if (page.isPagePresent(pageTitle)) {
  page.deletePage(pageTitle);
}

To cleanup after test we just delete created page if it exists

Test Example

This is a simple test which logins into author instance, creates page and cleans after it is finished

package com.cognifide.bobcat.examples;

import static org.junit.Assert.assertTrue;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.cognifide.qa.bb.aem.AemLogin;
import com.cognifide.qa.bb.aem.ui.wcm.SiteAdminPage;
import com.cognifide.qa.bb.junit.Modules;
import com.cognifide.qa.bb.junit.TestRunner;
import com.google.inject.Inject;

@RunWith(TestRunner.class)
@Modules(GuiceModule.class)
public class CreatePageTest {

  private static final String CREATE_PAGE_TEMPLATE = "Media Article";

  private static final String BASE_PARENT_URL = "/content/geometrixx-media/en/entertainment";

  private static final String CREATED_PAGE_TITLE = "What is bobcat";

  @Inject
  private SiteAdminPage page;

  @Inject
  private AemLogin aemLogin;

  @Before
  public void openSiteadminPage() {
    aemLogin.authorLogin();
    page.open(BASE_PARENT_URL);
  }

  @Test
  public void createPage() {
    if (!page.isPagePresent(CREATED_PAGE_TITLE)) {
      page.createNewPage(CREATED_PAGE_TITLE, CREATE_PAGE_TEMPLATE);
    }
    assertTrue(page.isPagePresent(CREATED_PAGE_TITLE));
    assertTrue(page.isTemplateOnTheList(CREATED_PAGE_TITLE, CREATE_PAGE_TEMPLATE));
  }

  @After
  public void cleanUp() {
    removePage(BASE_PARENT_URL, CREATED_PAGE_TITLE);
  }

  private void removePage(String parentPath, String pageTitle) {
    page.open(parentPath);
    if (page.isPagePresent(pageTitle)) {
      page.deletePage(pageTitle);
    }
  }
}

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