コンポーネントテストアクションを上書きする
自動テストフレームワーク (ATF) に固有の HTML 属性を使用して、特定のページコンポーネントのテストプロパティを変更します。
始める前に
このタスクについて
自動テストフレームワーク (ATF) がコンポーネントを取得するとき、それが設定可能なコンポーネントかクリック可能なコンポーネントかなど、サポートする対話式操作を決定します。コンポーネントが設定可能な場合、自動テストフレームワーク (ATF) は設定できるフィールドタイプを決定します。自動テストフレームワーク (ATF)がカスタムコンポーネントのアクションまたはフィールドタイプを誤って決定した場合、またはコンポーネントに 1 つのエンティティとして扱う必要がある複数の DOM 要素が含まれている場合は、自動テストフレームワーク (ATF)に固有の HTML 属性を使用して明示的に設定します。
sn-atf-clickable 属性と sn-atf-settable 属性の使用
sn-atf-clickable 属性と sn-atf-settable 属性を使用して、要素とその子要素をカスタムのクリック可能コンポーネントまたはカスタム設定可能なコンポーネントとして扱う必要があることを指定します。
始める前に
手順
例
//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>
sn-atf-class 属性の使用
カスタムのクリック可能または設定可能コンポーネントをテストするときに使用する JavaScript オブジェクトを指定するには、sn-atf-class 属性を使用します。カスタム JavaScript オブジェクトを書いて、カスタムコンポーネントに使用できるテストアクションを指定します。
始める前に
このタスクについて
sn-atf-class 属性を割り当てることで、カスタムコンポーネントに使用できるテストアクションを手動で指定できます。属性の値を、コンポーネントテストアクションを含む JavaScript オブジェクトの名前に設定します。テスト可能なカスタムコンポーネントはクリック可能か設定可能のいずれかである必要があります。この分類によって、JavaScript オブジェクトに必要な機能とプロパティが決まります。テスト可能なページコンポーネントの要件については、「カスタム UI テストステップ」を参照してください。手順
例
//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>
参照とレコードピッカー
カスタム UI ステップを使用して、sn-reference-picker および sn-record-picker 角度ディレクティブの値を操作します。参照ピッカーの値は、選択されたレコードの sys_id を返します。レコードピッカーの値は、そのレコードピッカーに対して選択された値フィールドを返します。値として設定するレコードを選択することで、両方の要素を設定できます。