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

Activate and Deactivate Page in AEM

Mikołaj Mański edited this page Jul 8, 2016 · 4 revisions

Activate and Deactivate Page in AEM

Basics

In order to have something to activate and deactivate we need to create a page. At first we have to inject our Site Admin Page which will be used to create, activate and deactivate the page and AEM Login to get logged in.

  @Inject
  private AemLogin aemLogin;

  @Inject
  private SiteAdminPage siteAdminPage;

Now - let's create a method which will be creating our page:

  private static final String CREATED_PAGE_TITLE = "What is bobcat";
  private static final String CREATE_PAGE_TEMPLATE = "Media Article";
...
 private void createPage() {
    if (!siteAdminPage.isPagePresent(CREATED_PAGE_TITLE)) {
      siteAdminPage.createNewPage(CREATED_PAGE_TITLE, CREATE_PAGE_TEMPLATE);
    }
    assertTrue(siteAdminPage.isPagePresent(CREATED_PAGE_TITLE));
    assertTrue(siteAdminPage.isTemplateOnTheList(CREATED_PAGE_TITLE, CREATE_PAGE_TEMPLATE));
    reportEntryLogger.info("test page created");
  }

This method will use the Site Admin page to create our test page if it doesn't already exist . But wait - how to open the Site Admin page? We can use @Before annotation:

  private static final String BASE_PARENT_URL = "/content/geometrixx-media/en/entertainment";
  ...
  @Before
  public void openSiteadminPage() {
    aemLogin.authorLogin();
    siteAdminPage.open(BASE_PARENT_URL);
  }

This tells Bobcat that before each test it should login to the AEM with author credentials and open some base page in the site admin page's context.

Please bear in mind that your test suite should left the environment intact after testing. So - when we are creating a test page for testing we should delete it after test. @After annotation can be useful here:

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

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

Page activation and deactivation

When the test page is not present, method createNewPage will create a page of name CREATED_PAGE_TITLE from CREATE_PAGE_TEMPLATE page template. Now we can start implementing our test cases. Let's start from basic activation and deactivation:

  @Test
  public void shouldActivateAndDeactivatePageProperly() {
    SiteAdminGridRow createdPageGridRow;
    createPage();

    siteAdminPage.activatePage(CREATED_PAGE_TITLE);
    createdPageGridRow = siteAdminPage.getGrid().selectPageByTitle(CREATED_PAGE_TITLE);
    assertThat(createdPageGridRow.getActivationStatus(), is(ActivationStatus.ACTIVATED));

    siteAdminPage.deactivatePage(CREATED_PAGE_TITLE);
    createdPageGridRow = siteAdminPage.getGrid().selectPageByTitle(CREATED_PAGE_TITLE);
    assertThat(createdPageGridRow.getActivationStatus(), is(ActivationStatus.DEACTIVATED));
  }

Now let's take a closer look at this method step by step:

   SiteAdminGridRow createdPageGridRow;
   createPage();

At first we are defining our SiteAdminGridRow variable which will be used to manage Site Admin data, it will be described more clearly in a second. After that we are creating our test page using a method that we know well already.

  siteAdminPage.activatePage(CREATED_PAGE_TITLE);
  createdPageGridRow = siteAdminPage.getGrid().selectPageByTitle(CREATED_PAGE_TITLE);
  assertThat(createdPageGridRow.getActivationStatus(), is(ActivationStatus.ACTIVATED));

First method is obvious - we are activating the created page using Site Admin Page. On the second line we are initializng the createdPageGridRow by obtaining Site Admin's grid and selecting the test page we created before. The last step is just comparing the expected activation status with the actual status in the Site Admin Page Grid Row.

But what is this grid row actually?

It should be well described by this picture:

SiteAdminGridRow of example page

The SiteAdminGridRow is marked by black rectangle - it contains lots of information, including activation and deactivation status which is obtained by getActivationStatus() method. The test case with deactivating a page looks similar and should be obvious now.

Scheduling page activation and deactivation

Now let's test a case in which we will be scheduling page activation and deactivation to some time in the future. Scheduling activation:

  @Test
  public void shouldActivatePageLater() {
    createPage();
    siteAdminPage.activatePageLater(CREATED_PAGE_TITLE, "21/06/16", "10:12 AM");
    SiteAdminGridRow createdPageGridRow = siteAdminPage.getGrid().selectPageByTitle(CREATED_PAGE_TITLE);
    assertThat(createdPageGridRow.getPageStatusToolTip(),
        containsString(PageStatus.SCHEDULED_ACTIVATION.getStatusCss()));
  }

Let's take a closer look at this method:

siteAdminPage.activatePageLater(CREATED_PAGE_TITLE, "21/06/16", "10:12 AM"); This line is scheduling page activation by clicking Activate Later button and providing date and time as shown at the following image:

SiteAdminGridRow of example page

The last line is checking whether the Page Status Tooltip contains proper information by hovering a mouse cursor on it as shown at the image below:

Scheduled Activation Status

The test case for scheduling page deactviation looks similar:

  @Test
  public void shouldDeactivatePageLater() {
    createPage();
    siteAdminPage.deactivatePageLater(CREATED_PAGE_TITLE, "21/06/16", "10:12 AM");
    SiteAdminGridRow createdPageGridRow = siteAdminPage.getGrid().selectPageByTitle(CREATED_PAGE_TITLE);
    assertThat(createdPageGridRow.getPageStatusToolTip(),
            containsString(PageStatus.SCHEDULED_DEACTIVATION.getStatusCss()));
  }

Final code

This concludes the page activation and deactivation tutorial. The complete code can be found below:

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

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

import com.cognifide.qa.bb.aem.ui.wcm.constants.PageStatus;
import com.cognifide.bdd.demo.GuiceModule;
import com.cognifide.qa.bb.aem.AemLogin;
import com.cognifide.qa.bb.aem.ui.wcm.SiteAdminPage;
import com.cognifide.qa.bb.aem.ui.wcm.constants.ActivationStatus;
import com.cognifide.qa.bb.aem.ui.wcm.elements.SiteAdminGridRow;
import com.cognifide.qa.bb.junit.Modules;
import com.cognifide.qa.bb.junit.TestRunner;
import com.cognifide.qa.bb.logging.ReportEntryLogger;
import com.google.inject.Inject;


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

  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 AemLogin aemLogin;

  @Inject
  private SiteAdminPage siteAdminPage;

  @Inject
  private ReportEntryLogger reportEntryLogger;

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

  @Test
  public void shouldActivateAndDeactivatePageProperly() {
    SiteAdminGridRow createdPageGridRow;
    createPage();

    siteAdminPage.activatePage(CREATED_PAGE_TITLE);
    createdPageGridRow = siteAdminPage.getGrid().selectPageByTitle(CREATED_PAGE_TITLE);
    assertThat(createdPageGridRow.getActivationStatus(), is(ActivationStatus.ACTIVATED));

    siteAdminPage.deactivatePage(CREATED_PAGE_TITLE);
    createdPageGridRow = siteAdminPage.getGrid().selectPageByTitle(CREATED_PAGE_TITLE);
    assertThat(createdPageGridRow.getActivationStatus(), is(ActivationStatus.DEACTIVATED));
  }

  @Test
  public void shouldActivatePageLater() {
    createPage();
    siteAdminPage.activatePageLater(CREATED_PAGE_TITLE, "21/06/16", "10:12 AM");
    SiteAdminGridRow createdPageGridRow = siteAdminPage.getGrid().selectPageByTitle(CREATED_PAGE_TITLE);
    assertThat(createdPageGridRow.getPageStatusToolTip(),
        containsString(PageStatus.SCHEDULED_ACTIVATION.getStatusCss()));
  }

  @Test
  public void shouldDeactivatePageLater() {
    createPage();
    siteAdminPage.deactivatePageLater(CREATED_PAGE_TITLE, "21/06/16", "10:12 AM");
    SiteAdminGridRow createdPageGridRow = siteAdminPage.getGrid().selectPageByTitle(CREATED_PAGE_TITLE);
    assertThat(createdPageGridRow.getPageStatusToolTip(),
            containsString(PageStatus.SCHEDULED_DEACTIVATION.getStatusCss()));
  }

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

  private void createPage() {
    if (!siteAdminPage.isPagePresent(CREATED_PAGE_TITLE)) {
      siteAdminPage.createNewPage(CREATED_PAGE_TITLE, CREATE_PAGE_TEMPLATE);
    }
    assertTrue(siteAdminPage.isPagePresent(CREATED_PAGE_TITLE));
    assertTrue(siteAdminPage.isTemplateOnTheList(CREATED_PAGE_TITLE, CREATE_PAGE_TEMPLATE));
    reportEntryLogger.info("test page created");
  }


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

}

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