When UI elements change after an asynchronous request completes in ChronoATX, do I need to use fixed delays like await Task.Delay(…) in .atx scripts?
No, fixed-duration delays using await Task.Delay(…) are generally unnecessary and not recommended.
The timing of HTML parsing completion (DOMContentLoaded) and subsequent DOM re-rendering triggered by asynchronous communication (Ajax / Fetch) are distinct. Relying on fixed-second delays like Task.Delay(5000) causes test failures (flakiness) due to network latency and wastes test execution time.
The ChronoATX Runtime provides four smart waiting APIs that detect asynchronous operations driven by events and states. Choosing the right API for your scenario ensures fast, resilient test automation.
## 4 Approaches to Asynchronous Waiting
### 1. Wait For Network Idle
Use case: Waiting for all concurrent asynchronous API requests to complete (no network traffic for 500 ms or more) after performing actions like search, filtering, or page navigation.
// 企業名を入力して検索
await Web.ClickLinkAsync("依頼先");
await Web.InputByLabelAsync("企業名 / 業種 / 地域", "sell");
await Web.PressKeyAsync("Enter");
// ❌ 以前の書き方: 固定時間待機
// await Task.Delay(5000);
// ⭕ 推奨: 通信が完了した瞬間に即座に次へ進む
await Web.WaitForNetworkIdleAsync();
await Web.ClickButtonAsync("詳細を見る");
### 2. Wait For Specific API Response (Wait For Response)
Use case: Accurately waiting for a specific backend API response (e.g., HTTP 200) after actions like saving, signing in, or updating data.
// 方式 A: 操作後に特定の API レスポンス完了を待つ
await Web.ClickButtonAsync("サインイン");
await Web.WaitForResponseAsync("/api/auth/login", 200);
// 方式 B: レスポンスが極めて速い場合の競合(取りこぼし)を防ぐトリガー実行
await Web.RunAndWaitForResponseAsync(
async () => await Web.ClickButtonAsync("保存する"),
"/api/v1/products",
expectedStatus: 200
);
### 3. Wait For Loading Disappearance / Specific Text Appearance (Wait For Text / Hidden)
Use case: Waiting for a “Processing…” spinner or overlay backdrop to disappear, or waiting for a new status text to appear.
// 「処理中...」やローディング遮蔽幕が消えるまで待機
await Web.ClickButtonAsync("提出する");
await Web.WaitForTextHiddenAsync("処理中...");
// 特定のステータス文字列が表示されるまで待機(デフォルト最大30秒)
await Web.WaitForTextAsync("発送待ち");
### 4. Custom Condition Polling (Wait Until)
Use case: Waiting for combined conditions or custom business logic and DOM state transitions.
// いずれかの完了ステータスが表示されるまで最大 15 秒間ポーリング
await Web.WaitUntilAsync(async () => {
return await Web.IsTextVisibleAsync("受領済み") || await Web.IsTextVisibleAsync("完了");
}, timeoutMs: 15000, pollIntervalMs: 200);
### Best Practices (Notes)
Clicking newly appeared buttons or links: ChronoATX action APIs such as ClickButtonAsync and InputByLabelAsync include built-in Auto-waiting until the target element becomes visible and actionable. In most scenarios, you can interact with elements directly without writing explicit wait commands.
Assertions and verification: Verification methods like VerifyTextAsync and VerifyLabelValueAsync include a built-in 5-second self-healing retry mechanism. You can safely remove any Task.Delay calls placed immediately before assertions.
Was this article helpful?
Thank you for helping us improve our documentation.