May 2, 2020
Estimated Post Reading Time ~

Building Quality in AEM Applications — Automated Authoring Testing

Authoring is the process of content creation in Adobe Experience Manager (AEM). It allows content authors to make changes to content without a code release. A good AEM application should consist of components and pages that are easy to author for non-technical content authors. To ensure the AEM application meets the content authoring requirements, authoring testing is needed. Quality Assurance (QA) engineers usually prepare a set of test cases for authoring testing. Like any other type of testing, automation helps test cases run quickly and consistently across all environments, it saves the company a lot of operational costs. QA engineers don’t need to repeat tedious manual testing in different environments and different phases but can focus on writing and improving automation test suites. In this second post of Building Quality in the AEM Applications series, I am going to demonstrate automated authoring testing in AEM with Bobcat and Cucumber framework.

AEM Meets Bobcat and Cucumber

Bobcat
You probably heard of Hobbes.js for automated UI and authoring testing in AEM. It’s OOTB UI and authoring testing framework shipped with AEM. You can view and run Hobbes.js test cases by navigating to the testing console in AEM. If you want some references, AEM core components have implemented Hobbes.js authoring testing. For example, you can find a test suite for Title component here, and test cases here.

But what is Bobcat? Bobcat is an open source automated testing framework for web applications, built on top of Selenium, and it provides features and support for AEM authoring testing.

Cucumber and BDD
And what is Cucumber? Cucumber is an open source framework for Behaviour-Driven Development (BDD) that executes scenarios written in plain English and generates reports.

BDD is a development practice that fosters collaboration and communication among the agile team three amigos (BA/PO, developer and QA), records product requirements in behavioral specifications and automates tests.

With BDD and Cucumber framework, BA/PO can write requirements in the story in a format that can be reused directly in test cases. It improves application quality by having a thorough discussion of how the application should behave and having test cases in the requirement phase, even before development starts.

Bobcat vs. Hobbes.js
If you are choosing between Bobcat and Hobbes.js for automated AEM authoring testing, below is a side by side comparison.

Side by side comparison between Bobcat and Hobbes.js

Get Started with Bobcat and Cucumber
Since there is little public documentation on using Bobcat and Cucumber frameworks for AEM authoring testing, if you decide to go with or just try these two frameworks, I hope this blog can give you some guidance and code reference on how to them.

I am going to integrate Bobcat and Cucumber frameworks into my demo Blog repository, and I will write a simple BDD automated authoring test case for the title component with the latest Bobcat modules and APIs. All the codes are written and tested for AEM 6.4.

To start, Bobcat has built a Gradle template for AEM BDD, which includes the latest Bobcat core API, Cucumber, and AEM 6.4 specific codes. It creates necessary structures and wirings (although you’ll need to make some tweaks for Maven and older AEM versions, there’s separate documentation for older AEM versions here) for you. You can put them into the it.tests module in your AEM maven project. See below the anatomy of the generated code structures.

Anatomy of Bobcat AEM BDD code structures

Since the Bobcat framework is built on top of Selenium, You’ll also need to download and install a web driver of your choice (default is Chrome driver) for your test case to run.

Write Automated Authoring Test Case
After you’ve created a sample AEM BDD project from the template, you are ready to write your own automated authoring test case with Bobcat and Cucumber.

First, you’ll write or copy feature test cases in the Cucumber features folder. You define feature, rule, background, scenario, and steps, etc with Gherkin language. If you are use IntelliJ, there’re some plugins, like Gherkin and Cucumber for Java that help you write Cucumber BDD test cases as well.

Next, you will need to translate the scenarios and steps in your feature file into codes that can be run. This is the core of developing automated authoring tests. You will write logic and implementations for each step, a missing step implementation will lead to failure of the test case. You will also incorporate Bobcat and Selenium APIs in the step implementation. There’s a sample AEM authoring test tutorial in Bobcat documentation. Even though the tutorial is specific for Bobcat and JUnit, it should give you some insights on how to use the latest Bobcat modules and APIs.

You may notice the latest Bobcat core and AEM 6.4 modules have changed the framework architecture and support for AEM, as a lot of the previous Classic UI and Touch UI helper classes are deprecated and don’t work in AEM 6.4. One of the main differences is that it now encapsulates a lot of reusable classes and methods into AEM actions. These Bobcat AEM actions can be executed with or without data. And they can be extended or you can develop custom action for your use case. The other major change is the introduction of PageObject and PageObjectInterface, these are models for page and components, to encapsulate common logic and to be reused in different test cases.

You may also notice the current OOTB AEM actions don’t have strong support for the BDD framework yet, as they're only a few right now and not modular enough for a step implementation in BDD. So you can either develop your own action that can pass in modular parameters, or use Selenium APIs.

Lastly, you will need to write a test runner to trigger the BDD authoring test cases.

Run Automated Authoring Test Case
To run the automated authoring test cases, simply run mvn clean test.

If you don’t want to run those tests every build, you can create an integration test specific Maven profile.

Finally, let’s see what it looks like when it runs.

AEM BDD authoring test case run

Summary
As you are looking for automated AEM authoring test solutions, I recommend you review your use cases, business, development, and testing processes carefully with the pros and cons of the two frameworks.

I can definitely see the benefits of using Bobcat and Cucumber frameworks when your team can work together and adapt to the process changes, and you have the right people to design and set up the foundation for the frameworks to work and scale in your project. It’s a great concept and adds value to both business and technical teams.

At the same time, as I write this blog and went through all the documentation and APIs of Bobcat, I think there should be much better documentation on the APIs. I can also use more tutorials on how to use the framework with Cucumber in AEM. Also, given the 2.0.0 release was fairly recent and there is active development, I hope it will finalize on the AEM support model, provide more backward-compatible changes for easier migration and add more OOTB support for BDD use case soon.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.