Peržiūrite versijai skirtą žinyno turinį:
Adaptive forms are integral to your customer interactions. It is important to test your adaptive forms with every change you make in them, such as while rolling out a new fix pack or changing a rule in the form. However, functional testing adaptive forms and every field in them may be tedious.
Calvin allows you to automate testing of your adaptive forms in the web browser. Calvin utilizes Hobbes's user interface for running the tests and provides the following tools:
- A JavaScript API for creating tests.
- A user interface for running tests.
Using Calvin, you can create test cases in CRXDE and run UI tests directly in the web browser to thoroughly test your adaptive forms' following aspects:
Adaptive form aspect to test | Description |
Prefill experience of an Adaptive Form |
|
Submit experience of an adaptive form |
|
Expression Rules
|
|
Validations |
|
Lazy Loading
|
|
UI Interaction |
Before using this article to create your test cases, you need to know the following:
- Creating test suites and executing test cases using Hobbes
- Hobbes JavaScript APIs
- Calvin JavaScript APIs
The following example walks you through creation of a test suite for testing multiple adaptive forms. You need to create a separate test case for each form that you need to test. By following steps similar to the following ones and modifying the JavaScript code in step 11, you can create your own test suite to test your adaptive forms.
-
Specify the following property values in the newly created node (here afTestRegistration) and then click Save All. These properties help Hobbes recognize the folder as a test. To reuse this client library as a dependency in other client libraries, name it as granite.testing.calvin.tests.
Property Type Value categories
String[]
granite.testing.hobbes.tests, granite.testing.calvin.tests
dependencies
String[]
granite.testing.hobbes.testrunner, granite.testing.calvin, apps.testframework.all
Pastaba:
The granite.testing.calvin.af clientlib contains all the adaptive forms APIs. These APIs are part of the calvin namespace.
-
(function(window, hobs) { 'use strict'; window.testsuites = window.testsuites || {}; // Registering the test form suite to the sytem // If there are other forms, all registration should be done here window.testsuites.testForm = new hobs.TestSuite("Adaptive Form - Demo Test", { path: '/etc/clientlibs/afTestRegistration/init.js', register: true }); // window.testsuites.testForm1 = new hobs.TestSuite("testForm1"); }(window, window.hobs));
-
Property Type Value categories String[] granite.testing.hobbes.tests, granite.testing.hobbes.tests.testForm dependencies String[] granite.testing.calvin.tests Pastaba:
This example uses a dependency on the client lib granite.testing.calvin.tests for better management. This example also adds a client lib category, "granite.testing.hobbes.tests.testForm" to reuse this client lib, if necessary.
-
Right-click the folder you have created for the test form (here testForm) and select Create > Create File. Name the file scriptingTest.js and add the following code to the file and click Save All.
To use the following code to test another adaptive form, change the path and name of the form in navigateTo (lines 11, 36, and 62) and the respective test cases. For more information on APIs for testing different aspects of forms and form objects, see Calvin APIs.
(function(window, hobs) { 'use strict'; var ts = new hobs.TestSuite("Script Test", { path: '/etc/clientlibs/testForm/scriptingTest.js', register: false }) .addTestCase(new hobs.TestCase("Checking execution of calculate script") // navigate to the testForm which is to be tested .navigateTo("/content/forms/af/testForm.html?wcmmode=disabled") // check if adaptive form is loaded .asserts.isTrue(function () { return calvin.isFormLoaded() }) .execSyncFct(function () { // create a spy before checking for the expression calvin.spyOnExpression("panel1.textbox1"); // setValue would trigger enter, set the value and exit from the field calvin.setValueInDOM("panel1.textbox", "5"); }) // if the calculate expression was setting "textbox1" value to "5", let's also check that .asserts.isTrue(function () { return calvin.isExpressionExecuted("panel1.textbox1", "Calculate"); }) .execSyncFct(function () { calvin.destroySpyOnExpression("panel1.textbox1"); }) .asserts.isTrue(function () { return calvin.model("panel1.textbox1").value == "5" }) ) .addTestCase(new hobs.TestCase("Calculate script Test") // navigate to the testForm which is to be tested .navigateTo("/content/forms/af/cal/demoform.html?wcmmode=disabled&dataRef=crx:///content/forms/af/cal/prefill.xml") // check if adaptive form is loaded .asserts.isTrue(function () { return calvin.isFormLoaded() }) .execSyncFct(function () { // create a spy before checking for the expression calvin.spyOnExpression("panel2.panel1488218690733.downPayment"); // setValue would trigger enter, set the value and exit from the field calvin.setValueInDOM("panel2.panel1488218690733.priceProperty", "1000000"); }) .asserts.isTrue(function () { return calvin.isExpressionExecuted("panel2.panel1488218690733.downPayment", "Calculate"); }) .execSyncFct(function () { calvin.destroySpyOnExpression("panel2.panel1488218690733.downPayment"); }) .asserts.isTrue(function () { // if the calculate expression was setting "downPayment" value to "10000", let's also check that return calvin.model("panel2.panel1488218690733.downPayment").value == 10000 }) ) .addTestCase(new hobs.TestCase("Checking execution of Value commit script") // navigate to the testForm which is to be tested .navigateTo("/content/forms/af/cal/demoform.html?wcmmode=disabled&dataRef=crx:///content/forms/af/cal/prefill.xml") // check if adaptive form is loaded .asserts.isTrue(function () { return calvin.isFormLoaded() }) .execSyncFct(function () { // create a spy before checking for the expression calvin.spyOnExpression("panel2.panel1488218690733.priceProperty"); // setValue would trigger enter, set the value and exit from the field calvin.setValueInDOM("panel2.panel1488218690733.priceProperty", "100"); }) .asserts.isTrue(function () { return calvin.isExpressionExecuted("panel2.panel1488218690733.priceProperty", "Value Commit"); }) .execSyncFct(function () { calvin.destroySpyOnExpression("panel2.panel1488218690733.priceProperty"); }) .asserts.isTrue(function () { // if the value commit expression was setting "textbox1488215618594" value to "0", let's also check that return calvin.model("panel2.panel1488218690733.textbox1488215618594").value == 0 }) ); // register the test suite with testForm window.testsuites.testForm.add(ts); }(window, window.hobs));
The test case is created. Proceed to run the test case to test adaptive forms through Hobbes. For steps for running the test cases, see Executing Tests in Testing Your UI Using Automated Tests.
Atsisiųsti
Tests Suites can be run individually. When you run a Test Suite, the page changes as the Test Cases and their Actions are executed and the results appear after completion of the test. Icons indicate the results.
A checkmark icon indicates a passed test:
An "X" icon indicates a failed test:
To run a Test Suite:
The steps for testing your AEM adaptive forms are similar to steps for testing your AEM UI. For more information on testing your adaptive forms, see the following topics in Testing Your UI:
- Viewing Test Suites
- Running Multiple Tests
Term | Description |
Test suite |
A test suite is a collection of related test cases. |
Test case |
A test case represents a task that a user performs using your UI. Add test cases to your test suite to test the activities that users perform. |
Actions |
Actions are methods that perform a gesture in the UI, such as clicking a button or filling an input box with a value. The methods of the hobs.actions.Asserts, hobs.actions.Core and hobs.utils.af classes are actions that you can use in your tests. All actions execute synchronously. |
Author or publish environment |
In general, forms can either be tested in author or publish environment. In case of publish environment, by default, the access to execute the test is restricted. This is because all the client libraries related to test runner lies inside the /libs in the JCR structure. |