UiPath Documentation
uipath-cli
latest
false
UiPath CLI ユーザー ガイド
重要 :
このコンテンツは機械翻訳によって処理されています。 新しいコンテンツの翻訳は、およそ 1 ~ 2 週間で公開されます。

方法: CLI からテストを実行する

CI パイプラインの一部として UiPath CLI から Test Manager のテスト セットを実行し、実行判定を正しく解釈します。

このページでは、CI パイプラインの一部として CLI から UiPath Test Manager のテスト セットを実行する方法と、同様に重要な判定を正しく読み取る方法について説明します。uip tm ツールがテスト セットの実行を 3 つの動詞に分割するのには理由があります。そのうちの 1 つだけを使用すると、テストが失敗した場合でも合格するビルドを生成できます。

黄金律: 起動→待機→検証​

テスト セットの実行では、テストが失敗したために 1 つのuip tm動詞が 0 以外で終了することはありません。赤色のテスト セットの実行でパイプラインを失敗させるには、次の 3 つのコマンドが必要です (パッケージの実行には 1 つのコマンドが必要です。「 アップロードされたパッケージ内のすべてのテストを実行する」をご覧ください)。

  1. 起動 — uip tm testsets run.実行をキューに登録し、Orchestrator が要求を受け入れるとすぐに 0 を終了します。応答のStatus: "Running"は、最終的な結果ではなく、開始時の状態を反映しています。
  2. ブロック — uip tm waitです。実行が最終ステート (Finished または Cancelled) に達するまでポーリングを行います。いずれかの終了ステートに達したら 0 を終了します。これは「完了」がwaitの成功シグナルであるためです。 --timeoutで2を終了します (authentication-error スロットのドメイン固有の再利用により、スクリプトはテキストを解析せずに "時間がかかりすぎた" で分岐できます)。
  3. 確認 — uip tm report get。Data.Failed (および Passed、 None、 PassRate) を読み取ります。終了 0 、成功/不合格に関係なく、概要を正常に取得するたびに、スクリプトは Data.Failed > 0 をゼロ以外の終了に変える役割を担います。

テストセットには起動+待機のショートカットが存在します — 1回の呼び出しで起動とブロックを uip tm testsets run --waitします (--timeout/--poll-intervalポーリングの調整) — しかし、それはまだ起動 + 待機 + 検証ではありません: Finished実行は、内部のテストが失敗しても0終了します (Cancelled実行のみが終了します1)。赤色の実行をキャッチするには、まだ別の検証手順が必要です。必ず 3 つのステップ (または 2 ステップの run --wait と最後に確認する同じ report get ) を入力してください。

アップロードされたパッケージ内のすべてのテストを実行する​

Orchestrator にアップロード済みのパッケージでテストが出荷された場合、 uip tm run --type package は 1 回の呼び出しで起動、待機、検証を行います。パッケージ内のすべてのテスト ケースを、作成者にテスト セットなしで実行し、JUnit または UiPath のレポートを --result-pathに書き込み、テストが失敗したか、結果が報告されない、テスト実行がない、または実行がキャンセルされた場合に 1 を終了します。そのため、パイプラインは赤色の実行で失敗するので、別個の検証手順はありません。

uip tm run --type package \
  --project-key DEMO \
  --package-name MyTests \
  --package-version 1.0 \
  --folder-path Shared \
  --result-path ./results/junit.xml
uip tm run --type package \
  --project-key DEMO \
  --package-name MyTests \
  --package-version 1.0 \
  --folder-path Shared \
  --result-path ./results/junit.xml

Leave out --project-key to run the package in the tenant default project; Data.ProjectKey in the output names the project the tests ran in.

終了コード意味
0すべてのテストに合格しました。
1A test failed or reported no result, the run was cancelled, no test ran, or a service call failed. A missing login or no access to a project you passed also exits 1, before the run starts.
2Login or permission problem after the run starts, or no permission to open or create the tenant default project.
3オプションまたは入力が正しくありません。
4実行が --timeoutを超えました。

実用最小限のスニペット​

#!/usr/bin/env bash
set -euo pipefail

# 1. Launch
EXECUTION_ID=$(uip tm testsets run \
  --test-set-key DEMO:10 \
  --output-filter "ExecutionId" \
  --output plain)

# 2. Block (default timeout: 30 min; adjust with --timeout)
if ! uip tm wait \
  --execution-id "$EXECUTION_ID" \
  --project-key DEMO \
  --timeout 1800; then
  code=$?
  if [ "$code" -eq 2 ]; then
    echo "test run did not finish within 30 minutes" >&2
    exit 2
  fi
  echo "wait failed (exit $code)" >&2
  exit "$code"
fi

# 3. Verify
FAILED=$(uip tm report get \
  --execution-id "$EXECUTION_ID" \
  --project-key DEMO \
  --output-filter "Failed" \
  --output plain)

if [ "$FAILED" -gt 0 ]; then
  echo "$FAILED test case(s) failed" >&2
  exit 1
fi

echo "all tests passed"
#!/usr/bin/env bash
set -euo pipefail

# 1. Launch
EXECUTION_ID=$(uip tm testsets run \
  --test-set-key DEMO:10 \
  --output-filter "ExecutionId" \
  --output plain)

# 2. Block (default timeout: 30 min; adjust with --timeout)
if ! uip tm wait \
  --execution-id "$EXECUTION_ID" \
  --project-key DEMO \
  --timeout 1800; then
  code=$?
  if [ "$code" -eq 2 ]; then
    echo "test run did not finish within 30 minutes" >&2
    exit 2
  fi
  echo "wait failed (exit $code)" >&2
  exit "$code"
fi

# 3. Verify
FAILED=$(uip tm report get \
  --execution-id "$EXECUTION_ID" \
  --project-key DEMO \
  --output-filter "Failed" \
  --output plain)

if [ "$FAILED" -gt 0 ]; then
  echo "$FAILED test case(s) failed" >&2
  exit 1
fi

echo "all tests passed"

--output plain は、スカラー フィルター結果の裸の値を返します。これは、JSON を解析せずにフィールドをシェル変数にキャプチャする最も安全な方法です。「スクリプティング パターン — エンベロープから値を読み取る」を参照してください。

コマンドへの入力の選択​

uip tm testsets run UUIDではなく、 テストセットキーが必要です。キーの形式は <ProjectKey>:<Number> です (例: DEMO:10)。検索方法は 2 つあります。

# From the Test Manager UI — it is the "Key" column in the test set list.

# Or from the CLI:
uip tm testsets list --project-key DEMO --filter smoke \
  --output-filter "[*].{key:TestSetKey, name:Name}"
# From the Test Manager UI — it is the "Key" column in the test set list.

# Or from the CLI:
uip tm testsets list --project-key DEMO --filter smoke \
  --output-filter "[*].{key:TestSetKey, name:Name}"

list プロジェクトを --project-key または --project-idとして取得します。run は、テスト セット キーのプレフィックス ( プロジェクト DEMODEMO:10 → ) からプロジェクトを派生させます。

uip tm executions list --test-set-idに数値のUUIDが必要な場合、それは同じリスト出力のIdフィールドであり、TestSetKeyではありません。

実行するケースを選択する​

uip tm testsets run --execution-typeセット内のどのテスト ケースを実行するかを制御します。

  • automated (既定) — 自動化されたテスト ケースのみ。
  • manual — 手動テスト用のテスト ケースのみ
  • mixed — 両方です。
  • none — 型フィルターなし。

CIの場合、デフォルト(automated)のままにします—手動のケースでは、人間が合格/不合格をマークする必要があり、--timeoutまでInProgressに座ります。

パラメーターの上書きを渡す​

テスト セットでパラメーター (ターゲット URL やアカウント ID など) が公開されている場合は、起動時に --input-pathで上書きします。

cat > ./params.json <<'EOF'
[
  {"name": "TargetUrl", "type": "String", "value": "https://staging.example.com"},
  {"name": "AccountId", "type": "String", "value": "acme-staging"}
]
EOF

uip tm testsets run --test-set-key DEMO:10 --input-path ./params.json
cat > ./params.json <<'EOF'
[
  {"name": "TargetUrl", "type": "String", "value": "https://staging.example.com"},
  {"name": "AccountId", "type": "String", "value": "acme-staging"}
]
EOF

uip tm testsets run --test-set-key DEMO:10 --input-path ./params.json

オーバーライドは、テスト セットの現在のパラメーター定義と name (大文字と小文字は区別されず)、存在する場合は typeで照合されます。サーバーがパラメーター定義を報告しない場合、入力はそのまま送信されます。上書きはテスト セットに保存されるため、後で実行すると再利用 --input-path なくなります。

評決を詳しく読む​

uip tm report getは要約リーダーです。デフォルトの出力ではスコアカードが表示されます。 --query (JQ スタイルのフィルター) を渡して、1 回の呼び出しでサブセットを抽出します。

# Pretty scorecard
uip tm report get --execution-id "$EXECUTION_ID" --project-key DEMO

# Script-friendly — JSON with just the counts
uip tm report get --execution-id "$EXECUTION_ID" --project-key DEMO \
  --query '{total: .TotalTests, passed: .Passed, failed: .Failed}'
# Pretty scorecard
uip tm report get --execution-id "$EXECUTION_ID" --project-key DEMO

# Script-friendly — JSON with just the counts
uip tm report get --execution-id "$EXECUTION_ID" --project-key DEMO \
  --query '{total: .TotalTests, passed: .Passed, failed: .Failed}'

Data エンベロープには次のフィールドがあります (完全なスキーマについては、report get の参照をご覧ください)。

  • TotalTests, Passed, Failed, None (tests with no result), PassRate (a number such as 80, computed over the tests that passed or failed), Duration (HH:MM:SS).
  • FailedTests — 失敗したテスト ケースごとに 1 つのエントリ。 TestCaseName と Error 文字列 (ログの info フィールド、または失敗したアサーション メッセージを連結したリスト) が含まれます。

CIのテストダッシュボードに取り込むことができるJUnit-XMLファイルが必要な場合は、report getの代わりに(または並行して)uip tm result downloadを使用します。

失敗したケースを CI ログに表示する​

パイプラインを終了する前に、障害ごとに FailedTests 配列を人間が読める行に変換します。

if [ "$FAILED" -gt 0 ]; then
  uip tm report get \
    --execution-id "$EXECUTION_ID" \
    --project-key DEMO \
    --output-filter "FailedTests[*].[TestCaseName, Error]" \
    --output plain >&2
  echo "$FAILED test case(s) failed" >&2
  exit 1
fi
if [ "$FAILED" -gt 0 ]; then
  uip tm report get \
    --execution-id "$EXECUTION_ID" \
    --project-key DEMO \
    --output-filter "FailedTests[*].[TestCaseName, Error]" \
    --output plain >&2
  echo "$FAILED test case(s) failed" >&2
  exit 1
fi

より深い失敗分析 (失敗した 1uip tm testcaselog list-assertions つのケースのアサーションごとの詳細) には、 によって返されるログ IDuip tm executions testcaselogs list --only-failed の を使用します。

不安定なケースをリトライする​

実行に不安定なエラー (タイミング、環境) がある場合は、 失敗したケースのみを その場でリトライします。

uip tm executions retry \
  --execution-id "$EXECUTION_ID" \
  --project-key DEMO
uip tm executions retry \
  --execution-id "$EXECUTION_ID" \
  --project-key DEMO

uip tm executions retry同じ実行 ID が再利用され、新しい実行 ID は作成されません。再試行に失敗した場合は、情報メッセージを出力して 0 を終了します (意図的にエラーではありません)。

retry後、同じ実行 ID に対して wait + report get をループバックします。

よくある落とし穴​

  • 出力 testsets run 解析して合格/不合格を決定します。起動時の [ Status ] フィールドは通常 Running です。これは、すべてのテストに合格したのではなく、実行がキューに置かれたことを意味します。必ず wait に電話してから report getに電話してください。
  • waitに--timeoutを忘れる。既定値は 1800 秒 (30 分) です。無期限に待つために 0 を渡します(CIで望むことはめったにありません)。長いスイートの場合は、より大きな数を渡します。
  • wait からの終了2を認証エラーとして扱います。特にwaitでは、2はAuthenticationErrorではなくタイムアウトを意味します - 終了コードuip tm waitを参照してください。
  • testsets動詞を使用してテストを作成する。テスト ケースおよびテスト ケースと Orchestrator のオートメーションへのリンクは uip tm testcasesに基づいています。testsetsそれらをグループ化するだけです。

完全な CI 対応の例​

パイプライン ステップの bash スニペット — テストが失敗、タイムアウト、またはエラーが発生すると、ビルドに失敗します。

#!/usr/bin/env bash
set -euo pipefail

TEST_SET_KEY="${TEST_SET_KEY:?TEST_SET_KEY is required}"
PROJECT_KEY="${PROJECT_KEY:?PROJECT_KEY is required}"
TIMEOUT="${TEST_TIMEOUT:-1800}"

EXECUTION_ID=$(uip tm testsets run \
  --test-set-key "$TEST_SET_KEY" \
  --output-filter "ExecutionId" \
  --output plain)

echo "started execution $EXECUTION_ID" >&2

if ! uip tm wait \
  --execution-id "$EXECUTION_ID" \
  --project-key "$PROJECT_KEY" \
  --timeout "$TIMEOUT"; then
  code=$?
  case "$code" in
    2) echo "execution $EXECUTION_ID did not finish within ${TIMEOUT}s" >&2; exit 2 ;;
    *) echo "wait failed with exit $code" >&2; exit "$code" ;;
  esac
fi

# Get the scorecard and the names of any failed cases in one shot
uip tm report get \
  --execution-id "$EXECUTION_ID" \
  --project-key "$PROJECT_KEY"

FAILED=$(uip tm report get \
  --execution-id "$EXECUTION_ID" \
  --project-key "$PROJECT_KEY" \
  --output-filter "Failed" \
  --output plain)

if [ "$FAILED" -gt 0 ]; then
  echo "$FAILED test case(s) failed" >&2
  exit 1
fi

echo "all tests passed"
#!/usr/bin/env bash
set -euo pipefail

TEST_SET_KEY="${TEST_SET_KEY:?TEST_SET_KEY is required}"
PROJECT_KEY="${PROJECT_KEY:?PROJECT_KEY is required}"
TIMEOUT="${TEST_TIMEOUT:-1800}"

EXECUTION_ID=$(uip tm testsets run \
  --test-set-key "$TEST_SET_KEY" \
  --output-filter "ExecutionId" \
  --output plain)

echo "started execution $EXECUTION_ID" >&2

if ! uip tm wait \
  --execution-id "$EXECUTION_ID" \
  --project-key "$PROJECT_KEY" \
  --timeout "$TIMEOUT"; then
  code=$?
  case "$code" in
    2) echo "execution $EXECUTION_ID did not finish within ${TIMEOUT}s" >&2; exit 2 ;;
    *) echo "wait failed with exit $code" >&2; exit "$code" ;;
  esac
fi

# Get the scorecard and the names of any failed cases in one shot
uip tm report get \
  --execution-id "$EXECUTION_ID" \
  --project-key "$PROJECT_KEY"

FAILED=$(uip tm report get \
  --execution-id "$EXECUTION_ID" \
  --project-key "$PROJECT_KEY" \
  --output-filter "Failed" \
  --output plain)

if [ "$FAILED" -gt 0 ]; then
  echo "$FAILED test case(s) failed" >&2
  exit 1
fi

echo "all tests passed"

このスクリプトは、 いずれかの CI レシピのソリューションのデプロイ ステップの後に実行します。唯一の環境固有の設定は TEST_SET_KEY / PROJECT_KEY です — パイプライン内の環境ごとに設定し、同じスクリプトが dev/stage/prod 全体できれいにプロモートします。

参照​

このページは役に立ちましたか?

接続

ヘルプ リソース サポート(opens in new window)

学習する UiPath アカデミー(opens in new window)

質問する UiPath フォーラム(opens in new window)

最新情報を取得