跪拜 Guibai
← All articles
Testing · Artificial Intelligence · Interview

AI in Test Automation: What It Genuinely Can't Do and What You're Just Using Wrong

By 狂师 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Teams burning budget on AI testing tools while skipping testability groundwork and prompt engineering are paying for 60-point solutions that break unpredictably. The gap between a flaky AI-generated suite and a stable one is not a better model—it's accessible markup, explicit business rules in prompts, and disciplined wait strategies.

Summary

AI can write test code that runs, but it stumbles on the parts that require deep business knowledge: calculating correct order totals under stacked promotion rules, verifying that an async chain across six systems actually completed, or diagnosing why an endpoint slowed down. These tasks demand domain judgment and investigative experience that current models lack. Forcing AI into these roles produces scripts that pass superficially while missing real failures.

The flip side is that many common complaints about AI testing are self-inflicted. Element location breaks because applications lack accessibility labels and test IDs. Generated data looks fake because prompts never specify sandbox number ranges, user tiers, or risk-control constraints. Scripts turn into unmaintainable spaghetti because no one told the model to use Page Object patterns, fixtures, or Arrange-Act-Assert structure. Flaky tests persist because `time.sleep(1)` is still the default wait strategy instead of explicit waits on business signals like loading spinners disappearing or URLs changing.

Fixing these requires no model upgrade. It requires testers to build testability into the application, write prompts that spell out business rules and timing conventions, and establish the data factories and code frameworks that let AI produce maintainable output. The bottleneck is rarely the AI; it's the clarity of the instructions and the quality of the testing infrastructure underneath.

Takeaways
AI cannot derive correct business assertions from code alone; it needs rules about promotion stacking, risk triggers, and point calculations that only domain experts hold.
Asynchronous chain verification across message queues and databases is invisible to AI's synchronous-response view, so human-designed reconciliation and monitoring remain essential.
Performance root cause analysis requires investigative reasoning—flame graphs, slow logs, GC correlation—that AI can report on but not independently diagnose.
Element location failures are usually a testability problem: missing aria-labels, absent accessibility IDs, and duplicate button names that no locator strategy can resolve.
Test data quality depends entirely on prompt specificity; specifying user tiers, sandbox number segments, and risk-control constraints produces production-usable data instead of 'test123.'
AI defaults to linear scripts; supplying Page Object patterns, fixture injection, and Arrange-Act-Assert structure in the prompt yields maintainable, parameterized test suites.
Flaky tests overwhelmingly trace back to `time.sleep` instead of explicit waits on business signals like loading spinners, URL changes, or DOM state transitions.
Three self-audit questions determine AI testing success: Does the app have accessible anchors? Does the prompt spell out business rules and timing? Is the test infrastructure solid?
Conclusions

The taxonomy splits AI testing failures into two clean categories—tasks where the model lacks the reasoning capability (business logic, async chains, root cause) and tasks where the human lacks the discipline (testability, prompt engineering, infrastructure). Most teams conflate the two and blame the model.

Business assertions are framed as a knowledge problem, not a code-generation problem. The AI can write `assert` statements fluently; it cannot know that a VIP discount stacking with a coupon should trigger risk rule RULE_VIP_OVERLAP unless someone who learned that from a production incident encodes it.

The waiting-strategy section diagnoses flaky tests as a failure to communicate 'business timing' to the model. This reframes flakiness from a tooling issue to a specification gap—the tester never told the AI that the list loads asynchronously or that the popup has a 300ms animation.

The closing argument—'a tester who knows how to use AI will make those who don't unemployed'—is a labor-market claim, not a technical one. It predicts that AI won't replace testers but will stratify them by their ability to instruct and constrain the tool.

Concepts & terms
Business assertion
A test check that verifies a business outcome—such as a final order price after discounts, triggered risk-control rules, or earned loyalty points—rather than a technical status like HTTP 200. These require domain knowledge that AI cannot infer from code alone.
Flaky test
A test that passes and fails intermittently without code changes, often caused by race conditions, improper waits (e.g., fixed `time.sleep`), or shared state. The most common fix is replacing time-based waits with explicit waits on business signals like DOM changes or URL transitions.
Page Object pattern
A test-design pattern where pages or services are encapsulated as classes with methods representing user actions. It separates test logic from locator details, making scripts more maintainable and reusable—something AI produces only when explicitly instructed.
Accessibility tree / semantic locators
The structured representation of a UI that assistive technologies and modern test tools use to identify elements by role, label, or accessibility ID. AI defaults to these locators, but they only work if developers have set attributes like `aria-label`, `ContentDescription`, or `data-testid`.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗