> For the complete documentation index, see [llms.txt](https://help.autify.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.autify.com/nocode-web/autify-university/advanced/variables/test-plan-variables.md). Agents can also search and read this documentation through its [MCP server](https://help.autify.com/~gitbook/mcp).

# テストプラン変数

## 概要

テストプラン変数は、テストプランに設定できるキーと値のペアで、テストプラン内のシナリオから参照することができます。テストプラン内のシナリオで共通で使われるような変数、たとえばユーザーIDや環境設定などがある場合に、テストプラン変数は便利です。

## 変数の使用

### 変数の優先度

Autifyには[テスト間の変数の受け渡し](https://help.autify.com/nocode-web/autify-university/advanced/variables/passing-variables-between-tests.md)の仕組みがあるので、異なるレベルの変数を柔軟に使うことができます。テストプラン変数の話題に移る前に、Autifyでは異なる種類の変数がどのように動作するかを見てみましょう。シナリオから参照される変数は、インポート変数と呼ばれるキーと値のペアとして定義されます。インポート変数を持つシナリオがテストプラン内で実行された場合、変数は以下の順番で参照されます：

1. テストプラン内で先行するシナリオ実行から **エクスポートされた変数**
2. テストプランで定義された変数（**テストプラン変数**）
3. シナリオに設定された **インポート変数のデフォルト値**

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-d5623bbea90ba0f28d226d791b0b7eb4947b5d77%2FVariables-ja.png?alt=media)

[テスト間の変数受け渡し](https://help.autify.com/nocode-web/autify-university/advanced/variables/passing-variables-between-tests.md)も参照してください。

### テストプラン変数を参照するシナリオの作成

テストプラン変数を参照するには、まずインポート変数を持つシナリオを作成する必要があります。インポート変数については、ドキュメントを参照してください。

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-47c844a8bf618fc38c60a85f35ef4295c10fe33e%2FScreen%20Shot%202023-11-13%20at%208.58.51.png?alt=media)

### テストプラン変数の作成

シナリオができたら、テストプラン変数を作成しましょう。テストプラン詳細画面の「テストプラン変数」へ移動し、**追加** をクリックして変数を追加します。

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-4a11ab262a5062f671a75ae3e4fee67944df08fe%2FScreen%20Shot%202023-11-12%20at%2021.20.27.png?alt=media)

変数のキーとデフォルト値を指定し、**作成** をクリックします。キーの名前が、シナリオに設定されたインポート変数と同じものになるようにしてください。

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-2d430d01e8d3ab10745c6ac7a2a9c65afa872ab9%2FScreen%20Shot%202023-11-12%20at%2021.21.04.png?alt=media)

この手順を繰り返せば、最大50個までテストプラン変数を作成することができます。

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-080834b7b90091c0acf5d2e0ff711954e6eae161%2FScreen%20Shot%202023-11-12%20at%2021.22.31.png?alt=media)

### 変数を使ったテストの実行

次に、テストプラン変数を使ったテストがどのように実行されるのか、例を見てみましょう。

#### シナリオ

このシナリオは `FIRST_NAME` と `LAST_NAME` をインポート変数として取り込みます。`FIRST_NAME` のデフォルト値は "Foo"、`LAST_NAME` のデフォルト値は "Bar" とします。

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-56a394d888192383ab8461e68ef111f934d65e4d%2FScreen%20Shot%202023-11-21%20at%201.16.07\(1\).png?alt=media)

シナリオでは、テキストを入力するステップで `FIRST_NAME` と `LAST_NAME` をそれぞれ利用しています。

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-93910e2d9c722aba9a81c8b16e49133a0dbcb91d%2FScreen%20Shot%202023-11-21%20at%201.15.52.png?alt=media)

#### テストプラン

このテストプランは `FIRST_NAME` と `LAST_NAME` をテストプラン変数に持っています。`FIRST_NAME` の値は "Hatty"、`LAST_NAME` の値は "Bee" です。

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-aeaf1543d09511fb6e09d42f9ac46ac24b3b56de%2FScreen%20Shot%202023-11-22%20at%2017.48.13\(1\).png?alt=media)

#### テスト結果

シナリオの「今すぐ実行」でテストが個別に実行された場合、インポート変数のデフォルト値が利用されます。

* FIRST\_NAME = `Foo` (デフォルト値)
* LAST\_NAME = `Bar` (デフォルト値)

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-e7beb5790f5e01f00556ea1d56bd35495d9666d1%2FScreen%20Shot%202023-11-21%20at%201.14.52.png?alt=media)

一方、シナリオが前述のテストプランの中で実行された場合は、テストプラン変数が参照されます。

* FIRST\_NAME = `Hatty` (テストプラン内のデフォルト値)
* LAST\_NAME = `Bee` (テストプラン内のデフォルト値)

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-22950c99d9d3a818d50da1257046108f7428a763%2FScreen%20Shot%202023-11-21%20at%201.15.29.png?alt=media)

## ユースケース

### 異なる複数の環境に対してテストする

テストプラン変数の主な用途に一つに、異なる環境に対して異なる値を利用したいケースが挙げられます。これは、URL置換機能と併用するととても強力です。たとえば、ドメインが異なる本番環境とステージング環境で、別々のユーザーIDを利用したいケースを考えてみましょう。

|          | 開始URL                     | ユーザーID            |
| -------- | ------------------------- | ----------------- |
| 本番環境     | <https://prd.example.com> | <prd@example.com> |
| ステージング環境 | <https://stg.example.com> | <stg@example.com> |

これは、以下の方法で実現することができます。

* ユーザーIDをインポート変数として取得するシナリオを作成する
* 環境毎（本番・ステージング）に、以下を設定した別々のテストプランを作成する
  * URL置換（本番・ステージング）
  * ユーザーID用のテストプラン変数

このようにすれば、簡単に複数の環境に対して変数と共にテストプランを活用させることができます。

#### ステージング環境用のテストプランの設定

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-e737ebc0b73907d80b4470b1b2006d2713b23707%2FScreen%20Shot%202023-11-21%20at%200.53.14.png?alt=media)

#### 本番環境用のテストプランの設定

![](https://50135409-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fof7cb8AGXhWvWThq3R0w%2Fuploads%2Fgit-blob-e49a5f2db0ae45fe78432e0234c13810766fe7df%2FScreen%20Shot%202023-11-21%20at%200.55.19.png?alt=media)

みなさまがどのようにテストプラン変数を活用されるか、楽しみしています！


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.autify.com/nocode-web/autify-university/advanced/variables/test-plan-variables.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
