# Bug, Defect & Advanced Testing

{% hint style="info" %}
**Who is this for?** SDETs, developers, and DevOps engineers integrating ContextQA with AI coding assistants (Claude, Cursor) or CI/CD pipelines.
{% endhint %}

This reference covers three capability groups: defect lifecycle tools that bridge test failures to your ALM, advanced testing tools for performance and security, and AI analysis tools that surface test impact and code context.

***

## Bug & Defect

***

## create\_defect\_ticket

Compiles failure evidence from an execution and pushes a structured defect ticket to the connected ALM (Jira or Azure DevOps); use this immediately after a failed execution to file a bug without leaving your AI assistant.

**Category:** Bug & Defect | **Authentication required:** Yes

### Parameters

| Name          | Required | Type   | Description                                     |
| ------------- | -------- | ------ | ----------------------------------------------- |
| execution\_id | ✅        | string | ID of the failed test execution to report.      |
| project\_id   | ✅        | string | ALM project identifier to create the ticket in. |

### Returns

JSON with the created ticket's `id`, `url`, `title`, and the ALM system it was filed against.

### Example

```json
{
  "execution_id": "exec_4d8f1a",
  "project_id": "CQA"
}
```

### Related Tools

`get_test_case_results`, `investigate_failure`, `get_root_cause`

***

## get\_auto\_healing\_suggestions

Retrieves AI-generated proposals for repairing broken locators detected in a failed execution; review suggestions before applying them with `approve_auto_healing`.

**Category:** Bug & Defect | **Authentication required:** Yes

### Parameters

| Name          | Required | Type   | Description                                        |
| ------------- | -------- | ------ | -------------------------------------------------- |
| execution\_id | ✅        | string | ID of the execution that produced broken locators. |

### Returns

JSON array of healing proposals. Each item includes `healing_id`, the original broken locator, the proposed replacement locator, a confidence score, and the affected test step.

### Example

```json
{
  "execution_id": "exec_4d8f1a"
}
```

### Related Tools

`approve_auto_healing`, `get_test_step_results`, `investigate_failure`

***

## approve\_auto\_healing

Applies a specific auto-healing patch to update the broken locator in the test case definition; always review the suggestion from `get_auto_healing_suggestions` first.

**Category:** Bug & Defect | **Authentication required:** Yes

### Parameters

| Name          | Required | Type   | Description                                                                            |
| ------------- | -------- | ------ | -------------------------------------------------------------------------------------- |
| healing\_id   | ✅        | string | ID of the healing proposal to apply. Obtained from `get_auto_healing_suggestions`.     |
| execution\_id | ❌        | string | Execution context for the heal. Helps the engine track which run triggered the repair. |

### Returns

JSON confirmation with `status`, the updated locator value, and the test step that was modified.

### Example

```json
{
  "healing_id": "heal_7c3b2e",
  "execution_id": "exec_4d8f1a"
}
```

### Related Tools

`get_auto_healing_suggestions`, `get_test_case_steps`, `update_test_case_step`

***

## Advanced Testing

***

## execute\_performance\_test

Runs a load test against the flows covered by a test case using a configurable virtual user count, duration, and ramp-up period.

**Category:** Advanced Testing | **Authentication required:** Yes

### Parameters

| Name           | Required | Type    | Description                                                |
| -------------- | -------- | ------- | ---------------------------------------------------------- |
| test\_case\_id | ✅        | integer | Numeric ID of the test case to use as the load scenario.   |
| virtual\_users | ✅        | integer | Number of concurrent virtual users to simulate.            |
| duration       | ✅        | integer | Total test duration in seconds.                            |
| ramp\_up       | ✅        | integer | Time in seconds to ramp up to the full virtual user count. |

### Returns

JSON with a performance execution ID, configuration echo, and a link to the live results dashboard.

### Example

```json
{
  "test_case_id": 88,
  "virtual_users": 100,
  "duration": 300,
  "ramp_up": 60
}
```

### Related Tools

`get_test_cases`, `get_execution_status`, `execute_test_case`

***

## execute\_security\_dast\_scan

Launches a DAST (Dynamic Application Security Testing) scan against the application exercised by a test case, using the specified scan profile to control scan depth and aggression.

**Category:** Advanced Testing | **Authentication required:** Yes

### Parameters

| Name           | Required | Type    | Description                                                                                                                                           |
| -------------- | -------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| test\_case\_id | ✅        | integer | Numeric ID of the test case whose flows define the scan target.                                                                                       |
| scan\_profile  | ✅        | string  | Scan intensity profile. Accepted values: `"standard"`, `"aggressive"`. Use `"standard"` for CI pipelines; `"aggressive"` for dedicated security runs. |

### Returns

JSON with a DAST scan execution ID, scan profile confirmation, and a link to the vulnerability report once the scan completes.

### Example

```json
{
  "test_case_id": 88,
  "scan_profile": "standard"
}
```

### Related Tools

`get_test_cases`, `get_execution_status`, `execute_test_case`

***

## export\_test\_case\_as\_code

Exports one or more test cases as runnable code in a specified framework and language, writing the output to a local path.

**Category:** Advanced Testing | **Authentication required:** Yes

### Parameters

| Name              | Required | Type    | Description                                                        |
| ----------------- | -------- | ------- | ------------------------------------------------------------------ |
| test\_case\_id    | ✅        | integer | Numeric ID of the test case to export.                             |
| framework\_type   | ✅        | string  | Target framework, e.g. `"playwright"`, `"cypress"`, `"selenium"`.  |
| language          | ✅        | string  | Output language, e.g. `"typescript"`, `"javascript"`, `"python"`.  |
| destination\_path | ✅        | string  | Absolute local path where the generated file(s) should be written. |

### Returns

JSON confirmation with the `destination_path`, a `download_url` to retrieve the file from ContextQA, and the list of generated files.

### Example

```json
{
  "test_case_id": 55,
  "framework_type": "playwright",
  "language": "typescript",
  "destination_path": "/home/dev/projects/my-app/tests/generated"
}
```

### Related Tools

`export_to_playwright`, `get_test_cases`, `migrate_repo_to_contextqa`

***

## AI-Powered Analysis

***

## get\_root\_cause

Sends failed step data, screenshots, and the session recording to the ContextQA root cause engine and returns a structured AI root cause analysis; use this as the first step in any failure investigation.

**Category:** AI Analysis | **Authentication required:** Yes

### Parameters

| Name          | Required | Type   | Description                            |
| ------------- | -------- | ------ | -------------------------------------- |
| execution\_id | ✅        | string | ID of the failed execution to analyse. |

### Returns

JSON with `rootCause` (a plain-English summary), `affectedStep`, `errorType`, `evidenceLinks` (screenshots, recording), and suggested remediation.

### Example

```json
{
  "execution_id": "exec_4d8f1a"
}
```

### Related Tools

`investigate_failure`, `get_ai_reasoning`, `get_test_step_results`, `create_defect_ticket`

***

## query\_repository

Queries a connected source code repository with a natural-language question and returns the most relevant code context and file references; use this to understand how the application under test is implemented before writing or debugging tests.

**Category:** AI Analysis | **Authentication required:** Yes

### Parameters

| Name         | Required | Type    | Description                                                  |
| ------------ | -------- | ------- | ------------------------------------------------------------ |
| question     | ✅        | string  | Natural-language question about the codebase.                |
| repo\_url    | ✅        | string  | URL of the Git repository to query (HTTPS or SSH).           |
| limit\_files | ❌        | integer | Maximum number of file references to return. Defaults to 10. |

### Returns

JSON with a `answer` string, a `files` array of relevant file paths with matched snippets, and a `confidence` score.

### Example

```json
{
  "question": "How does the checkout flow calculate shipping costs?",
  "repo_url": "https://github.com/example-org/storefront",
  "limit_files": 5
}
```

### Related Tools

`analyze_test_impact`, `generate_tests_from_code_change`, `analyze_test_repo`

***

## analyze\_test\_impact

Determines which existing test cases are affected by a set of changed files (and optionally changed functions), and returns a prioritised list of tests to rerun; use this in CI after a PR diff is known.

**Category:** AI Analysis | **Authentication required:** Yes

### Parameters

| Name               | Required | Type             | Description                                                                           |
| ------------------ | -------- | ---------------- | ------------------------------------------------------------------------------------- |
| changed\_files     | ✅        | array of strings | List of file paths that changed in the current diff, relative to repo root.           |
| changed\_functions | ❌        | array of strings | List of function or method names that changed. Improves precision of impact analysis. |

### Returns

JSON with `affectedTestCases` (array of test case objects with IDs and names) and `recommendedRerunIds` (array of integers ready to pass to `execute_test_case`).

### Example

```json
{
  "changed_files": [
    "src/checkout/ShippingCalculator.ts",
    "src/cart/CartSummary.tsx"
  ],
  "changed_functions": [
    "calculateShipping",
    "applyDiscount"
  ]
}
```

### Related Tools

`query_repository`, `generate_tests_from_code_change`, `execute_test_case`, `get_test_cases`

***
