アサーションリファレンス
アサーションはステップの結果を検証します。AI エージェントが MCP ツールを通じて QA プランを構築する際に、各ステップにアサーションを含めます。各ステップには、1 つ以上のアサーションオブジェクトを含む assertions 配列を指定できます。ステップが成功とみなされるには、ステップ内のすべてのアサーションがパスする必要があります。
HTTP アサーション
Section titled “HTTP アサーション”http_request アクションタイプのステップに適用されるアサーションです。
status_code
Section titled “status_code”レスポンスのステータスコードが正確な値と一致するかチェックします。
{ "type": "status_code", "expected": 200 }| フィールド | 型 | 説明 |
|---|---|---|
type | "status_code" | アサーションタイプの識別子です。 |
expected | number | 期待する HTTP ステータスコードです。 |
status_code_in
Section titled “status_code_in”レスポンスのステータスコードが許可された値のいずれかであるかチェックします。
{ "type": "status_code_in", "expected": [200, 201] }| フィールド | 型 | 説明 |
|---|---|---|
type | "status_code_in" | アサーションタイプの識別子です。 |
expected | number[] | 許容される HTTP ステータスコードの配列です。 |
json_path
Section titled “json_path”レスポンスボディ内の特定の JSON パスにある値を検証します。
{ "type": "json_path", "path": "$.user.email", "expected": "alice@example.com" }| フィールド | 型 | 説明 |
|---|---|---|
type | "json_path" | アサーションタイプの識別子です。 |
path | string | チェックする値を指す JSONPath 式です。 |
condition | "exists" | "not_exists" | "contains" | (省略可) 比較モードです。省略すると完全一致となります。 |
expected | any | (exists/not_exists 使用時は省略可) 期待する値です。 |
条件の動作:
- 省略 —
pathの値とexpectedの完全一致チェックを行います。 "exists"— 指定したパスに値が存在すればパスします。expectedフィールドは無視されます。"not_exists"— 指定したパスに値が存在しなければパスします。expectedフィールドは無視されます。"contains"—pathの文字列値がexpectedを部分文字列として含んでいればパスします。
バイナリレスポンス: json_path はバイナリレスポンス(画像や PDF ダウンロード等)では常に失敗し、明示的なメッセージを返します。代わりに header、body_size、body_hash を使用してください。
header
Section titled “header”レスポンスヘッダーの値を検証します。ヘッダー名は大文字小文字を区別しません。
{ "type": "header", "name": "Content-Type", "expected": "application/json" }{ "type": "header", "name": "Location", "condition": "contains", "expected": "/users/" }{ "type": "header", "name": "X-Request-Id", "condition": "exists" }{ "type": "header", "name": "Set-Cookie", "condition": "matches", "expected": "session_id=" }| フィールド | 型 | 説明 |
|---|---|---|
type | "header" | アサーションタイプの識別子です。 |
name | string | ヘッダー名(大文字小文字を区別しない)。 |
condition | "equals" | "contains" | "exists" | "not_exists" | "matches" | (省略可) マッチ条件。既定は "equals"。"matches" は expected を正規表現として扱う。 |
expected | string | (equals/contains/matches で必須) 期待する値、または正規表現パターン。 |
body_size
Section titled “body_size”レスポンス body のバイト長を検証します。ダウンロードファイルが空でないことや、想定範囲に収まることの確認に有効です。
{ "type": "body_size", "expected": 12345 }{ "type": "body_size", "condition": "between", "expected": [1000, 5000] }{ "type": "body_size", "condition": "greater_than", "expected": 0 }| フィールド | 型 | 説明 |
|---|---|---|
type | "body_size" | アサーションタイプの識別子です。 |
condition | "equals" | "greater_than" | "less_than" | "between" | (省略可) 比較条件。既定は "equals"。 |
expected | number | [number, number] | 期待するバイト数。"between" の場合は [min, max] のタプル(両端含む)を指定。 |
body_hash
Section titled “body_hash”レスポンス body のハッシュ値を検証します。生成 PDF / Excel 等の golden file 比較に有効です。
{ "type": "body_hash", "expected": "<sha256 hex>" }{ "type": "body_hash", "algorithm": "md5", "expected": "<md5 hex>" }| フィールド | 型 | 説明 |
|---|---|---|
type | "body_hash" | アサーションタイプの識別子です。 |
algorithm | "sha256" | "md5" | (省略可) ハッシュアルゴリズム。既定は "sha256"。 |
expected | string | 期待する hex digest(大文字小文字を区別しない)。 |
body_contains
Section titled “body_contains”(テキスト)レスポンス body に部分文字列が含まれることを検証します。HTML ページ、プレーンテキスト webhook 等の非 JSON テキストレスポンスに有効です。
{ "type": "body_contains", "expected": "Welcome back" }| フィールド | 型 | 説明 |
|---|---|---|
type | "body_contains" | アサーションタイプの識別子です。 |
expected | string | レスポンス body に含まれているべき部分文字列。 |
バイナリレスポンス: body_contains はバイナリレスポンスでは常に失敗し、明示的なメッセージを返します。代わりに body_size または body_hash を使用してください。
ブラウザアサーション
Section titled “ブラウザアサーション”browser アクションタイプのステップに適用されるアサーションです。
element_text
Section titled “element_text”要素のテキストコンテンツをチェックします。
{ "type": "element_text", "selector": ".welcome-message" }{ "type": "element_text", "selector": ".welcome-message", "contains": "Hello" }| フィールド | 型 | 説明 |
|---|---|---|
type | "element_text" | アサーションタイプの識別子です。 |
selector | string | 対象要素の CSS セレクタです。 |
contains | string | (省略可) 要素のテキストに含まれるべき部分文字列です。省略すると、要素にテキストコンテンツがあることをアサートします。 |
element_visible
Section titled “element_visible”要素がページ上で表示されていることをアサートします。
{ "type": "element_visible", "selector": "#main-content" }| フィールド | 型 | 説明 |
|---|---|---|
type | "element_visible" | アサーションタイプの識別子です。 |
selector | string | 対象要素の CSS セレクタです。 |
element_not_visible
Section titled “element_not_visible”要素がページ上で表示されていないことをアサートします。
{ "type": "element_not_visible", "selector": ".error-banner" }| フィールド | 型 | 説明 |
|---|---|---|
type | "element_not_visible" | アサーションタイプの識別子です。 |
selector | string | 対象要素の CSS セレクタです。 |
url_contains
Section titled “url_contains”現在のページ URL が部分文字列を含むことをアサートします。
{ "type": "url_contains", "expected": "/dashboard" }| フィールド | 型 | 説明 |
|---|---|---|
type | "url_contains" | アサーションタイプの識別子です。 |
expected | string | URL に含まれるべき部分文字列です。 |
ページタイトルが正確な値と一致することをアサートします。
{ "type": "title", "expected": "Dashboard - My App" }| フィールド | 型 | 説明 |
|---|---|---|
type | "title" | アサーションタイプの識別子です。 |
expected | string | 期待するページタイトルです。 |
screenshot
Section titled “screenshot”スクリーンショットをキャプチャします。このアサーションは常にパスし、視覚的なドキュメントとして使用されます。
{ "type": "screenshot", "name": "checkout-page", "description": "Final state of the checkout form" }| フィールド | 型 | 説明 |
|---|---|---|
type | "screenshot" | アサーションタイプの識別子です。 |
name | string | (省略可) スクリーンショットファイルの名前です。 |
description | string | (省略可) スクリーンショットが何をキャプチャしているかの説明です。 |
element_count
Section titled “element_count”セレクタに一致する要素の数をアサートします。
{ "type": "element_count", "selector": ".cart-item", "expected": 3 }| フィールド | 型 | 説明 |
|---|---|---|
type | "element_count" | アサーションタイプの識別子です。 |
selector | string | 対象要素の CSS セレクタです。 |
expected | number | 一致する要素の期待数です。 |
element_attribute
Section titled “element_attribute”要素の属性値をアサートします。
{ "type": "element_attribute", "selector": "#submit-btn", "attribute": "disabled", "expected": "true" }| フィールド | 型 | 説明 |
|---|---|---|
type | "element_attribute" | アサーションタイプの識別子です。 |
selector | string | 対象要素の CSS セレクタです。 |
attribute | string | チェックする属性名です。 |
expected | string | 期待する属性値です。 |
cookie_exists
Section titled “cookie_exists”指定した名前のクッキーが存在することをアサートします。
{ "type": "cookie_exists", "name": "session_id" }| フィールド | 型 | 説明 |
|---|---|---|
type | "cookie_exists" | アサーションタイプの識別子です。 |
name | string | チェックするクッキー名です。 |
cookie_value
Section titled “cookie_value”クッキーの値をアサートします。
{ "type": "cookie_value", "name": "theme", "expected": "dark", "match": "exact" }| フィールド | 型 | 説明 |
|---|---|---|
type | "cookie_value" | アサーションタイプの識別子です。 |
name | string | クッキー名です。 |
expected | string | 期待するクッキーの値です。 |
match | "exact" | "contains" | (省略可) マッチモードです。デフォルトは "exact" です。 |
localstorage_exists
Section titled “localstorage_exists”localStorage にキーが存在することをアサートします。
{ "type": "localstorage_exists", "key": "auth_token" }| フィールド | 型 | 説明 |
|---|---|---|
type | "localstorage_exists" | アサーションタイプの識別子です。 |
key | string | チェックする localStorage のキーです。 |
localstorage_value
Section titled “localstorage_value”localStorage エントリの値をアサートします。
{ "type": "localstorage_value", "key": "locale", "expected": "en-US", "match": "exact" }| フィールド | 型 | 説明 |
|---|---|---|
type | "localstorage_value" | アサーションタイプの識別子です。 |
key | string | localStorage のキーです。 |
expected | string | 期待する値です。 |
match | "exact" | "contains" | (省略可) マッチモードです。デフォルトは "exact" です。 |