Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

What's the best approach to populating test content in the repo for ui.tests?

Avatar

Level 2

Pretty much as the question states above.

 

My understanding is when the pipeline executes you get essentially vanilla instances of AEM author and publisher to test against. I can think of a few ways I could probably inject a content package of a barebones site to test against, but what's the recommended approach?

 

Can't see any mention of it in the docs.

 

Cheers in advance!

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 9

Hi @raininglemons ,

To populate test content in your AEM (Adobe Experience Manager) repository for UI tests, you need a strategy that ensures your tests have consistent and predictable content to interact with each time the pipeline runs. Here’s a recommended approach:

1. Using Content Packages

Content packages are a robust way to inject necessary content into AEM instances. This involves creating and deploying a content package that contains the test content, which gets installed on the AEM instances during the pipeline execution. Here’s how you can do it:

Steps:

  1. Create a Content Package:

    • Use AEM Package Manager or a tool like wcm.io Content Package Maven Plugin to create a content package.
    • This package should contain the essential pages, components, and configurations needed for your UI tests.
    • Ensure that the package is minimal and only includes what is necessary for testing to keep the instances lightweight.
  2. Automate Content Package Deployment:

    • In your CI/CD pipeline, include a step that deploys this content package to the AEM author and publisher instances.
    • Use cURL or AEM Package Manager's REST API to upload and install the package as part of your build process.
  3. Validation:

    • After deploying the content package, include a validation step to confirm that the content is installed correctly.

Example Using cURL:

curl -u admin:admin -F file=@your-content-package.zip http://localhost:4502/crx/packmgr/service.jsp?cmd=upload
curl -u admin:admin -F file=@your-content-package.zip http://localhost:4502/crx/packmgr/service.jsp?cmd=install

Example Using Maven:

<plugin>
    <groupId>com.day.jcr.vault</groupId>
    <artifactId>content-package-maven-plugin</artifactId>
    <version>1.0.2</version>
    <executions>
        <execution>
            <id>install-package</id>
            <phase>install</phase>
            <goals>
                <goal>install</goal>
            </goals>
            <configuration>
                <vaultFiles>
                    <vaultFile>${project.basedir}/target/your-content-package.zip</vaultFile>
                </vaultFiles>
            </configuration>
        </execution>
    </executions>
</plugin>

2. Using Repository Initializer

AEM Repository Initializer is a feature that allows you to define repository structure and content through OSGi configurations or files. This is typically more lightweight than a content package and can be easier to manage for simple setups.

Steps:

  1. Create an Initialization Script:

    • Write a repository initialization script (e.g., XML or JSON) that defines the content structure and nodes required for your tests.
  2. Deploy the Initialization Script:

    • Include the initialization script in your codebase and configure the repository initializer to execute this script on AEM startup.

Example Configuration:

<Configuration xmlns:rep="http://www.jcp.org/jcr/1.0">
    <repository>
        <node name="content" primaryType="nt:unstructured">
            <node name="my-test-page" primaryType="cq:Page">
                <!-- Define page content here -->
            </node>
        </node>
    </repository>
</Configuration>

3. Using Sling Content Loader

The Sling Content Loader allows for automatic loading of content from the filesystem into the JCR repository. It is suitable for simple, static content setups.

Steps:

  1. Organize Content Files:

    • Prepare your content files in a format Sling Content Loader can read (e.g., JSON or XML).
  2. Configure Sling Content Loader:

    • Add configurations in your project to tell Sling Content Loader where to find and how to load these files.

Example Configuration:

<content>
    <my-test-page jcr:primaryType="cq:Page">
        <!-- Define content here -->
    </my-test-page>
</content>

4. Using AEM Mocks for Unit Testing

For testing at a more granular level, AEM Mocks provided by tools like wcm.io AEM Mocks can be used for unit testing without the need for a full AEM instance. This is more suitable for unit tests rather than UI tests.

Recommendation:

For most UI test scenarios, content packages are the preferred method due to their flexibility and ease of deployment. They allow you to bundle any content and configurations needed, making them ideal for setting up a consistent testing environment.

Additional Considerations:

  • Keep Content Minimal: Include only the necessary content to reduce the size and complexity of your AEM instances.
  • Version Control: Store content packages and initialization scripts in version control to ensure they are consistent with your test cases.
  • Automation: Automate the deployment and validation process as part of your CI/CD pipeline to ensure a smooth and repeatable setup.

Resources:

Following these steps should give you a structured approach to populating test content in your AEM repository and ensure your UI tests have the necessary context to execute reliably.




View solution in original post

2 Replies

Avatar

Correct answer by
Level 9

Hi @raininglemons ,

To populate test content in your AEM (Adobe Experience Manager) repository for UI tests, you need a strategy that ensures your tests have consistent and predictable content to interact with each time the pipeline runs. Here’s a recommended approach:

1. Using Content Packages

Content packages are a robust way to inject necessary content into AEM instances. This involves creating and deploying a content package that contains the test content, which gets installed on the AEM instances during the pipeline execution. Here’s how you can do it:

Steps:

  1. Create a Content Package:

    • Use AEM Package Manager or a tool like wcm.io Content Package Maven Plugin to create a content package.
    • This package should contain the essential pages, components, and configurations needed for your UI tests.
    • Ensure that the package is minimal and only includes what is necessary for testing to keep the instances lightweight.
  2. Automate Content Package Deployment:

    • In your CI/CD pipeline, include a step that deploys this content package to the AEM author and publisher instances.
    • Use cURL or AEM Package Manager's REST API to upload and install the package as part of your build process.
  3. Validation:

    • After deploying the content package, include a validation step to confirm that the content is installed correctly.

Example Using cURL:

curl -u admin:admin -F file=@your-content-package.zip http://localhost:4502/crx/packmgr/service.jsp?cmd=upload
curl -u admin:admin -F file=@your-content-package.zip http://localhost:4502/crx/packmgr/service.jsp?cmd=install

Example Using Maven:

<plugin>
    <groupId>com.day.jcr.vault</groupId>
    <artifactId>content-package-maven-plugin</artifactId>
    <version>1.0.2</version>
    <executions>
        <execution>
            <id>install-package</id>
            <phase>install</phase>
            <goals>
                <goal>install</goal>
            </goals>
            <configuration>
                <vaultFiles>
                    <vaultFile>${project.basedir}/target/your-content-package.zip</vaultFile>
                </vaultFiles>
            </configuration>
        </execution>
    </executions>
</plugin>

2. Using Repository Initializer

AEM Repository Initializer is a feature that allows you to define repository structure and content through OSGi configurations or files. This is typically more lightweight than a content package and can be easier to manage for simple setups.

Steps:

  1. Create an Initialization Script:

    • Write a repository initialization script (e.g., XML or JSON) that defines the content structure and nodes required for your tests.
  2. Deploy the Initialization Script:

    • Include the initialization script in your codebase and configure the repository initializer to execute this script on AEM startup.

Example Configuration:

<Configuration xmlns:rep="http://www.jcp.org/jcr/1.0">
    <repository>
        <node name="content" primaryType="nt:unstructured">
            <node name="my-test-page" primaryType="cq:Page">
                <!-- Define page content here -->
            </node>
        </node>
    </repository>
</Configuration>

3. Using Sling Content Loader

The Sling Content Loader allows for automatic loading of content from the filesystem into the JCR repository. It is suitable for simple, static content setups.

Steps:

  1. Organize Content Files:

    • Prepare your content files in a format Sling Content Loader can read (e.g., JSON or XML).
  2. Configure Sling Content Loader:

    • Add configurations in your project to tell Sling Content Loader where to find and how to load these files.

Example Configuration:

<content>
    <my-test-page jcr:primaryType="cq:Page">
        <!-- Define content here -->
    </my-test-page>
</content>

4. Using AEM Mocks for Unit Testing

For testing at a more granular level, AEM Mocks provided by tools like wcm.io AEM Mocks can be used for unit testing without the need for a full AEM instance. This is more suitable for unit tests rather than UI tests.

Recommendation:

For most UI test scenarios, content packages are the preferred method due to their flexibility and ease of deployment. They allow you to bundle any content and configurations needed, making them ideal for setting up a consistent testing environment.

Additional Considerations:

  • Keep Content Minimal: Include only the necessary content to reduce the size and complexity of your AEM instances.
  • Version Control: Store content packages and initialization scripts in version control to ensure they are consistent with your test cases.
  • Automation: Automate the deployment and validation process as part of your CI/CD pipeline to ensure a smooth and repeatable setup.

Resources:

Following these steps should give you a structured approach to populating test content in your AEM repository and ensure your UI tests have the necessary context to execute reliably.