Override component test actions
Change the testing properties of a particular page component using HTML attributes that are specific to Automated Test Framework.
Avant de commencer
Pourquoi et quand exécuter cette tâche
When Automated Test Framework retrieves a component, it determines which interactions it supports, such as whether it is a settable or clickable component. If the component is settable, Automated Test Framework determines the field type that can be set. If Automated Test Framework incorrectly determines your custom component's actions or field types, or your component contains multiple DOM elements that should be treated as one entity, explicitly set them using HTML attributes that are specific to Automated Test Framework.
Using sn-atf-clickable and sn-atf-settable attributes
Use sn-atf-clickable and sn-atf-settable attributes
to specify that an element and its child elements should be treated as a custom clickable or
custom settable component.
Avant de commencer
Procédure
Exemple
//A custom clickable component
<div sn-atf-clickable="true" sn-atf-disabled id="customClickable">
<button id="customButton">Click me</button>
</div>
<script>
var customClickableDiv = document.getElementById("customClickable");
customClickableDiv.addEventListener('sn-atf-click', function() {
document.getElementById('customButton').click();
});
</script>
//A custom settable component
<div sn-atf-settable="true" id="customSettable" sn-atf-component-value="A default value">
<input id="customInput" value="A default value"></input>
</div>
<script>
var customSettableDiv = document.getElementById("customSettable");
customSettableDiv.addEventListener('sn-atf-setvalue', function(event) {
var newValue = event.detail.newValue;
document.getElementById("customInput").value = newValue;
});
</script>
Using sn-atf-class attribute
Use the sn-atf-class attribute to specify the JavaScript object to
use when testing a custom clickable or settable component. Write a custom JavaScript object
to specify the test actions available for a custom component.
Avant de commencer
Pourquoi et quand exécuter cette tâche
sn-atf-class attribute. Set the value of the attribute to
the name of the JavaScript object containing the component test actions. Testable custom
components must be either clickable or settable, and this classification determines the
functions and properties your JavaScript object requires. See Custom UI test steps for testable page component
requirements.Procédure
Exemple
//A custom clickable component
<form>
<div sn-atf-class="MyClickableComponent">
<label for="a_clickable_checkbox">MyClickableComponent</label>
<input type="checkbox" id="a_clickable_checkbox" checked="true"/>
</div>
</form>
<script>
var MyClickableComponent = {
// The constructor must have this signature, but you can perform additional setup after the $super(element, area) call
initialize: function($super, element, area) {
$super(element, area);
},
click: function() {
document.getElementById('a_clickable_checkbox').click();
return {success: true};
},
// The function returns an object with a result attribute of type String
getValue: function() {
var isChecked = document.getElementById('a_clickable_checkbox').checked ? "true" : "false";
return {success: true, result: isChecked};
},
// The function returns an object with a result attribute of type Boolean
isDisabled: function() {
if (document.getElementById('a_clickable_checkbox').disabled)
return {success: true, result: true};
return {success: true, result: false};
},
};
</script>
//A custom settable component
<form>
<div sn-atf-class="MySettableComponent">
<label for="a_settable_checkbox">MySettableComponent</label>
<input type="checkbox" id="a_settable_checkbox" checked="true"/>
</div>
</form>
<script>
var MySettableComponent = {
// This attribute is required for settable components
isSettable: true,
// The constructor must have this signature, but you can perform additional setup after the $super(element, area) call
initialize: function($super, element, area) {
$super(element, area);
},
// The value parameter is a string
setValue: function(value) {
document.getElementById('a_settable_checkbox').checked = (value == "true");
return {success: true};
},
// The function returns an object with a result attribute of type String
getValue: function() {
var isChecked = document.getElementById('a_settable_checkbox').checked ? "true" : "false";
return {success: true, result: isChecked};
},
// The function returns an object with a result attribute of type Boolean
isDisabled: function() {
if (document.getElementById('a_settable_checkbox').disabled)
return {success: true, result: true};
return {success: true, result: false};
},
};
</script>
Reference and record picker
Use custom UI steps to manipulate the values of the
sn-reference-picker and sn-record-picker angular directives.
The value on a reference picker returns the sys_id of the chosen record. The
value on a record picker returns the value field chosen for that record picker. Both elements
can be set by selecting a record to set as their value.