---
sourceDocument: ブラジル アプリケーションのビルドまたは変更
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/ja-JP/application-development

 Release :

    - brazil

ft:locale :

    - ja-JP

ft:publication_title :

    - ブラジル アプリケーションのビルドまたは変更

ft:clusterId :

    - cadev

bundleId :

    - cadev

workflow :

    - Development, Data, and Analytics


---

# コンポーネントテストアクションを上書きする

# コンポーネントテストアクションを上書きする {#ariaid-title1}

リリースバージョン: Brazil  
更新日 2026年09月10日  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 所要時間：13分  
自動テストフレームワーク (ATF) 固有の HTML 属性を使用して、特定のページコンポーネントのテストプロパティを変更します。

## 始める前に

必要なロール：アドミン

## このタスクについて

自動テストフレームワーク (ATF) がコンポーネントを取得するとき、それが設定可能なコンポーネントかクリック可能なコンポーネントかなど、サポートする対話式操作を決定します。コンポーネントが設定可能な場合、自動テストフレームワーク (ATF) は設定できるフィールドタイプを決定します。自動テストフレームワーク (ATF) がカスタムコンポーネントのアクションまたはフィールドタイプを誤って決定する場合、またはコンポーネントに 1 つのエンティティとして扱う必要がある複数の DOM 要素が含まれている場合は、自動テストフレームワーク (ATF) 固有の HTML 属性を使用してそれらを明示的に設定します。

## sn-atf-clickable 属性と sn-atf-settable 属性の使用 {#ariaid-title2}

`sn-atf-clickable` 属性と `sn-atf-settable` 属性を使用して、要素とその子要素をカスタムのクリック可能コンポーネントまたはカスタム設定可能なコンポーネントとして扱う必要があることを指定します。

### 始める前に

必要なロール：アドミン

### 手順

1. テストするカスタム UI ページを開きます。
2. `sn-atf-clickable` または `sn-atf-settable` 属性をテスト対象の要素に追加します。  

       <div sn-atf-clickable="true" sn-atf-disabled id="customClickable">
       	<button id="customButton">Click me</button>
       </div>

       <div sn-atf-settable="true" id="customSettable" sn-atf-component-value="A default value">
       	<input id="customInput" value="A default value"></input>
       </div>

   注:  
   `sn-atf-clickable` 属性または `sn-atf-settable` 属性のいずれかを使用して、要素をカスタムのクリック可能コンポーネントまたはカスタム設定可能なコンポーネントとして扱う必要があるかどうかを指定します。同じ要素で両方の属性を使用することはできません。
3. `sn-atf-clickable` 属性または `sn-atf-settable` 属性のいずれかを使用します。  
   * `sn-atf-clickable`： `sn-atf-clickable` 属性を追加した場合、ATF は `sn-atf-clickable` 属性を持つ DOM 要素に `sn-atf-click` イベントを送信することによってコンポーネントをクリックします。この DOM 要素にイベントリスナーを追加し (たとえば、`addEventListener` を使用)、コンポーネントのカスタムクリックロジックを実装する必要があります。[\[コンポーネントをクリック\]](Z78TaIKcJZU41d3LubmLYw#atf-click-component "カスタム UI ページ上のコンポーネントをクリックします。") テストステップを使用して、クリック可能なカスタムコンポーネントを操作できます。 {#atf-override-component-class-02__table_r5q_gry_cgb__entry__2}

     | 属性の名前 | 説明 |
     |-|-|
     | sn-atf-disabled | このオプションの属性が存在すると、(その値に関係なく) このコンポーネントが無効であることを ATF が認識します 注: この属性が指定されていない場合、ATF はこのコンポーネントがデフォルトで有効になっていると見なします。 |
     | sn-atf-component-value | このコンポーネントの現在の値を ATF に通知する文字列または JSON オブジェクト |
     [表 : 1. クリック可能なコンポーネント属性]

     {#atf-override-component-class-02__table_r5q_gry_cgb}
   * `sn-atf-settable`： `sn-atf-settable` 属性を追加した場合、ATF は `sn-atf-settable` 属性を持つ DOM 要素に `sn-atf-setvalue` イベントを送信することによってコンポーネント値を設定します。この DOM 要素にイベントリスナーを追加し (たとえば、`addEventListener` を使用)、コンポーネントのカスタム設定値ロジックを実装する必要があります。設定する必要がある値には、`event.detail.newvalue` を使用してアクセスできます。`イベント`引数がイベントハンドラーに渡されます。[\[コンポーネント値の設定\]](Z78TaIKcJZU41d3LubmLYw#atf-set-component-values "カスタム UI ページにコンポーネント値を設定します。") テストステップを使用して、設定可能なカスタムコンポーネントを操作できます。 {#atf-override-component-class-02__table_kml_csy_cgb__entry__2}

     | 属性の名前 | 説明 |
     |-|-|
     | sn-atf-disabled | このオプションの属性の存在は (値に関係なく)、このコンポーネントが無効であることを ATF に通知します。 注: この属性が指定されていない場合、ATF はこのコンポーネントがデフォルトで有効になっていると見なします。 |
     | sn-atf-component-value | このコンポーネントの現在の値を ATF に通知する文字列または JSON オブジェクト。 |
     | sn-atf-data-type | ステップをビルドするときにユーザーに表示するオプションのフィールドタイプ。デフォルトは文字列です。たとえば、`glide_date_time`、reference、boolean などです。 |
     | sn-atf-data-type-params | データタイプの詳細を含む JSON オブジェクト。 |
     [表 : 2. 設定可能なコンポーネント属性]

     {#atf-override-component-class-02__table_kml_csy_cgb}
   {#atf-override-component-class-02__ul_xst_3rq_slb}
{#atf-override-component-class-02__steps_jyp_gkz_1gb}

### 例

    //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 属性の使用 {#ariaid-title3}

カスタムのクリック可能または設定可能コンポーネントをテストするときに使用する JavaScript オブジェクトを指定するには、`sn-atf-class` 属性を使用します。カスタム JavaScript オブジェクトを書いて、カスタムコンポーネントに使用できるテストアクションを指定します。

### 始める前に

必要なロール：アドミン

### このタスクについて

テスト設計者は、カスタムの JavaScript オブジェクトを書き、コンポーネントに `sn-atf-class` 属性を割り当てることで、カスタムコンポーネントに使用できるテストアクションを手動で指定できます。属性の値を、コンポーネントテストアクションを含む JavaScript オブジェクトの名前に設定します。テスト可能なカスタムコンポーネントはクリック可能か設定可能のいずれかである必要があります。この分類によって、JavaScript オブジェクトに必要な機能とプロパティが決まります。テスト可能なページコンポーネントの要件については、「[カスタム UI テストステップ](https://servicenow-prod.fluidtopics.net/jR2Pq1P614a50tcEQo2xkQ "HTML および JavaScript ページコンポーネントを取得し、それらがサポートするテストアクションを特定することによって、UI ページや UI マクロなどのカスタマイズされたユーザーインターフェイスをテストします。")」を参照してください。

### 手順

1. テストするカスタム UI ページを開きます。
2. `sn-atf-class` 属性をテスト対象の要素に追加し、getValue()、setValue()、click()、または isDisabled() の関数を処理するページに埋め込まれた JavaScript オブジェクトの名前に値を設定します。  

       <div sn-atf-class="MyClickableComponent">
           <label for="a_clickable_checkbox">MyClickableComponent</label>
           <input type="checkbox" id="a_clickable_checkbox" checked="true"/>
       </div>

3. `sn-atf-class` 属性に指定された JavaScript オブジェクトを作成し、カスタムページコンポーネントをクリック可能または設定可能ページコンポーネントとして識別するために必要な機能と属性を追加します。  
   {#override-component-class__table_r5q_gry_cgb__entry__2}

   | 関数名 | 説明 |
   |-|-|
   | initialize() | コンポーネントの初期値を取得します。次のように入力します。 $super(element, area) |
   | click() | コンポーネントを選択します。これらのプロパティを持つ JSON オブジェクトを返します。 `成功`：コンポーネントをクリックできる場合は true です。 注: UI テストステップのインテリジェント待機メカニズムをトリガーします。 |
   | getValue() | 要素の値を取得します。これらのプロパティを持つ JSON オブジェクトを返します。 * `成功`：値が取得された場合は true です。 * `結果`：コンポーネントの値。 {#override-component-class__ul_jym_3mm_wfb} |
   | isDisabled() | コンポーネントが無効かどうか。これらのプロパティを持つ JSON オブジェクトを返します。 * `成功`：コンポーネントが無効の場合は true です。 * `結果`：コンポーネントが無効の場合は true です。 {#override-component-class__ul_ont_4qm_wfb} |
   [表 : 3. クリック可能なコンポーネント関数]

   {#override-component-class__table_r5q_gry_cgb}  
   {#override-component-class__table_kml_csy_cgb__entry__2}

   | 関数名 | 説明 |
   |-|-|
   | initialize() | コンポーネントの初期値を取得します。次のように入力します。 $super(element, area) |
   | setValue(newValue) | コンポーネントの値を設定します。下記の 2 番目の例を参照してください。これらのプロパティを持つ JSON オブジェクトを返します。 `成功`：値が設定されている場合は true です。 注: UI テストステップのインテリジェント待機メカニズムをトリガーします。 |
   | getValue() | 要素の値を取得します。これらのプロパティを持つ JSON オブジェクトを返します。 * `成功`：値が取得された場合は true です。 * `結果`：コンポーネントの値。 {#override-component-class__ul_mml_csy_cgb} |
   | isDisabled() | コンポーネントが無効かどうか。これらのプロパティを持つ JSON オブジェクトを返します。 * `成功`：コンポーネントが無効の場合は true です。 * `結果`：コンポーネントが無効の場合は true です。 {#override-component-class__ul_nml_csy_cgb} |
   [表 : 4. 設定可能なコンポーネント関数]

   {#override-component-class__table_kml_csy_cgb}  
   {#override-component-class__table_p2n_psy_cgb__entry__2}

   | 属性の名前 | 説明 |
   |-|-|
   | isSettable: true | 設定可能なページコンポーネントとしてコンポーネントを識別します。 |
   [表 : 5. 設定可能なコンポーネント属性]

   {#override-component-class__table_p2n_psy_cgb}
4. Jelly でカスタムコンポーネントを作成するときは、`sn-atf-class` 属性で指定された JavaScript オブジェクトの周囲に `<g2:atf_only>` タグを追加します。  
   これらのタグにより、自動テスト中にのみ JavaScript オブジェクトが実行されます。
{#override-component-class__steps_jyp_gkz_1gb}

### 例

    //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>

## 参照とレコードピッカー {#ariaid-title4}

カスタム UI ステップを使用して、`sn-reference-picker` および `sn-record-picker` 角度ディレクティブの値を操作します。参照ピッカーの値は、選択されたレコードの `sys_id` を返します。レコードピッカーの値は、そのレコードピッカーに対して選択された値フィールドを返します。値として設定するレコードを選択することで、両方の要素を設定できます。

