Automated testing of Adaptive Forms using Calvin SDK

Calvin SDK is a utility API for Adaptive Forms developers to test Adaptive Forms. Calvin SDK is built on top of the Hobbes.js testing framework. Calvin SDK is available with AEM Forms 6.3 onwards.

In this tutorial, you will create the following:

  • Test Suite
  • Test Suite will contain one or more test cases
  • Test Cases will contain one or more actions

Getting started

Import and install  the package using AEM package manager. The package contains sample scripts and several Adaptive Forms. The sample scripts demonstrate various Calvin SDK API's availble to test Adaptive Forms. The general steps for testing AEM Adaptive Forms are:

  • Navigate to the form that needs to be tested
  • Set field's value
  • Submit the Adaptive Form
  • Check for error messages

The sample scripts in the package demonstrate all the above actions.

Download

Let's explore the code of mortgageForm.js

var mortgageFormTS = new hobs.TestSuite("Mortgage Form Test", {
        path: '/etc/clientlibs/testingAFUsingCalvinSDK/mortgageForm.js',
        register: true
})	

The code above creates a new Test Suite.

  • The name of the TestSuite in this case is "Mortgage Form Test". 
  • We also provide the absolute path in AEM to the js file which contains the test suite.
  • The register parameter when set to true, makes the Test Suite available in the testing UI.
.addTestCase(new hobs.TestCase("Calculate amount to borrow")
        // navigate to the mortgage form  which is to be tested
        .navigateTo("/content/forms/af/cal/mortgageform.html?wcmmode=disabled")
		.asserts.isTrue(function () {
            return calvin.isFormLoaded()
        })

Test cases can be added to test suite that can be executed against a adaptive form. To add a test case to test suite, use the addTestCase method of TestSuite object. The addTestCase method takes an TestCase Object as a parameter. To create TestCase use the hobs.TestCase(..) method. The first parameter is the name of the Test Case that will appear in the UI.

Once you have created a test case you can then add actions to your test case. Actions like navigateTo, asserts.isTrue can be added as actions to the test case.

Running the automated tests

Point your browser to http://localhost:4502/libs/granite/testing/hobbes.html. Expand the Test Suite and run the tests. If everything successfull you will see the following:

calvinImage

Try out the sample test suites

As part of the sample package there are 3 additional test suites. You can try them out by including the appropriate files in the js.txt file of the clientlibrary as shown below:

#base=.

scriptingTest.js
validationTest.js
prefillTest.js
mortgageForm.js

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy