<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>AI on Testing Observation</title><link>https://chengxiaqiucao.github.io/en/categories/ai/</link><description>Recent content in AI on Testing Observation</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>|by Daniel Wei</copyright><lastBuildDate>Wed, 04 Nov 2026 09:00:00 +0800</lastBuildDate><atom:link href="https://chengxiaqiucao.github.io/en/categories/ai/index.xml" rel="self" type="application/rss+xml"/><item><title>Handing Change Points to an Agent - Precision and Latency in Production Monitoring Need Not Be a Trade-off</title><link>https://chengxiaqiucao.github.io/en/post/149-agentic-change-monitoring/</link><pubDate>Wed, 04 Nov 2026 09:00:00 +0800</pubDate><guid>https://chengxiaqiucao.github.io/en/post/149-agentic-change-monitoring/</guid><description>&lt;img src="https://chengxiaqiucao.github.io/post/149-agentic-change-monitoring/cover.webp" alt="Featured image of post Handing Change Points to an Agent - Precision and Latency in Production Monitoring Need Not Be a Trade-off" />&lt;p>A rule of thumb long circulated in operations is that about 70% of production incidents are caused by changes to a running system &amp;ndash; binary releases, configuration pushes, feature flag switches. Given that, concentrating monitoring resources near those change points should in theory contain the impact of most regressions at minimal cost. Yet in engineering this is widely acknowledged as hard: not that nobody can write an alert, but that it is very hard to be both &amp;ldquo;accurate&amp;rdquo; and &amp;ldquo;early&amp;rdquo;, and harder still to make it run by itself inside an organisation.&lt;/p>
&lt;p>Large-model agents are changing that equation. What deserves attention is not the concept of &amp;ldquo;AI operations&amp;rdquo; but a specific engineering shape: let the model read code and write monitoring specs, let deterministic programs execute the specs, and let the model investigate the monitoring items that fire. This structure can already find regressions in systems it knows nothing about at prototype stage, with better precision and latency than a year ago.&lt;/p>
&lt;h2 id="why-change-point-monitoring-has-always-been-hard-to-land">Why Change-Point Monitoring Has Always Been Hard to Land
&lt;/h2>&lt;p>First, see where the old approach got stuck. Change-point monitoring is not a technical problem but the &amp;ldquo;takeoff&amp;rdquo; problem of platform engineering, and it has three typical dilemmas.&lt;/p>
&lt;p>The first is &lt;strong>picking the wrong first users&lt;/strong>. The natural move is to pilot with the teams that have the best operations foundation and the strongest motivation. But those teams&amp;rsquo; releases are already relatively safe, so the platform does not actually raise the overall operations water level; the value it offers is mainly toil reduction, a nice-to-have rather than a first-order safety improvement. Worse, precision is easy to achieve with such teams, so the new system ends up competing with existing alerts on recall and latency, with little chance of winning.&lt;/p>
&lt;p>The second is &lt;strong>too wide a spread gets drowned in noise&lt;/strong>. Switching to all services with only a small set of generic health metrics does give coverage, but those metrics carry irreducible noise, so precision is poor, alert fatigue sets in, and the platform gets switched off quickly.&lt;/p>
&lt;p>The third is the &lt;strong>structural trade-off between precision and latency&lt;/strong>. Before large models entered, available signals lined up along a spectrum: structured logs were precise but slow, metrics were coarse but fast, alerts were coarser still with unsatisfactory recall and precision but &amp;ldquo;at least there was something&amp;rdquo;. Getting both speed and accuracy inside a change window required a human to pre-label the metrics and pre-define the signals &amp;ndash; which depends on long-term organisational investment and the experience of senior engineers, experience that only years on the front line can build.&lt;/p>
&lt;p>There is one more piece of background worth counting: as code output and release volume grow fast, the share of the system&amp;rsquo;s &amp;ldquo;code that any single operations person has read&amp;rdquo; keeps falling. The system increasingly looks like something that was raised rather than fully designed, and people&amp;rsquo;s mental model of its internal state keeps thinning. That actually amplifies the value of automated investigation.&lt;/p>
&lt;h2 id="the-effective-shape-an-agent-that-writes-specs-plus-a-deterministic-system-that-executes-them">The Effective Shape: an Agent That Writes Specs Plus a Deterministic System That Executes Them
&lt;/h2>&lt;p>Why the agent works in this scenario is quite plain: it is happy to fire a large number of queries, can write queries on the spot for one specific change, and never tires of scanning logs. The trade-offs once forced by saving money and headcount &amp;ndash; how much to query, how finely, for how long &amp;ndash; are greatly relaxed, so precision and recall can be obtained at the same time.&lt;/p>
&lt;p>A working minimal prototype has three parts:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>A plan generator&lt;/strong>: reads the service code (especially the configuration consumption logic), proposes a monitoring plan for this change, and specifies which signals to watch, how long the window is, and what conditions count as anomalous;&lt;/li>
&lt;li>&lt;strong>An execution scaffold&lt;/strong>: compiles the plan into deterministic monitoring tasks and runs them on a cadence, handling collection, comparison and triggering, without depending on the model staying online;&lt;/li>
&lt;li>&lt;strong>An investigation agent&lt;/strong>: engages only when a monitoring item fires, reads code, checks metrics and logs, gives an explanation, and keeps a channel for escalating to a human.&lt;/li>
&lt;/ul>
&lt;p>The most important engineering judgement here is that &lt;strong>a pure agent loop is not the optimal shape&lt;/strong>. Having the model write a spec for &amp;ldquo;how to monitor this&amp;rdquo; and then handing it to a deterministic system to execute is cleaner and uses far fewer tokens than having the model loop over queries itself. The real &amp;ldquo;secret sauce&amp;rdquo; to polish in the prototype is not model capability but three very traditional pieces of engineering: noise-reduction heuristics, prompts that get the model to write high-quality specs, and a labelled evaluation set large enough to verify whether each subsequent adjustment is actually better.&lt;/p>
&lt;p>In other words, a monitoring agent needs scaffolding just like a coding agent. The round of adaptation the software development lifecycle went through for coding agents has not yet happened in monitoring.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/149-agentic-change-monitoring/03-fig1_hu_d47531ba54db8869.webp"
width="1024"
height="538"
srcset="https://chengxiaqiucao.github.io/post/149-agentic-change-monitoring/03-fig1_hu_bfc40fb573639884.webp 480w, https://chengxiaqiucao.github.io/post/149-agentic-change-monitoring/03-fig1_hu_d47531ba54db8869.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="190"
data-flex-basis="456px"
>
&lt;/p>
&lt;p>The three-stage structure of plan generation, deterministic execution and post-trigger investigation, plus the human escalation channel&lt;/p>
&lt;h2 id="three-structural-advantages-humans-cannot-match-or-cannot-afford">Three Structural Advantages Humans Cannot Match, or Cannot Afford
&lt;/h2>&lt;p>Once you accept the two premises &amp;ndash; that an agent can be better at monitoring than a person, and that a monitoring agent needs scaffolding &amp;ndash; several advantages become very concrete.&lt;/p>
&lt;p>&lt;strong>All-hours, full-volume tracking.&lt;/strong> If inference cost is low enough, then any regression in any metric you care about, or any suspicious log line, can be investigated without first crossing the tangent line of &amp;ldquo;worth a human&amp;rsquo;s attention&amp;rdquo;. Traditional on-call needs shifts across time zones; an agent does not.&lt;/p>
&lt;p>&lt;strong>Parallel fan-out investigation.&lt;/strong> During incident triage you can dispatch several investigation threads at once, each tracing a possible causal chain, and then quickly consolidate. This is already how many teams do incident triage &amp;ndash; a person manually starts a batch of investigation tasks; the starting action itself could well be handed to an agent, letting the &amp;ldquo;incident responder&amp;rdquo; role scale elastically on demand. This is especially true for security incidents: attackers already use agent clusters, so defenders naturally need the corresponding capability.&lt;/p>
&lt;p>&lt;strong>Faster time to understanding.&lt;/strong> Models read code, query and digest metrics and logs faster than people. Speed does not always translate directly into shorter detection time &amp;ndash; someone with extremely deep system knowledge may still find the key signal faster by intuition &amp;ndash; but as long as tacit knowledge is written down and retrievable, an agent will be consistently ahead at going from zero to understanding. For systems with thin operations experience, or that nobody really knows, the gap is even wider.&lt;/p>
&lt;h2 id="from-read-only-to-action-a-path-of-tiered-delegation">From Read-Only to Action: A Path of Tiered Delegation
&lt;/h2>&lt;p>What has been discussed so far is mostly read-only monitoring. The real incremental value is on the write path, but delegation must be tiered, with corresponding guardrails at each tier.&lt;/p>
&lt;p>&lt;strong>Tier one: more diligent observation.&lt;/strong> Nobody used to pay a full-time engineer to walk through every commit of every service, pick out what should be monitored, and hang a batch of fast-firing alerts on those changes specifically. At current inference costs this becomes feasible. Likewise, a model can watch performance data, read heap dumps, stack traces and CPU profiles, and propose optimizations from the patterns; the suggestions go into A/B experiments as usual and are monitored like any other change. One documented example: after several rounds of model investigation on a public hot library that had already been carefully optimized by hand, it found roughly another 50% heap memory saving and a 30% latency reduction. Give a strong enough model a virtual machine and a benchmark, and its ability to climb the local optimum is considerable.&lt;/p>
&lt;p>&lt;strong>Tier two: deterministic remediation actions.&lt;/strong> Scaling instances, rotating compute pools, rolling back a configuration or a binary &amp;ndash; these actions have a clear scope, are predictable and easy to roll back, and are suitable to delegate to an agent first.&lt;/p>
&lt;p>&lt;strong>Tier three: open-ended fixes.&lt;/strong> Locate the defect, propose a patch, redeploy. Risk rises with the scope of authorization, but as capability expands, more and more write-path work can be responsibly delegated. This is exactly what makes self-healing systems attractive, provided every tier has audit and rollback.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/149-agentic-change-monitoring/03-fig2_hu_ed3dda194caa0a4b.webp"
width="1024"
height="683"
srcset="https://chengxiaqiucao.github.io/post/149-agentic-change-monitoring/03-fig2_hu_ce2d582339374e61.webp 480w, https://chengxiaqiucao.github.io/post/149-agentic-change-monitoring/03-fig2_hu_ed3dda194caa0a4b.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="150"
data-flex-basis="360px"
>
&lt;/p>
&lt;p>Three tiers of delegation from read-only observation to open-ended fixing, each with different guardrails and rollback requirements&lt;/p>
&lt;h2 id="cost-is-no-longer-the-constraint-but-the-evaluation-set-is">Cost Is No Longer the Constraint, but the Evaluation Set Is
&lt;/h2>&lt;p>With current lightweight models, work such as watching charts and comparing trends is already within reach. For a mid-sized technology company, continuous monitoring of the entire service fleet lands at roughly the low hundreds of dollars a day, and a startup-scale fleet is only a fraction of that. Compared with human on-call, or even with the cost of observability infrastructure itself, this number is not a decision obstacle &amp;ndash; one team saved millions of dollars a year in observability spend after a single optimization round, and that was only a part of one team&amp;rsquo;s spend on it.&lt;/p>
&lt;p>With cost out of the way, the bottleneck shifts to &amp;ldquo;how do we know monitoring is getting better&amp;rdquo;. That is why the labelled evaluation set cannot be skipped: without it, changing prompts, changing noise-reduction rules or switching models is all guesswork, and the failure mode of a monitoring system is precisely silence &amp;ndash; nobody discovers the problems that were never reported.&lt;/p>
&lt;p>From this a virtuous cycle can also form: coding agents let teams deliver more systems, monitoring agents let teams support more systems, and the human capacity both release gets invested in building more things. Engineers spend more of their time &amp;ldquo;building factories&amp;rdquo; and &amp;ldquo;tending gardens&amp;rdquo; rather than staring at dashboards.&lt;/p>
&lt;h2 id="the-order-to-roll-this-out">The Order to Roll This Out
&lt;/h2>&lt;p>If you intend to try it, this order is suggested so you do not hand over write permission at step one.&lt;/p>
&lt;ol>
&lt;li>Pick one class of high-frequency change point (release or configuration push) as the single entry point, and first connect the three data streams: change events, service code, telemetry and logs;&lt;/li>
&lt;li>Have the model do only two things: generate a monitoring spec for each change, and explain the phenomenon after something fires &amp;ndash; read-only throughout, with all conclusions subject to human review and escalation;&lt;/li>
&lt;li>Hand spec execution to a deterministic program so the model is not in the always-on loop, and record the tokens and duration of every call along the way;&lt;/li>
&lt;li>Accumulate a labelled evaluation set: label confirmed real regressions, false positives and problem-free changes separately, and use it to test every change to the noise-reduction heuristics and prompts;&lt;/li>
&lt;li>Once evaluation is stable, delegate tier by tier, starting with deterministic rollback actions, with audit logs and one-click reclamation at every tier;&lt;/li>
&lt;li>Review with two metrics, &amp;ldquo;time to detection&amp;rdquo; and &amp;ldquo;false positive rate&amp;rdquo;, rather than process quantities such as &amp;ldquo;how many logs were investigated&amp;rdquo;.&lt;/li>
&lt;/ol>
&lt;p>Two premises need to be stated up front: that an agent really can do this better than a person, and that it must be constrained by scaffolding. Skip the first and you build an expensive chat window; skip the second and you get a loop that keeps burning money while the signal gets dirtier and dirtier.&lt;/p>
&lt;p>Before the industry turns this into standard practice, teams that start accumulating evaluation sets and noise-reduction experience now will gain a real head start. On current trends, it will not be long before &amp;ldquo;no agent is watching your system&amp;rdquo; is itself seen as an operations risk.&lt;/p></description></item><item><title>The Blind Spot Exposed by 2,572 Tests - Most Agent Suites Test the Plumbing, Not the Decisions</title><link>https://chengxiaqiucao.github.io/en/post/148-agent-tests-plumbing/</link><pubDate>Wed, 04 Nov 2026 09:00:00 +0800</pubDate><guid>https://chengxiaqiucao.github.io/en/post/148-agent-tests-plumbing/</guid><description>&lt;img src="https://chengxiaqiucao.github.io/post/148-agent-tests-plumbing/cover.webp" alt="Featured image of post The Blind Spot Exposed by 2,572 Tests - Most Agent Suites Test the Plumbing, Not the Decisions" />&lt;p>Model leaderboards and benchmarks take almost all the attention, while the tests teams write for the agent applications they build themselves are almost never systematically examined. A peer-reviewed empirical study fills that gap: instead of running scores or sending questionnaires, the researchers hand-labelled the test methods in real open-source projects one by one, and counted what they actually assert. The conclusion is not polite &amp;ndash; the vast majority of tests verify that a tool can be called and that the code runs, not whether the agent made a correct decision.&lt;/p>
&lt;p>For teams currently wiring large-model capability into business systems, the value of this statistics is not that &amp;ldquo;the score is low&amp;rdquo;, but that it provides explicit ratios you can check your own suite against.&lt;/p>
&lt;h2 id="how-the-study-was-done">How the Study Was Done
&lt;/h2>&lt;p>The method itself deserves a look first, because it determines whether the numbers that follow can be trusted.&lt;/p>
&lt;p>The research team searched a code hosting platform for Python projects built on agent frameworks, obtaining 1,190 candidate repositories across 11 frameworks, from which they extracted 1,723 agents and 4,111 tools. To keep the manual labelling representative, the deep-dive scope was narrowed to projects &amp;ldquo;with a test suite of some size&amp;rdquo;, and finally 2,572 test methods across 240 test modules in 12 projects were annotated one by one.&lt;/p>
&lt;p>Labelling was done independently by two people, with a Cohen&amp;rsquo;s kappa of 0.92, which falls in the near-perfect agreement range. The taxonomy was also fixed in advance: 23 test patterns across four dimensions &amp;ndash; fixtures, test data, test targets and assertions &amp;ndash; and every percentage is computed from explicitly defined categories rather than impressionistic summary. In addition, 10 senior practitioners with an average of more than 17 years of experience were interviewed to cross-check the repository data.&lt;/p>
&lt;p>This is counting evidence about &lt;strong>real code&lt;/strong>: not a survey of intentions, and not a vendor benchmark.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/148-agent-tests-plumbing/02-fig1_hu_b56e1188d8adcc59.webp"
width="1024"
height="683"
srcset="https://chengxiaqiucao.github.io/post/148-agent-tests-plumbing/02-fig1_hu_847086e620763d8.webp 480w, https://chengxiaqiucao.github.io/post/148-agent-tests-plumbing/02-fig1_hu_b56e1188d8adcc59.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="150"
data-flex-basis="360px"
>
&lt;/p>
&lt;p>The share of each test type in the labelled sample, sourced from the manual labelling results of that empirical study&lt;/p>
&lt;h2 id="finding-one-most-tests-never-run-the-whole-agent">Finding One: Most Tests Never Run the Whole Agent
&lt;/h2>&lt;p>61.8% of the labelled tests evaluate only the isolated behaviour of a single tool or a single agent; 34.6% target interactions between agents, or between an agent and other components; only 3.5% cover consecutive calls across multiple tools; and merely 0.1% do end-to-end verification through an API the application exposes.&lt;/p>
&lt;p>Compare this distribution with the way failures actually happen in production and the problem becomes clear. Agent failures usually occur at the interaction layer: the wrong tool is chosen after a plausible first step, state is carried incorrectly across turns, the output structure the second tool receives does not match what the first tool promised. And those fall exactly on the thinnest layer of testing.&lt;/p>
&lt;p>The study also observed that frameworks quietly determine test shape: frameworks offering clean tool isolation boundaries (such as MCP-based projects) lean towards unit tests; frameworks that write orchestration logic explicitly in code (such as LangChain and LangGraph style) show more integration tests. Technology choice inadvertently decides what the team &amp;ldquo;will test along the way&amp;rdquo;.&lt;/p>
&lt;h2 id="finding-two-a-third-of-tests-mock-the-very-thing-they-claim-to-test">Finding Two: A Third of Tests Mock the Very Thing They Claim to Test
&lt;/h2>&lt;p>34.4% of tests mock the agent or tools in some form: 21.7% replace some components, 22.3% replace the entire agent, with overlap between the two. And of all mock scenarios, only 13.4% use test doubles built specifically for a validation goal; the rest rely on standard stubs and fixtures.&lt;/p>
&lt;p>Mocking is not inherently sinful; it makes tests fast and deterministic. The problem is that in an agent system a tool actually has &lt;strong>two interfaces&lt;/strong>: the call API facing the machine, and the natural language description facing the model &amp;ndash; and the latter determines how the model understands when to use it and how to fill in its arguments. A mock that returns the correct value cannot say anything about whether that description leads the model to call this tool at the right moment, with the right arguments, or to call it at all.&lt;/p>
&lt;p>In other words, a mock test proves the orchestration logic is not written wrong, not that tool selection is not wrong. Both show up as green in the test report.&lt;/p>
&lt;h2 id="finding-three-inputs-are-much-cleaner-than-real-tasks">Finding Three: Inputs Are Much Cleaner Than Real Tasks
&lt;/h2>&lt;p>39.9% of tests use simple, example-style inputs, and only 10.5% cover multi-step scenarios.&lt;/p>
&lt;p>This is the classic &amp;ldquo;test data is tidier than users&amp;rdquo; problem in a new skin. A clean prompt with clear semantics and a single answer passes under almost any model version, any prompt tweak and any tool change; it will equally pass the whole week before a genuinely complex request brings the system down. When test inputs are an order of magnitude tidier than production requests, the suite only measures that tidy world.&lt;/p>
&lt;p>Specifically for agents, what is usually missing is this: requests with incomplete fields, a previous turn that changes the meaning of the current one, a tool that returns an error the first time and needs a retry or a detour, a user correcting the goal midway. Those are the actual contents of multi-step scenarios.&lt;/p>
&lt;h2 id="finding-four-reasoning-is-the-product-itself-yet-almost-never-asserted">Finding Four: Reasoning Is the Product Itself, Yet Almost Never Asserted
&lt;/h2>&lt;p>Among assertion targets, output accounts for 55.9%, state for 51.1%, and reasoning-related behaviour only 8.7%. The study&amp;rsquo;s assessment of that 8.7% is quite direct: most of them only check that &amp;ldquo;reasoning-like behaviour occurred&amp;rdquo;, not whether it was correct or useful. The example given is verifying that a sub-agent&amp;rsquo;s activity appears in the logs &amp;ndash; whether the delegation was appropriate, or whether the sub-agent&amp;rsquo;s work improved the final result, is of no interest to the test.&lt;/p>
&lt;p>Another number is more alarming: only 4.1% of tests verify interaction with non-deterministic, non-agent components, and 2.4% verify interaction with deterministic components. For a class of system whose main risk comes from side effects (writing files, changing records, sending messages, triggering payments), the &amp;ldquo;what it did&amp;rdquo; layer leaves almost no verifiable evidence. A correct final answer that called the wrong tool along the way and used the wrong customer ID cannot be caught by output assertions.&lt;/p>
&lt;h2 id="finding-five-security-performance-and-cost-are-barely-in-scope">Finding Five: Security, Performance and Cost Are Barely in Scope
&lt;/h2>&lt;p>Tests touching non-functional requirements are only 7.5%. Within that already small slice, 49.0% concern security, 33.5% performance, 8.8% memory and 4.6% policy compliance. Converted, about 2.5% of all labelled tests involve performance &amp;ndash; for software whose single task may loop dozens of paid model calls.&lt;/p>
&lt;p>Practitioners in the interviews value non-functional testing more than the open-source projects do, which roughly suggests that lessons from production supply what the repositories cannot show. But the core gaps reported by both sides are the same: no systematic testing foundation, unclear test goals, and difficulty generating high-quality test data.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/148-agent-tests-plumbing/02-fig2_hu_d1d1ea0671da3090.webp"
width="1024"
height="683"
srcset="https://chengxiaqiucao.github.io/post/148-agent-tests-plumbing/02-fig2_hu_189a3b5203c4af61.webp 480w, https://chengxiaqiucao.github.io/post/148-agent-tests-plumbing/02-fig2_hu_d1d1ea0671da3090.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="150"
data-flex-basis="360px"
>
&lt;/p>
&lt;p>A four-layer strengthening path from &amp;ldquo;testing only the plumbing&amp;rdquo; to covering trajectories, state and side effects&lt;/p>
&lt;h2 id="rebalance-not-rebuild">Rebalance, Not Rebuild
&lt;/h2>&lt;p>You do not need to rebuild the whole test system, only to adjust the ratios in the five directions below. The percentages from the study make a good baseline for &amp;ldquo;what to move away from&amp;rdquo;.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Add one end-to-end task test per critical workflow.&lt;/strong> Use real tools and real inputs with noise, and assert not the final text but the final state of the world: if the agent is supposed to update a record, go and check that record.&lt;/li>
&lt;li>&lt;strong>Assert the trajectory, not just the answer.&lt;/strong> Check which tools were called, in what order, with what arguments. Calling the wrong tool with the wrong customer ID yet still stumbling onto a correct answer is a failure that output assertions are bound to miss.&lt;/li>
&lt;li>&lt;strong>Keep mocks, but state what they cannot prove.&lt;/strong> A test with a mocked tool only proves orchestration logic; write that in the test name or a comment, so later readers do not read green as end-to-end confidence.&lt;/li>
&lt;li>&lt;strong>Put some dirt in the inputs.&lt;/strong> Ambiguous requests, missing fields, preceding turns that change semantics, tools that fail on first call. The 10.5% multi-step share is a number your own suite can aim to beat.&lt;/li>
&lt;li>&lt;strong>Add at least one non-functional test.&lt;/strong> A per-task token or cost ceiling, a timeout, or &amp;ldquo;must not trigger a tool call when retrieved content contains an injected prompt string&amp;rdquo;. One is better than the zero coverage that 92.5% of tests have.&lt;/li>
&lt;/ul>
&lt;h2 id="the-boundaries-of-this-study">The Boundaries of This Study
&lt;/h2>&lt;p>Using the conclusions accurately matters more than citing them, and three points must be stated together.&lt;/p>
&lt;p>The sample skews towards projects &amp;ldquo;disciplined enough to maintain a fairly large test suite&amp;rdquo;, so industry practice overall may be worse than these numbers, or may differ in kind; the study counts tests committed to repositories and does not cover trace review, evaluation dashboards, manual exploratory testing and other genuinely real verification paths outside the suite, which the authors explicitly acknowledge; and a unit-test majority is not itself wrong &amp;ndash; in any healthy suite, fast cheap unit tests should outnumber slow end-to-end tests. What is being discussed here is that &lt;strong>the other layers are almost entirely absent&lt;/strong>, not that the first layer should not exist.&lt;/p>
&lt;p>Conversely, the evidence supporting the conclusions is solid: dual manual labelling with 0.92 agreement, a taxonomy specific down to 23 patterns, interview conclusions and repository data pointing at the same core gaps, and results that went through peer review rather than a blog assertion.&lt;/p>
&lt;p>The study also lists three conditions that would overturn it, which make good observation indicators for a team to track: if a manual labelling study of comparable scale on closed-source production systems found reasoning assertions and non-functional tests several times higher, the open-source sample would stop being a valid warning; if teams dense in unit tests and mocks turned out no worse in production incident rates than teams doing trajectory and state testing, the practical importance of those missing layers would drop; and if frameworks made trajectory assertions and state diffing default capabilities, with data showing developers actually using them, this statistic would be a slice in time rather than a long-term problem.&lt;/p>
&lt;h2 id="a-self-check-you-can-do-right-now">A Self-Check You Can Do Right Now
&lt;/h2>&lt;p>Open your own project&amp;rsquo;s agent test suite and ask of every test: if the model stopped reasoning well from tomorrow but every pipe kept working, how many of these tests would still pass?&lt;/p>
&lt;p>That ratio is the part of the suite that genuinely covers agent capability. It is usually much lower than the number on the coverage report, and lower for a good reason &amp;ndash; from the moment they were written, the vast majority of assertions were never aimed at where the model is most likely to go wrong. Add one end-to-end state assertion, one trajectory assertion and one cost ceiling, and only then does the suite start testing the part of this system that makes it an agent.&lt;/p></description></item><item><title>How to Better Embed AI into a Testing Team</title><link>https://chengxiaqiucao.github.io/en/post/139-ai_in_qa_team/</link><pubDate>Tue, 27 Jan 2026 15:17:17 +0800</pubDate><guid>https://chengxiaqiucao.github.io/en/post/139-ai_in_qa_team/</guid><description>&lt;h2 id="introduction">Introduction
&lt;/h2>&lt;p>Today AI has gradually entered the work of testing teams more widely.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/139-ai_in_qa_team/Pasted-20260127_hu_3aadd07d5ec8bba8.webp"
width="1024"
height="351"
srcset="https://chengxiaqiucao.github.io/post/139-ai_in_qa_team/Pasted-20260127_hu_f5740f4486e7991a.webp 480w, https://chengxiaqiucao.github.io/post/139-ai_in_qa_team/Pasted-20260127_hu_3aadd07d5ec8bba8.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="292"
data-flex-basis="700px"
>
&lt;/p>
&lt;p>It usually does not arrive through a large planned transformation, but rather through the curiosity and growth of team members. Maybe one tester starts using DeepSeek to rewrite test cases; another uses Doubao to organize a long requirements document; or someone starts trying an &amp;ldquo;AI-driven&amp;rdquo; automation tool they saw on a WeChat account.&lt;/p>
&lt;p>Yet in many cases, when we look at the team as a whole, the way work is done has hardly changed at all.&lt;/p>
&lt;p>Some people use AI heavily while others almost never touch it.
Some use it but do not fully trust it.
A few are overly dependent on it.&lt;/p>
&lt;p>For most teams, something always seems to be missing: AI ought to be helping more than it does now.&lt;/p>
&lt;p>This is usually when team leaders step in and ask the wrong question:&lt;/p>
&lt;p>&lt;strong>&amp;ldquo;Which AI tool should we adopt and roll out?&amp;rdquo;&lt;/strong>&lt;/p>
&lt;p>In reality, the problem is rarely the tool.&lt;/p>
&lt;p>The problem is whether, and how, the team is accustomed to working with AI as part of its everyday thinking.&lt;/p>
&lt;h2 id="why-many-testing-teams-struggle-to-adopt-ai-meaningfully">Why Many Testing Teams Struggle to Adopt AI Meaningfully
&lt;/h2>&lt;p>When AI is introduced into a testing team, it is usually framed as a &amp;ldquo;productivity accelerator&amp;rdquo;. A tool that generates test cases faster, writes automation faster, or summarizes information in seconds.&lt;/p>
&lt;p>That preconception is dangerous.&lt;/p>
&lt;p>&lt;strong>Testing work is not just a link in the pipeline, and it is not merely producing test conclusions. It is about understanding risk, questioning assumptions and making judgments under imperfect conditions&lt;/strong>.&lt;/p>
&lt;p>When AI enters this territory without guidance, two things often happen:&lt;/p>
&lt;p>&lt;strong>Some people become defensive.&lt;/strong> They worry that skills built over years &amp;ndash; careful analysis, attention to detail, deep product knowledge &amp;ndash; are suddenly devalued.&lt;/p>
&lt;p>&lt;strong>Others go the opposite way.&lt;/strong> They start outsourcing their own thinking. If AI sounds confident and articulate, it is easy to lean towards assuming it must be right.&lt;/p>
&lt;p>But both reactions actually stem from the same root cause: a lack of training, not a lack of intelligence.&lt;/p>
&lt;p>AI has not removed the need for testing thinking. It amplifies problems, and amplification without guidance usually makes problems worse rather than clearer.&lt;/p>
&lt;h2 id="using-ai-in-a-testing-team-is-about-more-than-prompts">Using AI in a Testing Team Is About More Than Prompts
&lt;/h2>&lt;p>When teams discuss &amp;ldquo;AI training&amp;rdquo;, they usually mean how to write better prompts or how to use a particular tool.&lt;/p>
&lt;p>That may help, but it misses the core issue.&lt;/p>
&lt;p>The real challenge is not how to ask AI questions, but:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>When does asking make sense?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>What kind of answer is safe to use?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>How much trust is appropriate in different contexts?&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>In other words, AI needs to be placed inside the test decision process, not left outside it.&lt;/p>
&lt;p>One of the most useful mindset shifts leadership can bring to a testing team is this:&lt;/p>
&lt;p>&lt;strong>Every interaction with AI is itself a testing activity. AI&amp;rsquo;s output is not the result; the evaluation of that output is the result.&lt;/strong>&lt;/p>
&lt;p>Once testers internalize this idea, AI stops being a shortcut and becomes a thinking partner that still needs supervision.&lt;/p>
&lt;h2 id="connecting-the-testing-ecosystem-from-mindset-to-practice">Connecting the Testing Ecosystem, from Mindset to Practice
&lt;/h2>&lt;p>Once the mindset is in place, the next challenge is practice: AI should not exist in isolation. If it stays in a chat window disconnected from your tools, it will always be an experiment rather than part of the daily work.&lt;/p>
&lt;p>That is where connecting the testing ecosystem matters.&lt;/p>
&lt;p>Do not introduce AI as yet another tool; integrate it into the systems the team already uses: Jira, Xray, Playwright and the CI pipeline. The goal is not automation for its own sake, but reducing repetitive work while keeping human judgment in control.&lt;/p>
&lt;p>One effective approach is to go step by step, &lt;strong>introducing only one capability at a time&lt;/strong>. For example:&lt;/p>
&lt;h3 id="automated-test-generation-through-mcp-and-playwright">&lt;strong>Automated test generation through MCP and Playwright&lt;/strong>
&lt;/h3>&lt;p>A practical starting point is test automation support. By running a Playwright MCP Server connected to a local large language model (LLM), tests can be generated directly from the application under test. The AI reads DOM snapshots, suggests locators and generates runnable Playwright scripts for common flows such as checkout or refunds.&lt;/p>
&lt;p>At this stage the division of responsibility is very clear: AI writes the first draft. Testers review, adjust and decide what can enter the repository. This is not replacement but amplification. Cognitive load shifts from tedious boilerplate to verification, coverage and intent.&lt;/p>
&lt;h3 id="generating-test-cases-from-jira-and-pushing-them-to-xray">&lt;strong>Generating test cases from Jira and pushing them to Xray&lt;/strong>
&lt;/h3>&lt;p>Another high-impact integration point is the requirements flow. When a new Jira ticket is created, AI can analyze the description, suggest test cases, classify them by risk, and push a structured test plan skeleton to Xray through the API. By the time testers pick up the story, the groundwork is done.&lt;/p>
&lt;p>What changes is not ownership but timing. Testers spend less time transcribing and more time thinking: refining scenarios, challenging assumptions and identifying gaps. The result is not &amp;ldquo;AI-generated tests&amp;rdquo; but earlier, better testing conversations.&lt;/p>
&lt;h3 id="automating-test-reports-but-with-review-required">&lt;strong>Automating test reports, but with review required&lt;/strong>
&lt;/h3>&lt;p>Result reporting is another area where AI can add lift. After a run finishes, AI can produce a human-readable summary, group results by feature, highlight failures and link back to the Jira tickets directly. Stakeholders get clear information without going through spreadsheets, and testers are freed from mechanical reporting work.&lt;/p>
&lt;p>Importantly, these reports are summaries, not verdicts. They support communication; they do not replace explanation.&lt;/p>
&lt;h2 id="introducing-ai-pair-testing">Introducing &amp;ldquo;AI Pair Testing&amp;rdquo;
&lt;/h2>&lt;p>This is where the ecosystem really changes. Most teams use AI to &amp;ldquo;generate&amp;rdquo; things. A more powerful approach is to use AI to &amp;ldquo;challenge&amp;rdquo; thinking.&lt;/p>
&lt;p>During exploratory testing, AI can act as a relentless junior QA, the one who keeps asking uncomfortable questions. You feed it your observations, and it responds by probing edge cases, questioning assumptions and suggesting alternative failure modes.&lt;/p>
&lt;p>In this mode AI is no longer a tool but a thinking partner. The mindset shift is simple yet profound: stop asking what AI can generate, and start asking what it can question.&lt;/p>
&lt;h2 id="letting-testers-build-their-own-micro-assistants">Letting Testers Build Their Own Micro-Assistants
&lt;/h2>&lt;p>Once there is some traction in the testing work, you can go further.&lt;/p>
&lt;p>Rather than centralizing all AI use, encourage testers to build small, purpose-specific assistants with tools such as MCP. These are not company-wide platforms but personal accelerators.&lt;/p>
&lt;p>One tester might build an accessibility checker, another might create a regression planner that pulls data from Jira, and another might focus on generating release notes from Xray results. Every QA person owns their own assistant and &amp;ldquo;AI apprentice&amp;rdquo;. Ownership strengthens accountability rather than dependence. Some teams even demo these results internally, turning AI use into shared learning rather than a secret experiment.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/139-ai_in_qa_team/Pasted-20260127-1_hu_d6dd582efac45d6b.webp"
width="1024"
height="539"
srcset="https://chengxiaqiucao.github.io/post/139-ai_in_qa_team/Pasted-20260127-1_hu_1ebc8bffec2b492c.webp 480w, https://chengxiaqiucao.github.io/post/139-ai_in_qa_team/Pasted-20260127-1_hu_d6dd582efac45d6b.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="189"
data-flex-basis="455px"
>
&lt;/p>
&lt;h2 id="building-a-feedback-loop-around-ai-use">Building a Feedback Loop Around AI Use
&lt;/h2>&lt;p>Finally, AI should evolve with the team rather than sit outside the iteration rhythm. Every few sprints, review what actually worked:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Where did AI save real time?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Where did it add noise or hallucination?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>How accurate were its suggestions?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Which validation rules need strengthening?&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>This feedback loop makes AI use deliberate, inspected and continuously improved, just like any other part of the testing process.&lt;/p>
&lt;h2 id="starting-where-risk-is-low">Starting Where Risk Is Low
&lt;/h2>&lt;p>One reason AI adoption fails is that teams either take too big a step or stay too vague.&lt;/p>
&lt;p>They try from the start to use AI for final deliverables: final test cases, final documents, final decisions. When something goes wrong, trust collapses.&lt;/p>
&lt;p>A better approach is to start where risk is low and learning value is high. For example:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Ask AI to suggest test ideas you may not have considered&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Use it to rewrite acceptance criteria to check whether they are really clear&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Generate edge cases for you to challenge and refine&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Summarize exploratory testing notes so that patterns become visible&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>In these scenarios AI is not replacing responsibility but extending perspective. The rule that must be clear from day one is simple and powerful: &lt;strong>AI can help you think. But it cannot decide for you.&lt;/strong> When teams understand that ownership never left them, fear decreases and misuse becomes easier to spot.&lt;/p>
&lt;h2 id="letting-testers-apply-their-testing-skills-to-ai">Letting Testers Apply Their Testing Skills to AI
&lt;/h2>&lt;p>This is the part many organizations completely overlook. In many cases test engineers already have exactly the skills needed to use AI safely, but they do not realize those skills apply here too. Treat AI&amp;rsquo;s answers just like:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Unverified requirements&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Suggestions from a junior team member&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Assumptions that need evidence&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>Teams should explicitly encourage engineers to interrogate AI output:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>What assumptions did this answer make?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>What context is missing?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Which scenarios did it ignore?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Does this still hold in production?&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>When engineers start doing this consistently, something interesting happens. They stop asking &amp;ldquo;is AI good or bad?&amp;rdquo; and start asking &amp;ldquo;in which situations is AI useful, and in which situations does it mislead?&amp;rdquo; That is a far more mature relationship.&lt;/p>
&lt;h2 id="making-ai-part-of-existing-testing-habits">Making AI Part of Existing Testing Habits
&lt;/h2>&lt;p>If AI sits outside the workflow, it will never become &amp;ldquo;daily work&amp;rdquo;.&lt;/p>
&lt;p>You do not need new meetings or dedicated AI time slots. You need to integrate AI into the moments where thinking already happens.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>During &lt;strong>requirements refinement&lt;/strong>, AI can be used to surface risks the team may want to discuss.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>During &lt;strong>test planning&lt;/strong>, it can help build risk-based coverage.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>During &lt;strong>bug triage&lt;/strong>, it can help identify recurring themes across different defects.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>During &lt;strong>retrospectives&lt;/strong>, it can help summarize learnings for the team to judge.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>Even in test automation, AI can support the team by copying an existing test case template and adapting it to a new scenario, but always with human review and ownership.&lt;/p>
&lt;p>The key is consistency. If AI is used occasionally, it remains a novelty. If it is used visibly and repeatedly in shared spaces, it becomes normal. Culture changes through repetition, not through declarations.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/139-ai_in_qa_team/Pasted-20260127-2_hu_8866458211ec01a1.webp"
width="1024"
height="653"
srcset="https://chengxiaqiucao.github.io/post/139-ai_in_qa_team/Pasted-20260127-2_hu_b05e291e621c9ee0.webp 480w, https://chengxiaqiucao.github.io/post/139-ai_in_qa_team/Pasted-20260127-2_hu_8866458211ec01a1.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="156"
data-flex-basis="376px"
>
&lt;/p>
&lt;h2 id="setting-boundaries-that-empower-rather-than-constrain">Setting Boundaries That Empower Rather Than Constrain
&lt;/h2>&lt;p>One reason teams hesitate to use AI is uncertainty. They are unsure what is allowed, what is dangerous, or what might get them into trouble later.&lt;/p>
&lt;p>This is where leadership needs to be clear and pragmatic. Rather than a long policy, define simple guardrails:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Which types of data may be shared&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Which must never be shared&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Where human review is mandatory&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Where AI output must never be used&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>Good guardrails reduce anxiety. They make experimentation safer rather than scarier. When people feel safe, they learn faster.&lt;/p>
&lt;h2 id="rethinking-the-definition-of-success">Rethinking the Definition of &amp;ldquo;Success&amp;rdquo;
&lt;/h2>&lt;p>If you measure AI adoption by counting outputs, you will optimize for the wrong goal.&lt;/p>
&lt;p>More AI-generated test cases does not automatically mean better testing. In fact, it often means the opposite.&lt;/p>
&lt;p>More meaningful signals are subtler:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>Are discussions going deeper and focusing on risk?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Is onboarding to testing faster?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Are blind spots found earlier?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Is the team spending less time on mechanical work and more on judgment?&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>These are not glamorous metrics, but they reflect real improvement. AI works best in testing when it improves thinking rather than replacing it.&lt;/p>
&lt;h2 id="what-it-means-for-team-leadership">What It Means for Team Leadership
&lt;/h2>&lt;p>Once AI enters the team, the role of the testing leader shifts. You are no longer responsible only for quality outcomes. You are also responsible for how thinking happens inside the team. Your behaviour matters more than your guidelines.&lt;/p>
&lt;p>If you trust AI blindly, your team will follow.&lt;/p>
&lt;p>If you avoid it entirely, so will they.&lt;/p>
&lt;p>If you use it thoughtfully and critically, they will learn to do the same.&lt;/p>
&lt;p>That is how AI gets embedded &amp;ndash; not through enforcement, but through example. In the end, leading by example is not just a good strategy; it is the only one that truly works.&lt;/p>
&lt;h2 id="conclusion">Conclusion
&lt;/h2>&lt;p>The future of testing is not about humans versus AI.&lt;/p>
&lt;p>It is about those who know how to collaborate with AI without losing their judgment.&lt;/p>
&lt;p>A strong testing team is not one that uses AI everywhere, but one that knows exactly where AI helps, where it misleads and where it should stand aside.&lt;/p>
&lt;p>Training your team for this reality is not a technical challenge but more a leadership challenge.&lt;/p>
&lt;p>A challenge we cannot ignore.&lt;/p>
&lt;hr>
&lt;p>&lt;a class="link" href="https://www.youtube.com/watch?v=R0yqDH4_C-A" target="_blank" rel="noopener"
>Generative AI for Software Testers | Revolutionize Your Testing Workflow with AI Tools&lt;/a>&lt;/p>
&lt;p>This video shows, through concrete generative AI tools, how to revolutionize the testing workflow. It works well as a supplementary reference to the idea of embedding AI into daily practice discussed in the article.&lt;/p>
&lt;p>&lt;a class="link" href="https://medium.com/@deshmukhyog86/why-you-cant-use-ai-for-testing-until-you-know-how-to-test-ai-76f3bdcc6b6f?utm_campaign=Software%2BTesting%2BWeekly&amp;amp;utm_medium=web&amp;amp;utm_source=Software_Testing_Weekly_299" target="_blank" rel="noopener"
>https://medium.com/@deshmukhyog86/why-you-cant-use-ai-for-testing-until-you-know-how-to-test-ai-76f3bdcc6b6f?utm_campaign=Software%2BTesting%2BWeekly&amp;utm_medium=web&amp;utm_source=Software_Testing_Weekly_299&lt;/a>&lt;/p></description></item><item><title>The Art of AI Evaluation</title><link>https://chengxiaqiucao.github.io/en/post/138-ai_evaluate_future/</link><pubDate>Sat, 17 Jan 2026 20:55:40 +0800</pubDate><guid>https://chengxiaqiucao.github.io/en/post/138-ai_evaluate_future/</guid><description>&lt;blockquote>
&lt;p>The original comes from the blog of &lt;a class="link" href="https://testerstories.com/author/administrator/" target="_blank" rel="noopener"
>Jeff Nyman&lt;/a>, discussing the shift in thinking and the evaluation principles we should apply to AI testing. Translated here to share.&lt;/p>&lt;/blockquote>
&lt;h2 id="beyond-the-model-itself-the-art-of-ai-evaluation">Beyond the Model Itself: The Art of AI Evaluation
&lt;/h2>&lt;p>When we talk about &amp;ldquo;AI testing&amp;rdquo;, most people first think of the large language model itself. They focus on the &amp;ldquo;engine&amp;rdquo; and overlook the &amp;ldquo;vehicle&amp;rdquo;. Yet in the context of customized enterprise applications, what we test is not just a model but a complete system.&lt;/p>
&lt;p>This is crucial! More and more enterprises rely on embedding AI into their applications. But usually they are not building a simple architecture that just lets users &amp;ldquo;chat&amp;rdquo; with a bot. Instead they are building complex architectures in which AI is only one component of a large machine. Specifically, enterprises are leveraging AI through patterns that are already very clear:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Retrieval-augmented generation (RAG):&lt;/strong> Think of it as AI&amp;rsquo;s &amp;ldquo;library&amp;rdquo;. The model no longer merely guesses from training data; before it &amp;ldquo;speaks&amp;rdquo; it is forced to look up specific company documents (the &amp;ldquo;source of truth&amp;rdquo;).&lt;/li>
&lt;li>&lt;strong>Agentic workflows:&lt;/strong> Here AI plays the role of &amp;ldquo;project manager&amp;rdquo;. It is given a goal and allowed to use tools (such as querying a SQL database, searching the web or calling an API) to complete a multi-step task.&lt;/li>
&lt;li>&lt;strong>Structured output pipelines:&lt;/strong> In this scenario AI acts as a &amp;ldquo;data translator&amp;rdquo;. It takes messy, unstructured human text and turns it into clean, executable code or JSON that other parts of the business software can understand.&lt;/li>
&lt;/ul>
&lt;p>In traditional software testing we tend to look for &amp;ldquo;decisiveness&amp;rdquo;: &amp;ldquo;if I click X, Y must happen&amp;rdquo;. In AI testing we deal with &amp;ldquo;randomness&amp;rdquo;, meaning probability-based results. Since AI may describe the same fact in three different ways, our tests cannot rely solely on finding an exact text string. We must test its intent, accuracy and logic.&lt;/p>
&lt;p>This is where the concept of the &amp;ldquo;&lt;strong>evaluator&lt;/strong>&amp;rdquo; comes in. If the LLM is a witness giving testimony, then the evaluator is the forensic expert who checks that testimony against the physical evidence. We are not testing whether the AI is &amp;ldquo;smart&amp;rdquo;; we are testing whether the system is faithful to the data and relevant to the user&amp;rsquo;s needs.&lt;/p>
&lt;h3 id="the-distinction-potential-and-reality">The Distinction: Potential and Reality
&lt;/h3>&lt;p>It is very helpful to separate the general capability of a model from its concrete application.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Model (potential):&lt;/strong> A raw LLM is a vast library of statistical probabilities. Testing it in isolation only tells you what it can do in a vacuum.&lt;/li>
&lt;li>&lt;strong>Application (reality):&lt;/strong> Your enterprise application is the &amp;ldquo;implementation layer&amp;rdquo;. It contains your prompts, your RAG pipeline and your business logic.&lt;/li>
&lt;/ul>
&lt;p>If I had to use an analogy, I would say testing a raw LLM is like testing the quality of a chef&amp;rsquo;s knife; testing an AI application is like tasting the final beef bourguignon. A sharp knife is necessary (or at least very helpful!), but it does not guarantee the stew will not be too salty.&lt;/p>
&lt;h3 id="a-broader-evaluation-scope">A Broader Evaluation Scope
&lt;/h3>&lt;p>Evaluating these AI-infused applications requires us to focus on the &amp;ldquo;three pillars&amp;rdquo; of output quality in that context:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Answer relevancy:&lt;/strong> Does the reply actually address the user&amp;rsquo;s intent, or is it just a &amp;ldquo;hallucination&amp;rdquo; that sounds right but is in fact irrelevant?&lt;/li>
&lt;li>&lt;strong>Faithfulness:&lt;/strong> Is the answer strictly derived from the provided context (the &amp;ldquo;source of truth&amp;rdquo;), or did the model draw on external, possibly outdated training data?&lt;/li>
&lt;li>&lt;strong>Context precision:&lt;/strong> How well does the system perform when it first retrieves the correct information?&lt;/li>
&lt;/ol>
&lt;h3 id="llm-as-a-judge">&amp;ldquo;LLM-as-a-Judge&amp;rdquo;
&lt;/h3>&lt;p>To handle these problems at scale we can use dedicated tools such as DeepEval or RAGAS. These tools adopt a meta-cognitive approach usually called &amp;ldquo;LLM-as-a-Judge&amp;rdquo;. Frankly, I am not sure that is a good name. I prefer to think of it as &amp;ldquo;forensic examination&amp;rdquo; of a conversation.&lt;/p>
&lt;p>What I mean is that we use a secondary, usually more powerful model to act as an objective evaluator. It looks at the &amp;ldquo;evidence&amp;rdquo; (the retrieved context) and the &amp;ldquo;verdict&amp;rdquo; (the generated answer) to determine whether the logic holds up. This lets us turn qualitative human intuition into quantitative, reproducible metrics such as context recall and answer correctness.&lt;/p>
&lt;h2 id="setting-the-stage">Setting the Stage
&lt;/h2>&lt;p>I have a lot more to say on this topic, but here I want to &amp;ldquo;show&amp;rdquo; rather than merely &amp;ldquo;tell&amp;rdquo;. What I can say is that we are moving from a world of &amp;ldquo;testing by feel&amp;rdquo; (where we just ask the AI a few questions and see whether we like the answers) towards a world with rigorous evaluators. You may not be testing the LLM directly, but you are testing the governance of a given model&amp;rsquo;s power within a specific domain.&lt;/p>
&lt;p>I think that, for test experts working with companies that have chosen to make AI part of their operations (whether customer-facing or not), this largely constitutes their ethical mission.&lt;/p>
&lt;p>As for my own leaning, I am a Thomist. In Thomist terms, the LLM is the &amp;ldquo;material cause&amp;rdquo; (raw potential), while your application is the &amp;ldquo;formal cause&amp;rdquo; that gives it a specific shape and purpose. Testing only the LLM is like studying the properties of marble when you should be assessing the structural integrity of the cathedral built from it.&lt;/p>
&lt;p>So, to set up what is coming, this series will introduce the concepts and tools that help us &amp;ldquo;examine the cathedral&amp;rdquo;. It requires the reader to dig in a little. I will use Python mostly (or entirely), and show testers how to actually use these tools in combination with these broader concepts.&lt;/p>
&lt;p>I should point out that I consider this a completely empty area of modern testing. I see many people voicing concern about AI (perhaps legitimately), but very few actually learning how to use these tools to improve their market competitiveness in this future that has already arrived.&lt;/p>
&lt;p>I have talked before about the ethical mission of the &amp;ldquo;error expert&amp;rdquo;. As everyone knows, AI makes mistakes. In fact, Claude tells you so right at the bottom of any prompt you submit.
&lt;img src="https://chengxiaqiucao.github.io/post/138-ai_evaluate_future/Pasted-20260117_hu_262344bad33f57bd.webp"
width="1024"
height="195"
srcset="https://chengxiaqiucao.github.io/post/138-ai_evaluate_future/Pasted-20260117_hu_9d6ee5a453217829.webp 480w, https://chengxiaqiucao.github.io/post/138-ai_evaluate_future/Pasted-20260117_hu_262344bad33f57bd.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="526"
data-flex-basis="1262px"
>
&lt;/p>
&lt;p>ChatGPT does the same.
&lt;img src="https://chengxiaqiucao.github.io/post/138-ai_evaluate_future/Pasted-20260117-1_hu_f02e0153ec4b37ec.webp"
width="1024"
height="209"
srcset="https://chengxiaqiucao.github.io/post/138-ai_evaluate_future/Pasted-20260117-1_hu_8a605b5bcfaf5830.webp 480w, https://chengxiaqiucao.github.io/post/138-ai_evaluate_future/Pasted-20260117-1_hu_f02e0153ec4b37ec.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="489"
data-flex-basis="1173px"
>
&lt;/p>
&lt;p>That is great! Self-awareness is a good thing. But it leaves an open question: how do we &amp;ldquo;double-check replies&amp;rdquo; and &amp;ldquo;verify important information&amp;rdquo; at scale? For testers who want to stay ahead, this is a superb patch of ground.&lt;/p>
&lt;p>So our ethical mission has not been removed or replaced; it has actually expanded. As &amp;ldquo;error experts&amp;rdquo;, our area of focus grows with it.&lt;/p>
&lt;p>&lt;a class="link" href="https://testerstories.com/2026/01/ai-and-testing-ollama-and-models/" target="_blank" rel="noopener"
>https://testerstories.com/2026/01/ai-and-testing-ollama-and-models/&lt;/a>&lt;/p></description></item><item><title>A Handy Tool for Quickly Making Sense of Open-Source Project Code, This AI Tool Is a Must-Know!</title><link>https://chengxiaqiucao.github.io/en/post/114-zread_ai/</link><pubDate>Mon, 28 Jul 2025 16:50:34 +0800</pubDate><guid>https://chengxiaqiucao.github.io/en/post/114-zread_ai/</guid><description>&lt;img src="https://chengxiaqiucao.github.io/post/114-zread_ai/title.webp" alt="Featured image of post A Handy Tool for Quickly Making Sense of Open-Source Project Code, This AI Tool Is a Must-Know!" />&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/114-zread_ai/title_hu_1cdde587fbb134be.webp"
width="1024"
height="515"
srcset="https://chengxiaqiucao.github.io/post/114-zread_ai/title_hu_1b32f0db2922ce80.webp 480w, https://chengxiaqiucao.github.io/post/114-zread_ai/title_hu_1cdde587fbb134be.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="198"
data-flex-basis="477px"
>
&lt;/p>
&lt;p>In a previous article, we analyzed the source code of the popular AI testing tool &lt;code>Midscene.js&lt;/code>, focusing on how its main prompts for driving AI execution are set. (See that article 【】)&lt;/p>
&lt;p>Recently, I discovered another AI gem, a source-code analysis service launched by &lt;code>Zhipu AI&lt;/code>, accessible at&lt;/p>
&lt;p>&lt;code>https://zread.ai/&lt;/code>&lt;/p>
&lt;p>As a product of a Chinese company, it offers excellent support for Chinese.&lt;/p>
&lt;h2 id="using-the-tool">Using the Tool
&lt;/h2>&lt;p>After visiting the homepage, you&amp;rsquo;ll see a typical AI application interface.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/114-zread_ai/Pasted-20250728-2_hu_e22f73133e189ea1.webp"
width="1024"
height="516"
srcset="https://chengxiaqiucao.github.io/post/114-zread_ai/Pasted-20250728-2_hu_bbd5d6504c8a4a5e.webp 480w, https://chengxiaqiucao.github.io/post/114-zread_ai/Pasted-20250728-2_hu_e22f73133e189ea1.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="198"
data-flex-basis="476px"
>
&lt;/p>
&lt;p>We simply enter the GitHub address of the source-code project we want to analyze into the search box. If the project has already been indexed, pressing Enter will display an overview card for the project.&lt;/p>
&lt;p>Or more directly, we can replace &lt;code>github.com&lt;/code> in the source address with &lt;code>zread.ai&lt;/code>. For example, to analyze the &lt;code>Playwright&lt;/code> project, just visit the following address:&lt;/p>
&lt;p>&lt;code>https://zread.ai/microsoft/playwright&lt;/code>&lt;/p>
&lt;p>The analysis page is very comprehensive, covering installation and deployment, architecture analysis, core modules, and more. The figure below shows the &lt;code>Playwright&lt;/code> architecture analysis page.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/114-zread_ai/Pasted-20250728-4_hu_57ae936c071245c2.webp"
width="1024"
height="493"
srcset="https://chengxiaqiucao.github.io/post/114-zread_ai/Pasted-20250728-4_hu_9707a7801120c596.webp 480w, https://chengxiaqiucao.github.io/post/114-zread_ai/Pasted-20250728-4_hu_57ae936c071245c2.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="207"
data-flex-basis="498px"
>
&lt;/p>
&lt;p>Through the index-generated analysis, we can quickly understand the full picture of an open-source project, along with its core usage and key points.&lt;/p>
&lt;h2 id="further-empowerment-with-ai">Further Empowerment with AI
&lt;/h2>&lt;p>Beyond the tool&amp;rsquo;s own indexing and analysis of source code, with its built-in large-model integration we can go further and conduct targeted, in-depth analysis of a project to understand its specific details.&lt;/p>
&lt;p>We can use its &lt;code>Ask AI&lt;/code> feature to communicate deeply with the AI.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/114-zread_ai/Pasted-20250728-3_hu_c3ed62dadde1d7b6.webp"
width="1024"
height="596"
srcset="https://chengxiaqiucao.github.io/post/114-zread_ai/Pasted-20250728-3_hu_4585deb6459a4adf.webp 480w, https://chengxiaqiucao.github.io/post/114-zread_ai/Pasted-20250728-3_hu_c3ed62dadde1d7b6.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="171"
data-flex-basis="412px"
>
&lt;/p>
&lt;p>For example, below is a summary I asked it to put together of the key updates and applications in the last four versions of Playwright.&lt;/p>
&lt;hr>
&lt;p>The important feature updates in the latest four versions of Playwright (1.53, 1.52, 1.51, and 1.50) are as follows:&lt;/p>
&lt;h2 id="version-153">Version 1.53
&lt;/h2>&lt;ol>
&lt;li>
&lt;p>&lt;strong>Trace Viewer and HTML Reporter updates&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Added a test-step display feature, making the test execution process clearer and more visible&lt;/li>
&lt;li>The HTML reporting tool added a custom test-run title option, making it easier to distinguish different test runs&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">reporter: [[&amp;#39;html&amp;#39;, { title: &amp;#39;Custom test run #1028&amp;#39; }]]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;li>
&lt;p>&lt;strong>New Locator.describe method&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Allows adding descriptive information to a locator, displayed in the trace viewer and reports to improve test readability&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-gdscript3" data-lang="gdscript3">&lt;span class="line">&lt;span class="cl">&lt;span class="k">const&lt;/span> &lt;span class="n">button&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">getByTestId&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;btn-sub&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">describe&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;Subscribe button&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="n">await&lt;/span> &lt;span class="n">button&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">click&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;li>
&lt;p>&lt;strong>Browser version upgrades&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Chromium 138.0.7204.4&lt;/li>
&lt;li>Firefox 139.0&lt;/li>
&lt;li>WebKit 18.5&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;h2 id="version-152">Version 1.52
&lt;/h2>&lt;ol>
&lt;li>
&lt;p>&lt;strong>New assertion method toContainClass&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Simplifies assertions on element class names&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">await expect(page.getByRole(&amp;#39;listitem&amp;#39;)).toContainClass(&amp;#39;done&amp;#39;);
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;li>
&lt;p>&lt;strong>Aria snapshot enhancements&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Added the &lt;code>/children&lt;/code> attribute for strict matching&lt;/li>
&lt;li>Added the &lt;code>/url&lt;/code> attribute for link verification&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Test project configuration improvements&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Added the &lt;code>workers&lt;/code> property to control the number of concurrent worker processes for a test project&lt;/li>
&lt;li>Added the &lt;code>failOnFlakyTests&lt;/code> option to ensure all tests run stably in CI/CD environments&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Important changes&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Glob URL patterns no longer support &lt;code>?&lt;/code> and &lt;code>[]&lt;/code>; regular expressions are recommended instead&lt;/li>
&lt;li>&lt;code>Route.continue&lt;/code> no longer allows overriding the &lt;code>Cookie&lt;/code> header; use &lt;code>BrowserContext.addCookies&lt;/code> instead&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;h2 id="version-151">Version 1.51
&lt;/h2>&lt;ol>
&lt;li>
&lt;p>&lt;strong>IndexedDB storage state management&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Added support for saving and restoring IndexedDB content, useful for applications using services like Firebase Authentication&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">await page.context().storageState({ path: authFile, indexedDB: true });
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;li>
&lt;p>&lt;strong>Enhanced error messages - &amp;ldquo;Copy as prompt&amp;rdquo;&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Errors in the HTML report, trace viewer, and UI mode now have a &amp;ldquo;Copy prompt&amp;rdquo; button&lt;/li>
&lt;li>One-click copy of a pre-filled LLM prompt containing the error message and helpful context&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Visible element filtering&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>The &lt;code>Locator.filter&lt;/code> method gained a &lt;code>visible&lt;/code> option to match only visible elements&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-gdscript3" data-lang="gdscript3">&lt;span class="line">&lt;span class="cl">&lt;span class="k">const&lt;/span> &lt;span class="n">todoItems&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">getByTestId&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;todo-item&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">filter&lt;/span>&lt;span class="p">({&lt;/span> &lt;span class="n">visible&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="bp">true&lt;/span> &lt;span class="p">});&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;li>
&lt;p>&lt;strong>Git information integration&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Added the &lt;code>captureGitInfo&lt;/code> configuration to show Git commit and diff information in the HTML report&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;h2 id="version-150">Version 1.50
&lt;/h2>&lt;ol>
&lt;li>
&lt;p>&lt;strong>Test step improvements&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Added a &lt;code>test.step&lt;/code> timeout option to set a maximum runtime for individual steps&lt;/li>
&lt;li>Added the &lt;code>test.step.skip&lt;/code> method to disable execution of specific test steps&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">await test.step(&amp;#39;a step&amp;#39;, async () =&amp;gt; { // this step can have its own timeout independent of the test}, { timeout: 1000 });
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;li>
&lt;p>&lt;strong>Accessibility testing enhancements&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Extended the &lt;code>toMatchAriaSnapshot&lt;/code> method to allow storing snapshots in separate YAML files&lt;/li>
&lt;li>Added the &lt;code>toHaveAccessibleErrorMessage&lt;/code> assertion for verifying an element&amp;rsquo;s aria error message&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Snapshot update strategy improvements&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Added the &lt;code>changed&lt;/code> option for &lt;code>updateSnapshots&lt;/code> to update only changed snapshots&lt;/li>
&lt;li>Added the &lt;code>updateSourceMethod&lt;/code> option to define how source code is updated, adding &lt;code>overwrite&lt;/code> and &lt;code>3-way&lt;/code> modes&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>UI updates&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Improved attachment display in the HTML report&lt;/li>
&lt;li>Codegen added an element-picker button for generating aria snapshots&lt;/li>
&lt;li>Added detailed information about API calls into the trace display&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;p>These updates together improve Playwright&amp;rsquo;s testing capabilities, debugging experience, and reporting features, making test automation more reliable and efficient.&lt;/p>
&lt;h2 id="proactive-indexing-and-private-repositories">Proactive Indexing and Private Repositories
&lt;/h2>&lt;p>Besides popular open-source projects that Zread has already indexed in advance, some newer or personal projects may not yet have been indexed; entering the project address lets you proactively start indexing, and analysis completes after a short wait.&lt;/p>
&lt;p>For example, below is a test practice project I open-sourced a while ago, with indexing triggered proactively.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/114-zread_ai/Pasted-20250728_hu_36c99b58bdefc521.webp"
width="1024"
height="652"
srcset="https://chengxiaqiucao.github.io/post/114-zread_ai/Pasted-20250728_hu_8ab561e873b2c736.webp 480w, https://chengxiaqiucao.github.io/post/114-zread_ai/Pasted-20250728_hu_36c99b58bdefc521.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="157"
data-flex-basis="376px"
>
&lt;/p>
&lt;p>Soon I got a complete introduction and core code analysis for this project.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/114-zread_ai/Pasted-20250728-1_hu_75a4762ac139fee9.webp"
width="1024"
height="522"
srcset="https://chengxiaqiucao.github.io/post/114-zread_ai/Pasted-20250728-1_hu_12610e5e1ba4f762.webp 480w, https://chengxiaqiucao.github.io/post/114-zread_ai/Pasted-20250728-1_hu_75a4762ac139fee9.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="196"
data-flex-basis="470px"
>
&lt;/p>
&lt;p>For some non-public private repositories, you can also grant code-read permission to &lt;code>Zread.ai&lt;/code> through authorization to achieve the same goal.&lt;/p>
&lt;h2 id="conclusion">Conclusion
&lt;/h2>&lt;p>In short, this tool is absolutely a powerful assistant for quickly understanding an open-source project, and I highly recommend it~~&lt;/p></description></item><item><title>A New Trend in Using AI - From Prompt Engineering to Context Engineering</title><link>https://chengxiaqiucao.github.io/en/post/111-context_engineering/</link><pubDate>Mon, 14 Jul 2025 15:58:57 +0800</pubDate><guid>https://chengxiaqiucao.github.io/en/post/111-context_engineering/</guid><description>&lt;h2 id="preface">Preface
&lt;/h2>&lt;p>With the explosion of large AI models, &lt;strong>prompt engineering&lt;/strong> was once the most important and most essential technique for users to apply AI and bring its capabilities into play. But now, building on &amp;ldquo;prompt engineering,&amp;rdquo; a broader and more powerful evolved concept has been proposed—the &amp;ldquo;&lt;strong>Context Engineering&lt;/strong>&amp;rdquo; we are introducing in this article.&lt;/p>
&lt;p>Especially this year, with the explosion of AI Agents, when applying AI it has become increasingly important to effectively pass the right information into AI&amp;rsquo;s &amp;ldquo;limited memory space.&amp;rdquo; Very often, poor results from calling an AI Agent are not due to any weakness of the large model itself, but rather to a deficiency in the quality of the &lt;strong>context&lt;/strong>.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/111-context_engineering/Pasted-20250715-1_hu_ccc62d617b0cf5b4.webp"
width="1024"
height="555"
srcset="https://chengxiaqiucao.github.io/post/111-context_engineering/Pasted-20250715-1_hu_99f3f429464100d3.webp 480w, https://chengxiaqiucao.github.io/post/111-context_engineering/Pasted-20250715-1_hu_ccc62d617b0cf5b4.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="184"
data-flex-basis="442px"
>
&lt;/p>
&lt;h2 id="the-limitations-of-prompt-engineering">The Limitations of Prompt Engineering
&lt;/h2>&lt;p>&lt;strong>Prompt engineering&lt;/strong> can improve a model&amp;rsquo;s output quality by optimizing the text fed into the model.&lt;/p>
&lt;p>But as more and more Agents join in and application scenarios grow increasingly complex, relying on prompts alone makes it ever harder for large models to effectively complete increasingly complex tasks.&lt;/p>
&lt;p>For example, to build an AI-powered intelligent test case system, the following information is also needed in the process of using the large model:&lt;/p>
&lt;ul>
&lt;li>The original requirements documents and interface (API) documentation&lt;/li>
&lt;li>The system&amp;rsquo;s architectural design, database, and system framework&lt;/li>
&lt;li>The status of the various application interfaces&lt;/li>
&lt;li>Invocations of external tools such as test case management, document management, and automated testing&lt;/li>
&lt;/ul>
&lt;p>These requirements can hardly be fulfilled merely by passing prompts to the large model and its corresponding Agent.&lt;/p>
&lt;p>This is the greatest limitation of prompt engineering: &lt;strong>the lack of context understanding and state management capabilities&lt;/strong>.&lt;/p>
&lt;h2 id="what-is-context-engineering">What Is Context Engineering?
&lt;/h2>&lt;p>To understand &amp;ldquo;context engineering,&amp;rdquo; we must first clarify what &lt;strong>context&lt;/strong> is.&lt;/p>
&lt;p>Compared with a prompt, &lt;strong>context&lt;/strong> is not merely the single prompt we pass to the large model; it can be understood as &lt;strong>everything the large model sees before it returns a result&lt;/strong>.&lt;/p>
&lt;p>In summary, &lt;strong>context&lt;/strong> includes the following:&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/111-context_engineering/Pasted-20250714_hu_dc08a81cedc8595b.webp"
width="1024"
height="849"
srcset="https://chengxiaqiucao.github.io/post/111-context_engineering/Pasted-20250714_hu_960680e037ad5d36.webp 480w, https://chengxiaqiucao.github.io/post/111-context_engineering/Pasted-20250714_hu_dc08a81cedc8595b.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="120"
data-flex-basis="289px"
>
&lt;/p>
&lt;h3 id="background--system-prompt-instructions--system-prompt">Background / System Prompt (**Instructions / System Prompt)
&lt;/h3>&lt;p>This is the initial agreement between the user and the large model throughout the entire session. It includes the agreed background, the role the model plays, its expected behavior, and so on. It can be constrained through some examples and rule definitions.&lt;/p>
&lt;p>For example, in the AI-based test case generation tool we introduced earlier, the system prompt might specify&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl">你是一个资深测试开发专家，负责根据用户提供的接口文档，调用本地配置的AI大模型，生成一组详细的测试用例。
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">你需要确保每个测试用例都具有明确的目标、输入参数、预期结果。
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">请按照指定格式输出JSON数组，每个条目包括：
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- test_case_id: 测试用例编号
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- description: 测试描述
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- input_params: 输入参数
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- expected_output: 预期输出
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- priority: 优先级（1-5）
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="user-prompt">User Prompt
&lt;/h3>&lt;p>The user prompt, in contrast to the system prompt which applies to the entire session, is the instruction or question the user currently gives to the large model.&lt;/p>
&lt;p>It is in fact the main application of prompt engineering mentioned earlier—by optimizing how user prompts are written, one can communicate more effectively with AI.&lt;/p>
&lt;p>As in the example above, in the process of AI-assisted development, it is the specific development task we submit to AI.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl">根据之前生成的项目代码结构，完成数据库创建部分的脚本，并注入部分调试数据。
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="state-and-conversation-history-short-term-memory">State and Conversation History (Short-Term Memory)
&lt;/h3>&lt;p>This mainly refers to the conversation history and the intermediate results generated during the current session.&lt;/p>
&lt;p>For example, during script development, the completed code files, the errors that appear when the program runs, and other such information.&lt;/p>
&lt;h3 id="long-term-memory">Long-Term Memory
&lt;/h3>&lt;p>This contains more durable background knowledge, including information collected from multiple previous conversations, such as learned user preferences, summaries of past projects, or information provided by the user for future use.&lt;/p>
&lt;p>As in the development process above, this includes the project&amp;rsquo;s requirements documents, architectural design, database structure, test data, and other information.&lt;/p>
&lt;h3 id="rag-retrieval-augmented-generation">RAG (Retrieval-augmented generation)
&lt;/h3>&lt;p>RAG provides the model with additional relevant information through vector databases, knowledge base retrieval, and other means. It enables the model to consult the latest, relevant context when answering questions, instead of relying on knowledge from its training.&lt;/p>
&lt;h3 id="structured-output">Structured Output
&lt;/h3>&lt;p>To make model output more controllable and parseable, and easier for Agents to handle, we usually need to define an output format—such as a JSON Schema or a specific field structure—to improve result consistency.&lt;/p>
&lt;p>For example, the system prompt above explicitly requires the model to output a JSON object containing the relevant fields.&lt;/p>
&lt;h3 id="available-tools">Available Tools
&lt;/h3>&lt;p>Through Agents or MCP, the large model can invoke tool capabilities, such as automated testing tools (Playwright), CI/CD continuous integration systems, and so on.&lt;/p>
&lt;h2 id="the-keys-to-using-context-engineering">The Keys to Using Context Engineering
&lt;/h2>&lt;p>✅ Context is not a string, but a system&lt;/p>
&lt;p>Context is system logic that runs before the LLM call; it dynamically assembles all relevant information rather than being a static template.&lt;/p>
&lt;p>✅ Context is dynamic&lt;/p>
&lt;p>Before each LLM call, context must be dynamically prepared according to the current task—for example, injecting the current date, user preferences, project configuration, and so on.&lt;/p>
&lt;p>✅ Context emphasizes the precise matching of information and tools&lt;/p>
&lt;p>One cannot simply pile up information; instead, the most relevant knowledge and capabilities must be provided at the right time. For example, inject a database connection tool only when it is needed.&lt;/p>
&lt;p>✅ Format determines output quality&lt;/p>
&lt;p>How information is presented matters. A concise summary is better than raw data, and a clear tool schema is more useful than vague instructions.&lt;/p>
&lt;h2 id="conclusion">Conclusion
&lt;/h2>&lt;p>The tech industry produces new terms and new concepts every so often, and we have grown used to it. Although &amp;ldquo;&lt;strong>Context Engineering&lt;/strong>&amp;rdquo; differs from &amp;ldquo;&lt;strong>prompt engineering&lt;/strong>&amp;rdquo; at the conceptual level, their starting point and goal are in fact the same—to enable more effective communication between users and AI. In essence, this is in line with the explanation in our earlier article【】.&lt;/p>
&lt;p>It is not really a brand-new technology; we can simply understand it as a technique for using AI!&lt;/p></description></item><item><title>Collaborating with AI, the Focus Is Still Communication — A Detailed Look at Communicating with AI More Effectively</title><link>https://chengxiaqiucao.github.io/en/post/106-%E5%92%8Cai%E6%B2%9F%E9%80%9A/</link><pubDate>Wed, 02 Jul 2025 21:46:47 +0800</pubDate><guid>https://chengxiaqiucao.github.io/en/post/106-%E5%92%8Cai%E6%B2%9F%E9%80%9A/</guid><description>&lt;img src="https://chengxiaqiucao.github.io/post/106-%E5%92%8Cai%E6%B2%9F%E9%80%9A/logo.webp" alt="Featured image of post Collaborating with AI, the Focus Is Still Communication — A Detailed Look at Communicating with AI More Effectively" />&lt;h2 id="preface">Preface
&lt;/h2>&lt;p>In my previous article 【】, we explored the central role of communication in team collaboration. Nowadays AI is being applied ever more broadly; in particular, the powerful capabilities of generative AI mean that a great deal of work can actually be accomplished with AI&amp;rsquo;s help. From AI browsers and coding assistants to workflow engines and integrations with various MCPs, AI is increasingly participating in our daily work.&lt;/p>
&lt;p>And completing work with the help of AI is, in essence, another form of team collaboration — except that here the collaborator is AI. So in collaborating with AI, the core is still communication.&lt;/p>
&lt;p>From this perspective, this article considers how to communicate and collaborate with AI more effectively.&lt;/p>
&lt;h2 id="the-johari-communication-window">The Johari Communication Window
&lt;/h2>&lt;p>In team collaboration, there is an important model and tool — the &lt;strong>Johari Communication Window&lt;/strong> we introduced earlier.&lt;/p>
&lt;p>In this window, we divide things into four quadrants according to the level of awareness held by the communication partner and by ourselves. Only by understanding which quadrant each party is in during a conversation can we communicate well.&lt;/p>
&lt;p>When we collaborate with AI, we can likewise define such a communication-window model:&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/106-%E5%92%8Cai%E6%B2%9F%E9%80%9A/Pasted-20250705_hu_fa7e7a47cfd5e8d.webp"
width="1024"
height="577"
srcset="https://chengxiaqiucao.github.io/post/106-%E5%92%8Cai%E6%B2%9F%E9%80%9A/Pasted-20250705_hu_148d14c4245577f9.webp 480w, https://chengxiaqiucao.github.io/post/106-%E5%92%8Cai%E6%B2%9F%E9%80%9A/Pasted-20250705_hu_fa7e7a47cfd5e8d.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="177"
data-flex-basis="425px"
>
&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Open Zone&lt;/strong> — this area corresponds to information that both we and AI already possess and understand; it can be considered the shared ground between the two sides. For example, when communicating with AI we often preset a role or identity for it — such instructions belong to the Open Zone. Or, having already drafted an article, we ask AI to polish it on that basis. Both are typical examples of communicating in the Open Zone.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Blind Spot Zone&lt;/strong> — here is information we do not possess ourselves, but which AI, with its rich knowledge base, can provide to us. In this area AI is like a teacher — but a passive one, relying on us to ask questions actively to obtain knowledge. The ability to ask good questions is the key to communicating in this zone.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Unknown Zone&lt;/strong> — this area covers information that we are unclear about and that AI has not yet mastered. Communication in this zone is more like co-creating with AI — brainstorming together to explore information in unknown territory.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Hidden Zone&lt;/strong> — in this area, the information is mostly our private-domain information that AI cannot access on its own. For instance, if we simply give AI the instruction &lt;code>please help me output this week's work report&lt;/code>, AI has no way to start. So communication in this area means fully providing AI with the contextual information it needs — feeding private-domain information to AI. Things like project background, internal processes, and local data from our work — only once AI has learned and mastered this information can it go on to assist with subsequent tasks.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="communication-techniques-for-ai-in-different-quadrants">Communication Techniques for AI in Different Quadrants
&lt;/h2>&lt;p>Based on the four distinct zones defined by the window model above, we can think about the key points of communication when collaborating with AI — that is, how to use prompts better so that AI delivers results more closely aligned with our needs.&lt;/p>
&lt;h3 id="communicating-in-the-open-zone">Communicating in the Open Zone
&lt;/h3>&lt;p>In this zone, because both sides already hold the relevant information, the main thing is to make the boundaries of the Open Zone clear to AI. The clearer and more specific the information you specify, the more closely AI&amp;rsquo;s results will match our needs. So in this zone, what matters more is issuing &lt;strong>clear tasks&lt;/strong>. You should also avoid gilding the lily — vague prompt instructions can instead cause the results to diverge.&lt;/p>
&lt;p>For example:&lt;/p>
&lt;p>&lt;code>You are a senior software test engineer, proficient in test automation, familiar with Python, and familiar with various testing tools.&lt;/code>&lt;/p>
&lt;p>&lt;code>Accurately translate the English document in the attachment and return the translated content in Markdown format, without including any information that is not part of the target content&lt;/code> is better than &lt;code>Translate the attached English document in a witty, lively style that rides current internet trends&lt;/code> — it preserves the key points of the original content without adding a lot of extra material that may not be appropriate, and the returned content can be generated directly in the format we need.&lt;/p>
&lt;h3 id="communicating-in-the-blind-spot-zone">Communicating in the Blind Spot Zone
&lt;/h3>&lt;p>The Blind Spot Zone is the area where leveraging AI&amp;rsquo;s capabilities can most easily help us improve ourselves. Through AI, we fill gaps in our knowledge and eliminate our blind spots.&lt;/p>
&lt;p>In this area, the key to communicating efficiently with AI is the ability to ask questions. For relatively complex information, we can proceed step by step, asking progressive questions, so that AI gradually builds a complete knowledge system, identifies our blind spots, and strengthens them. In prompt engineering, there is a dedicated technical term for this — &lt;strong>Chain-of-Thought (COT)&lt;/strong> — which can guide AI to think progressively and step by step to arrive at the knowledge we truly need.&lt;/p>
&lt;p>For this, you can also refer to the &lt;strong>5 Whys technique&lt;/strong> we introduced earlier, gradually focusing on the root cause of a problem.&lt;/p>
&lt;p>For example, if we want to master the POM model in test automation and actually solve specific problems in implementation, we can ask questions step by step to focus on solving real problems:&lt;/p>
&lt;ul>
&lt;li>&lt;code>What is the POM model?&lt;/code>&lt;/li>
&lt;li>&lt;code>In which scenarios of test automation is the POM model more suitable?&lt;/code>&lt;/li>
&lt;li>&lt;code>For the login scenario of a web portal site such as www.saucedemo.com, give an example of implementing POM in Python and explain the key points&lt;/code>&lt;/li>
&lt;li>&lt;code>In the above example, what other general approaches are suitable for unified encapsulation, such as element identification and driver definition?&lt;/code>&lt;/li>
&lt;/ul>
&lt;h3 id="communicating-in-the-unknown-zone">Communicating in the Unknown Zone
&lt;/h3>&lt;p>The Unknown Zone is content that neither we nor AI has mastered. This is more about innovative scenarios, where through continuous iteration and brainstorming with AI we gradually discover what we truly need.&lt;/p>
&lt;p>For example, when using an AI coding assistant to help develop an application, we may only have sketched out the basic functions. AI will help generate the application interface based on the information provided, and we in turn will have further ideas for improvement based on that interface. Through such continuous communication and iteration, we ultimately complete a software product with good usability.&lt;/p>
&lt;p>So the emphasis of communication here is &lt;strong>co-innovation and continuous iteration&lt;/strong>.&lt;/p>
&lt;h3 id="communicating-in-the-hidden-zone">Communicating in the Hidden Zone
&lt;/h3>&lt;p>The Hidden Zone is beyond the reach of AI&amp;rsquo;s current capabilities; it often has to be completed based on internal information and local data. To make good use of AI in such cases, we need to build a sufficiently informative context — feeding our local information and data to AI, letting it digest them, and making up for the part of the information it does not know. Once communication moves from the Hidden Zone to the Open Zone, we can issue clear tasks to have things handled.&lt;/p>
&lt;p>The key to communication in this area is actually to give AI the ability to reach knowledge blind spots through approaches such as RAG, model fine-tuning, building a local knowledge base, or exposing local capability calls via MCP.&lt;/p>
&lt;p>The focus of communication in this area is to fully provide AI with background and related information it does not yet understand, so that after &lt;strong>feeding and digesting information&lt;/strong> the purpose of normal collaboration can be achieved.&lt;/p>
&lt;h2 id="conclusion">Conclusion
&lt;/h2>&lt;p>When we want to treat AI as a collaborator that can genuinely help us, we should establish good communication with that collaborator. The Johari Window provides a sound communication model that can offer good guidance in helping us make effective use of AI.&lt;/p>
&lt;hr></description></item><item><title>Will MCP Fail? Questions About MCP</title><link>https://chengxiaqiucao.github.io/en/post/105-mcp_must_fail/</link><pubDate>Sun, 29 Jun 2025 21:25:34 +0800</pubDate><guid>https://chengxiaqiucao.github.io/en/post/105-mcp_must_fail/</guid><description>&lt;img src="https://chengxiaqiucao.github.io/post/105-mcp_must_fail/Pasted-20250629.webp" alt="Featured image of post Will MCP Fail? Questions About MCP" />&lt;blockquote>
&lt;p>&lt;strong>Model-Context Protocol (MCP&lt;/strong> has attracted widespread attention and rapid adoption since its launch. A large number of AI tools now support MCP. (For a detailed introduction to MCP, see my previous article【】) But as MCP has risen to prominence, doubts about it have gradually begun to emerge—for example, concerns about its security limitations (see my previous article【】). Recently, Edgenesis founder Yongli, Chen also published an article arguing that MCP is destined to fail. Here I have organized his main points into this article (see the link at the end for the original), so that you may use them as a reference and form your own judgment.&lt;/p>&lt;/blockquote>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/105-mcp_must_fail/Pasted-20250629_hu_e9f2634ec35fe931.webp"
width="1024"
height="576"
srcset="https://chengxiaqiucao.github.io/post/105-mcp_must_fail/Pasted-20250629_hu_5d057b90ccc7264f.webp 480w, https://chengxiaqiucao.github.io/post/105-mcp_must_fail/Pasted-20250629_hu_e9f2634ec35fe931.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="177"
data-flex-basis="426px"
>
&lt;/p>
&lt;h2 id="introduction">Introduction
&lt;/h2>&lt;p>&lt;strong>Model-Context Protocol (MCP)&lt;/strong> has been in the spotlight since its very inception. It has been hailed as a universal standard aimed at seamless integration between artificial intelligence (AI) models and all kinds of software tools. On the surface, the protocol does address a genuine industry pain point: &lt;strong>replacing today&amp;rsquo;s chaotic jumble of custom application programming interfaces (APIs) and proprietary plugins with one simple, standard solution&lt;/strong>. MCP&amp;rsquo;s proponents paint a future in which AI agents can effortlessly connect to countless applications without tedious custom integration.&lt;/p>
&lt;p>Yet for all its technical elegance and the enormous attention it drew early on, MCP is destined to struggle. This is not due to any technical defect, but because it fundamentally misunderstands a crucial economic reality: in the digital business landscape, end-user attention is the key to commercial success.&lt;/p>
&lt;p>Every company will go to great lengths to guard user attention, because it is their primary source of monetization. Tool vendors therefore simply cannot afford the price of reducing themselves to mere backend functions by adopting MCP across the board.&lt;/p>
&lt;h2 id="the-real-battleground---ownership-of-attention">The Real Battleground - Ownership of Attention
&lt;/h2>&lt;p>To understand why MCP faces resistance, we must first consider a basic fact: &lt;strong>whoever controls the user interface controls the user relationship&lt;/strong>. A company that owns the interface thereby owns user engagement, data, and the revenue opportunities that arise from them. Services relegated to the backend, by contrast, become freely replaceable commodities—not only easy to substitute, but also stripped of any direct contact with their customers.&lt;/p>
&lt;p>History has repeatedly proved this law. Facebook, for example, built its business empire precisely by turning third-party applications into pure content providers. The early social-gaming giant Zynga learned this lesson the hard way. When Facebook changed its platform rules and tightened restrictions, the visibility of Zynga&amp;rsquo;s games plummeted. Zynga&amp;rsquo;s fate was sealed, because Facebook held a firm grip on user attention and thus dictated Zynga&amp;rsquo;s revenue and customer interaction.&lt;/p>
&lt;p>Similarly, Twitter blocked third-party clients because these clients allowed users to bypass Twitter&amp;rsquo;s advertising system, which amounted to &amp;ldquo;stealing&amp;rdquo; the platform&amp;rsquo;s user attention. Apple&amp;rsquo;s attitude toward web apps is another highly persuasive example: for years, Apple deliberately limited the functionality of web apps on iOS to ensure that native apps in the App Store stayed dominant, thereby preserving Apple&amp;rsquo;s direct relationship with users and its revenue streams.&lt;/p>
&lt;h2 id="mcps-naive-proposal">MCP&amp;rsquo;s Naive Proposal
&lt;/h2>&lt;p>MCP is, in effect, asking software vendors to voluntarily accept a new model: &lt;strong>turning their core functionality into simple backend services accessed primarily through AI-driven interfaces&lt;/strong>.&lt;/p>
&lt;p>Imagine a future in which booking a trip is done entirely through an AI assistant that interacts invisibly behind the scenes with airlines, hotels, and travel agencies via MCP. In this model, the interface—the point of user contact and decision-making—belongs entirely to the AI assistant, leaving the vendors unable to reach user attention directly.&lt;/p>
&lt;p>This effectively demotes vendors from &amp;ldquo;destinations&amp;rdquo; with differentiated brands and customer loyalty to standardized &amp;ldquo;utilities.&amp;rdquo; Such a shift would seriously threaten the core ability of vendors to capture value.&lt;/p>
&lt;p>Software-as-a-Service (SaaS) and tool vendors rely heavily on direct interaction with users to monetize their businesses—for example, upselling value-added features, crafting branded experiences, and collecting valuable user data.&lt;/p>
&lt;p>Once they fully embrace MCP, these vendors hand the user interface over to external AI aggregators, inevitably losing their customer relationships and direct monetization channels.&lt;/p>
&lt;h2 id="evidence-from-the-current-ai-ecosystem">Evidence from the Current AI Ecosystem
&lt;/h2>&lt;p>In reality, major software companies have behaved very cautiously in handling their relationships with AI-driven platforms such as OpenAI&amp;rsquo;s &lt;strong>ChatGPT&lt;/strong> and Anthropic&amp;rsquo;s &lt;strong>Claude&lt;/strong>.&lt;/p>
&lt;p>Whether Salesforce, Microsoft, or Google, all of them are seeking to embed AI capabilities deeply into their own proprietary interfaces, rather than allowing their tools to be fully invoked by external AI agents.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/105-mcp_must_fail/Pasted-20250629-1_hu_1c27de0fc4a773cd.webp"
width="1024"
height="686"
srcset="https://chengxiaqiucao.github.io/post/105-mcp_must_fail/Pasted-20250629-1_hu_a8f15bf055ce4acc.webp 480w, https://chengxiaqiucao.github.io/post/105-mcp_must_fail/Pasted-20250629-1_hu_1c27de0fc4a773cd.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="149"
data-flex-basis="358px"
>
&lt;/p>
&lt;p>For example, Einstein GPT from Salesforce integrates AI directly into its customer relationship management (CRM) system, locking users firmly inside its own ecosystem. Similarly, Microsoft has prioritized deeply embedding Copilot AI into the Office and Windows environments. When tool vendors do attempt external AI integration, they usually provide only limited functionality—enough to attract users, but not enough to fully replace their own interfaces. A travel app, for instance, might let an AI assistant browse flight information, but will ultimately steer users back to its own platform to complete the booking, so as to preserve the crucial customer interaction and upselling opportunity.&lt;/p>
&lt;h2 id="mcp-is-bound-to-face-difficulties">MCP Is Bound to Face Difficulties
&lt;/h2>&lt;p>Past experience clearly reveals why MCP has struggled to gain widespread adoption—especially since the large software vendors that dominate market attention could never pivot fully to MCP.&lt;/p>
&lt;p>If these vendors truly believed it was worthwhile to give up user attention in exchange for open integration, they would have long since offered fully featured public APIs for free. The opposite is true: they typically build tightly controlled ecosystems, attracting new users through selective integration, and would never voluntarily surrender control over the user experience or revenue.&lt;/p>
&lt;p>This careful balancing act highlights MCP&amp;rsquo;s fundamental flaw: no matter how elegant or superior a protocol may be on the technical side, software vendors have no incentive to hand their precious customer relationships and monetization capabilities over to external aggregators.&lt;/p>
&lt;h2 id="platform-economics-is-the-foundation-of-technology">Platform Economics Is the Foundation of Technology
&lt;/h2>&lt;p>Ultimately, what decides MCP&amp;rsquo;s fate is not its technical merits or demerits, but commercial incentives and the dynamics of platform economics. Platform owners will inevitably find ways to protect their core asset—the direct connection with users. The approach MCP proposes fundamentally upends this dynamic, setting it against deeply entrenched economic incentives.&lt;/p>
&lt;p>In practice, MCP may gain limited adoption among some smaller vendors or niche communities where openness itself has intrinsic value. Among the mainstream SaaS vendors and large platforms that dominate today&amp;rsquo;s digital economy, however, adopting MCP is at best more about extending one&amp;rsquo;s own reach than exposing one&amp;rsquo;s own capabilities.&lt;/p>
&lt;p>In essence, although MCP aspires to become a universal standard, it faces a harsh economic reality: no company wants to resign itself to becoming an invisible backdrop. Every company will fight tooth and nail to defend its control over the user interface (that is, &lt;strong>control of the user relationship&lt;/strong>) and to limit any integration that might threaten its strategic position.&lt;/p>
&lt;h3 id="conclusion">Conclusion
&lt;/h3>&lt;p>The vision of seamless, universal AI integration painted by MCP is undeniably compelling, but in the business world, striking technology alone rarely decides success or failure.&lt;/p>
&lt;p>The battle over standards is ultimately a battle over economic power. MCP&amp;rsquo;s design challenges the very incentive structures that have driven the digital economy for decades. It is precisely for this reason that MCP faces enormous obstacles on the road to widespread adoption.&lt;/p>
&lt;p>Until it can better align with platform economics and vendors&amp;rsquo; inherent incentives, MCP&amp;rsquo;s ambition to become the universal standard for AI-tool integration is likely to remain a distant dream.&lt;/p>
&lt;p>Original article link:
&lt;a class="link" href="https://www.forbes.com/councils/forbestechcouncil/2025/06/12/mcp-will-fail-and-heres-why/" target="_blank" rel="noopener"
>https://www.forbes.com/councils/forbestechcouncil/2025/06/12/mcp-will-fail-and-heres-why/&lt;/a>&lt;/p></description></item><item><title>The Sky Is Falling for Cursor - Google Open-Sources Gemini-cli, the Ultimate Overachiever of Coding Assistants Is Here</title><link>https://chengxiaqiucao.github.io/en/post/102-gemini-cli/</link><pubDate>Thu, 26 Jun 2025 13:21:59 +0800</pubDate><guid>https://chengxiaqiucao.github.io/en/post/102-gemini-cli/</guid><description>&lt;img src="https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626.webp" alt="Featured image of post The Sky Is Falling for Cursor - Google Open-Sources Gemini-cli, the Ultimate Overachiever of Coding Assistants Is Here" />&lt;h2 id="preface">Preface
&lt;/h2>&lt;p>Yesterday (2025-6-25), Google made a big splash by open-sourcing a command-line-based AI coding Agent, &lt;code>Gemini-Cli&lt;/code>, which deeply integrates AI-assisted programming into the Terminal command-line interface that developers know best. It also directly incorporates Google&amp;rsquo;s latest &lt;code>Gemini 2.5 Pro&lt;/code> capabilities, free for developers to use (with a cap, but a generous one). In just one day, it shot up to 20K stars on GitHub, a clear sign of just how enthusiastic developers are about this tool!!&lt;/p>
&lt;p>Open-source project address: &lt;a class="link" href="https://github.com/google-gemini/gemini-cli" target="_blank" rel="noopener"
>https://github.com/google-gemini/gemini-cli&lt;/a>&lt;/p>
&lt;p>The star history, a terrifying vertical climb 😂&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626-4_hu_9ba2719d9e18f57f.webp"
width="1024"
height="620"
srcset="https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626-4_hu_ca39a5294cde2743.webp 480w, https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626-4_hu_9ba2719d9e18f57f.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="165"
data-flex-basis="396px"
>
&lt;/p>
&lt;p>Below we bring you an out-of-the-box hands-on experience!&lt;/p>
&lt;h2 id="installation">Installation
&lt;/h2>&lt;p>Installing &lt;code>Gemini-Cli&lt;/code> is very convenient. It depends on &lt;code>node.js&lt;/code>; make sure Node.js 18 or above is installed on your machine, then simply run:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">npx https://github.com/google-gemini/gemini-cli
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Or install it with npm and then run &lt;code>gemini&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">npm install -g @google/gemini-cli
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">gemini
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>This brings you to the command-line startup screen:&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626_hu_901185c6c0de428e.webp"
width="1024"
height="569"
srcset="https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626_hu_adad402076698165.webp 480w, https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626_hu_901185c6c0de428e.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="180"
data-flex-basis="432px"
>
&lt;/p>
&lt;p>Pick a coding theme you like, and you will then be prompted to authenticate; usually you can simply sign in with your Google account. Once authorization shows the following information, you can continue using it.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626-1_hu_86837983014c8082.webp"
width="1024"
height="454"
srcset="https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626-1_hu_89fd95b2ff82e500.webp 480w, https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626-1_hu_86837983014c8082.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="225"
data-flex-basis="540px"
>
&lt;/p>
&lt;p>After authorization, you have access to a number of large AI models by default, including Gemini 25 pro, and it &amp;ldquo;lavishly&amp;rdquo; provides &lt;strong>60 requests per minute and 1,000 per day&lt;/strong> of AI calls. Compared with many other large models that still impose limits by token count, this is genuinely generous! Compared with &lt;code>Cursor&lt;/code>&amp;rsquo;s paid tier, which caps usage at 500 requests per month, Cursor must be crying in the bathroom by now~~&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626-2_hu_b11c4ab5019493ba.webp"
width="1024"
height="533"
srcset="https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626-2_hu_b24c6619c8c4fc3e.webp 480w, https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626-2_hu_b11c4ab5019493ba.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="192"
data-flex-basis="461px"
>
&lt;/p>
&lt;h2 id="hands-on-results">Hands-on Results
&lt;/h2>&lt;p>Without further ado, as a testing professional, I first asked it to help build an AI-based test case generation tool.&lt;/p>
&lt;p>The instruction I gave is as follows&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-gdscript3" data-lang="gdscript3">&lt;span class="line">&lt;span class="cl">&lt;span class="n">Write&lt;/span> &lt;span class="n">a&lt;/span> &lt;span class="n">web&lt;/span> &lt;span class="n">program&lt;/span> &lt;span class="n">that&lt;/span> &lt;span class="n">supports&lt;/span> &lt;span class="n">uploading&lt;/span> &lt;span class="n">a&lt;/span> &lt;span class="n">requirements&lt;/span> &lt;span class="n">document&lt;/span> &lt;span class="ow">and&lt;/span> &lt;span class="n">calls&lt;/span> &lt;span class="n">AI&lt;/span> &lt;span class="n">capabilities&lt;/span> &lt;span class="n">to&lt;/span> &lt;span class="nb">convert&lt;/span> &lt;span class="n">it&lt;/span> &lt;span class="n">into&lt;/span> &lt;span class="n">test&lt;/span> &lt;span class="n">cases&lt;/span>&lt;span class="o">.&lt;/span> &lt;span class="n">The&lt;/span> &lt;span class="n">cases&lt;/span> &lt;span class="n">are&lt;/span> &lt;span class="n">displayed&lt;/span> &lt;span class="n">on&lt;/span> &lt;span class="n">the&lt;/span> &lt;span class="n">page&lt;/span> &lt;span class="ow">in&lt;/span> &lt;span class="n">table&lt;/span> &lt;span class="n">form&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">with&lt;/span> &lt;span class="n">fields&lt;/span> &lt;span class="n">including&lt;/span> &lt;span class="n">Case&lt;/span> &lt;span class="n">ID&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">Case&lt;/span> &lt;span class="n">Name&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">Description&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">Test&lt;/span> &lt;span class="n">Steps&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">Priority&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">Pass&lt;/span> &lt;span class="n">Criteria&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">Associated&lt;/span> &lt;span class="n">Requirement&lt;/span> &lt;span class="n">ID&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">optional&lt;/span>&lt;span class="p">),&lt;/span> &lt;span class="n">etc&lt;/span>&lt;span class="o">.&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Very quickly, after a brief analysis, it produced an implementation plan.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626-5_hu_f2097fe25442f51d.webp"
width="1024"
height="606"
srcset="https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626-5_hu_22ed59e752fe3f16.webp 480w, https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626-5_hu_f2097fe25442f51d.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="168"
data-flex-basis="405px"
>
&lt;/p>
&lt;p>As the actual work began, it automatically created the relevant code files and guided me step by step to complete everything from data mocking to real AI capability integration.&lt;/p>
&lt;p>After more than half an hour of collaboration (mostly pasting error messages back to it whenever errors came up), we finally succeeded in building a basic AI test case generation tool.&lt;/p>
&lt;p>For example, I uploaded the requirements &lt;code>req-sprint0.md&lt;/code> from a testing practice site I had open-sourced earlier:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt"> 10
&lt;/span>&lt;span class="lnt"> 11
&lt;/span>&lt;span class="lnt"> 12
&lt;/span>&lt;span class="lnt"> 13
&lt;/span>&lt;span class="lnt"> 14
&lt;/span>&lt;span class="lnt"> 15
&lt;/span>&lt;span class="lnt"> 16
&lt;/span>&lt;span class="lnt"> 17
&lt;/span>&lt;span class="lnt"> 18
&lt;/span>&lt;span class="lnt"> 19
&lt;/span>&lt;span class="lnt"> 20
&lt;/span>&lt;span class="lnt"> 21
&lt;/span>&lt;span class="lnt"> 22
&lt;/span>&lt;span class="lnt"> 23
&lt;/span>&lt;span class="lnt"> 24
&lt;/span>&lt;span class="lnt"> 25
&lt;/span>&lt;span class="lnt"> 26
&lt;/span>&lt;span class="lnt"> 27
&lt;/span>&lt;span class="lnt"> 28
&lt;/span>&lt;span class="lnt"> 29
&lt;/span>&lt;span class="lnt"> 30
&lt;/span>&lt;span class="lnt"> 31
&lt;/span>&lt;span class="lnt"> 32
&lt;/span>&lt;span class="lnt"> 33
&lt;/span>&lt;span class="lnt"> 34
&lt;/span>&lt;span class="lnt"> 35
&lt;/span>&lt;span class="lnt"> 36
&lt;/span>&lt;span class="lnt"> 37
&lt;/span>&lt;span class="lnt"> 38
&lt;/span>&lt;span class="lnt"> 39
&lt;/span>&lt;span class="lnt"> 40
&lt;/span>&lt;span class="lnt"> 41
&lt;/span>&lt;span class="lnt"> 42
&lt;/span>&lt;span class="lnt"> 43
&lt;/span>&lt;span class="lnt"> 44
&lt;/span>&lt;span class="lnt"> 45
&lt;/span>&lt;span class="lnt"> 46
&lt;/span>&lt;span class="lnt"> 47
&lt;/span>&lt;span class="lnt"> 48
&lt;/span>&lt;span class="lnt"> 49
&lt;/span>&lt;span class="lnt"> 50
&lt;/span>&lt;span class="lnt"> 51
&lt;/span>&lt;span class="lnt"> 52
&lt;/span>&lt;span class="lnt"> 53
&lt;/span>&lt;span class="lnt"> 54
&lt;/span>&lt;span class="lnt"> 55
&lt;/span>&lt;span class="lnt"> 56
&lt;/span>&lt;span class="lnt"> 57
&lt;/span>&lt;span class="lnt"> 58
&lt;/span>&lt;span class="lnt"> 59
&lt;/span>&lt;span class="lnt"> 60
&lt;/span>&lt;span class="lnt"> 61
&lt;/span>&lt;span class="lnt"> 62
&lt;/span>&lt;span class="lnt"> 63
&lt;/span>&lt;span class="lnt"> 64
&lt;/span>&lt;span class="lnt"> 65
&lt;/span>&lt;span class="lnt"> 66
&lt;/span>&lt;span class="lnt"> 67
&lt;/span>&lt;span class="lnt"> 68
&lt;/span>&lt;span class="lnt"> 69
&lt;/span>&lt;span class="lnt"> 70
&lt;/span>&lt;span class="lnt"> 71
&lt;/span>&lt;span class="lnt"> 72
&lt;/span>&lt;span class="lnt"> 73
&lt;/span>&lt;span class="lnt"> 74
&lt;/span>&lt;span class="lnt"> 75
&lt;/span>&lt;span class="lnt"> 76
&lt;/span>&lt;span class="lnt"> 77
&lt;/span>&lt;span class="lnt"> 78
&lt;/span>&lt;span class="lnt"> 79
&lt;/span>&lt;span class="lnt"> 80
&lt;/span>&lt;span class="lnt"> 81
&lt;/span>&lt;span class="lnt"> 82
&lt;/span>&lt;span class="lnt"> 83
&lt;/span>&lt;span class="lnt"> 84
&lt;/span>&lt;span class="lnt"> 85
&lt;/span>&lt;span class="lnt"> 86
&lt;/span>&lt;span class="lnt"> 87
&lt;/span>&lt;span class="lnt"> 88
&lt;/span>&lt;span class="lnt"> 89
&lt;/span>&lt;span class="lnt"> 90
&lt;/span>&lt;span class="lnt"> 91
&lt;/span>&lt;span class="lnt"> 92
&lt;/span>&lt;span class="lnt"> 93
&lt;/span>&lt;span class="lnt"> 94
&lt;/span>&lt;span class="lnt"> 95
&lt;/span>&lt;span class="lnt"> 96
&lt;/span>&lt;span class="lnt"> 97
&lt;/span>&lt;span class="lnt"> 98
&lt;/span>&lt;span class="lnt"> 99
&lt;/span>&lt;span class="lnt">100
&lt;/span>&lt;span class="lnt">101
&lt;/span>&lt;span class="lnt">102
&lt;/span>&lt;span class="lnt">103
&lt;/span>&lt;span class="lnt">104
&lt;/span>&lt;span class="lnt">105
&lt;/span>&lt;span class="lnt">106
&lt;/span>&lt;span class="lnt">107
&lt;/span>&lt;span class="lnt">108
&lt;/span>&lt;span class="lnt">109
&lt;/span>&lt;span class="lnt">110
&lt;/span>&lt;span class="lnt">111
&lt;/span>&lt;span class="lnt">112
&lt;/span>&lt;span class="lnt">113
&lt;/span>&lt;span class="lnt">114
&lt;/span>&lt;span class="lnt">115
&lt;/span>&lt;span class="lnt">116
&lt;/span>&lt;span class="lnt">117
&lt;/span>&lt;span class="lnt">118
&lt;/span>&lt;span class="lnt">119
&lt;/span>&lt;span class="lnt">120
&lt;/span>&lt;span class="lnt">121
&lt;/span>&lt;span class="lnt">122
&lt;/span>&lt;span class="lnt">123
&lt;/span>&lt;span class="lnt">124
&lt;/span>&lt;span class="lnt">125
&lt;/span>&lt;span class="lnt">126
&lt;/span>&lt;span class="lnt">127
&lt;/span>&lt;span class="lnt">128
&lt;/span>&lt;span class="lnt">129
&lt;/span>&lt;span class="lnt">130
&lt;/span>&lt;span class="lnt">131
&lt;/span>&lt;span class="lnt">132
&lt;/span>&lt;span class="lnt">133
&lt;/span>&lt;span class="lnt">134
&lt;/span>&lt;span class="lnt">135
&lt;/span>&lt;span class="lnt">136
&lt;/span>&lt;span class="lnt">137
&lt;/span>&lt;span class="lnt">138
&lt;/span>&lt;span class="lnt">139
&lt;/span>&lt;span class="lnt">140
&lt;/span>&lt;span class="lnt">141
&lt;/span>&lt;span class="lnt">142
&lt;/span>&lt;span class="lnt">143
&lt;/span>&lt;span class="lnt">144
&lt;/span>&lt;span class="lnt">145
&lt;/span>&lt;span class="lnt">146
&lt;/span>&lt;span class="lnt">147
&lt;/span>&lt;span class="lnt">148
&lt;/span>&lt;span class="lnt">149
&lt;/span>&lt;span class="lnt">150
&lt;/span>&lt;span class="lnt">151
&lt;/span>&lt;span class="lnt">152
&lt;/span>&lt;span class="lnt">153
&lt;/span>&lt;span class="lnt">154
&lt;/span>&lt;span class="lnt">155
&lt;/span>&lt;span class="lnt">156
&lt;/span>&lt;span class="lnt">157
&lt;/span>&lt;span class="lnt">158
&lt;/span>&lt;span class="lnt">159
&lt;/span>&lt;span class="lnt">160
&lt;/span>&lt;span class="lnt">161
&lt;/span>&lt;span class="lnt">162
&lt;/span>&lt;span class="lnt">163
&lt;/span>&lt;span class="lnt">164
&lt;/span>&lt;span class="lnt">165
&lt;/span>&lt;span class="lnt">166
&lt;/span>&lt;span class="lnt">167
&lt;/span>&lt;span class="lnt">168
&lt;/span>&lt;span class="lnt">169
&lt;/span>&lt;span class="lnt">170
&lt;/span>&lt;span class="lnt">171
&lt;/span>&lt;span class="lnt">172
&lt;/span>&lt;span class="lnt">173
&lt;/span>&lt;span class="lnt">174
&lt;/span>&lt;span class="lnt">175
&lt;/span>&lt;span class="lnt">176
&lt;/span>&lt;span class="lnt">177
&lt;/span>&lt;span class="lnt">178
&lt;/span>&lt;span class="lnt">179
&lt;/span>&lt;span class="lnt">180
&lt;/span>&lt;span class="lnt">181
&lt;/span>&lt;span class="lnt">182
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-markdown" data-lang="markdown">&lt;span class="line">&lt;span class="cl">&lt;span class="gu">### Personal Book Management System - Iteration 1 Requirements Document
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**Version**&lt;/span>: v1.0
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**Goal**&lt;/span>: Implement basic create, read, update, and delete (CRUD) functions for personal books
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">---
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">#### **User Story 1 - Adding a Book**
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**As a**&lt;/span> book collector
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**I want to**&lt;/span> add a new book to my library
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**So that**&lt;/span> I can keep a record of the books I own
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**Acceptance Criteria (Given-When-Then):**&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">1.&lt;/span> &lt;span class="gs">**Successful Addition**&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *Given* the user is on the &amp;#34;Add Book&amp;#34; page
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *When* the required fields (Book Title, Author) are filled in and Submit is clicked
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *Then* the system saves the book, shows an &amp;#34;Added successfully&amp;#34; message, and navigates to the book list page
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">2.&lt;/span> &lt;span class="gs">**Addition Failed (Missing Validation)**&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *Given* the user has not filled in &amp;#34;Book Title&amp;#34; or &amp;#34;Author&amp;#34;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *When* the Submit button is clicked
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *Then* the system shows a red error message below the corresponding field
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">---
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">#### **User Story 2 - Viewing the Book List**
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**As a**&lt;/span> book collector
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**I want to**&lt;/span> view the list of all books
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**So that**&lt;/span> I can quickly browse my collection
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**Acceptance Criteria:**&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">1.&lt;/span> &lt;span class="gs">**Basic List Display**&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *Given* at least one book exists
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *When* the user visits the home page
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *Then* all books are shown in a table (including at least name, author, and reading status)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">2.&lt;/span> &lt;span class="gs">**Empty State Handling**&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *Given* there are no books
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *When* the user visits the home page
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *Then* a &amp;#34;No books yet, click to add&amp;#34; prompt and a navigation link are shown
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">---
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">#### **User Story 3 - Editing Book Information**
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**As a**&lt;/span> book collector
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**I want to**&lt;/span> edit book information
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**So that**&lt;/span> I can update a book&amp;#39;s status or notes
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**Acceptance Criteria:**&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">1.&lt;/span> &lt;span class="gs">**Successful Edit**&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *Given* the user enters a book&amp;#39;s &amp;#34;Edit&amp;#34; page from the list page
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *When* a field is modified (such as updating the reading status to &amp;#34;Read&amp;#34;) and submitted
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *Then* the system saves the changes, returns to the list page, and shows the updated data
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">2.&lt;/span> &lt;span class="gs">**Invalid Data Interception**&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *Given* the user enters letters in the price field
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *When* Submit is clicked
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *Then* the system blocks submission and shows &amp;#34;Please enter a valid number&amp;#34;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">---
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">#### **User Story 4 - Deleting a Book**
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**As a**&lt;/span> book collector
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**I want to**&lt;/span> delete books I no longer need
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**So that**&lt;/span> my library stays tidy
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**Acceptance Criteria:**&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">1.&lt;/span> &lt;span class="gs">**Deletion Operation**&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *Given* the user is on the book list page
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *When* a book&amp;#39;s &amp;#34;Delete&amp;#34; button is clicked
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *Then* the system removes the book and the list refreshes in real time
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">---
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">#### **User Story 5 - Searching Books**
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**As a**&lt;/span> book collector
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**I want to**&lt;/span> search books by name or author
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**So that**&lt;/span> I can quickly locate the book I want
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gs">**Acceptance Criteria:**&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">1.&lt;/span> &lt;span class="gs">**Basic Search**&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *Given* the user types a keyword into the search box at the top of the list page
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *When* the &amp;#34;Search&amp;#34; button is clicked
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> *Then* the system shows books whose name or author matches (case-insensitive)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">---
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">### Field Definitions (Book Attributes)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| Field | Type | Required | Description | Example |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">|--------------|----------|------|-------------------------------|----------------------|
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| Book Title | Text | ✓ | Book title (length ≤ 100 characters) | The Three-Body Problem |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| Author | Text | ✓ | Author name (length ≤ 50 characters) | Liu Cixin |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| Synopsis | Long Text | ✗ | Book description (length ≤ 500 characters) | A sci-fi masterpiece... |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| Publication Date | Date | ✗ | YYYY-MM-DD format | 2008-01-01 |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| List Price | Decimal | ✗ | Positive number (≥ 0) | 68.5 |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| User Purchase Price | Decimal | ✗ | Positive number (≥ 0) | 52.0 |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| User Notes | Long Text | ✗ | Reading notes (length ≤ 1000 characters) | A stunning view of the cosmos... |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| Reading Status | Enum | ✗ | To Read / Read / Reading (default To Read) | To Read |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| In-Library Status | Enum | ✗ | In Library / Borrowed In / Lent Out / Archived (default In Library) | Lent Out |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| Self-Rating | Integer | ✗ | 1-5 stars (default 3 stars) | 5 |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">---
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">### Tech Stack
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="gu">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| Module | Technology Choice |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">|--------|-----------------------|
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| Backend | Python + FastAPI |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| Database | SQLite |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| Frontend | HTML/CSS + Bootstrap |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| API Interaction| AJAX (Fetch API) |
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>The developed program calls DeepSeek deployed locally via Ollama, and then generates test cases! The interface is as follows:&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626-3_hu_b9140ae6eededed1.webp"
width="1024"
height="618"
srcset="https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626-3_hu_6c7fdeaaa31fb612.webp 480w, https://chengxiaqiucao.github.io/post/102-gemini-cli/Pasted-20250626-3_hu_b9140ae6eededed1.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="165"
data-flex-basis="397px"
>
&lt;/p>
&lt;p>It really is too good to pass up! Go recommend it to your friends~~&lt;/p>
&lt;hr>
&lt;p>Reply with &lt;code>进群&lt;/code> to join Qiucao&amp;rsquo;s tech discussion group, share techniques with friends, and exchange news~~
Reply with &lt;code>大纲&lt;/code> to view the detailed syllabus of Qiucao&amp;rsquo;s advanced systematic testing technology course 😉😉😉&lt;/p></description></item><item><title>Source Code Analysis of the AI Automation Tool Midscene.js</title><link>https://chengxiaqiucao.github.io/en/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/</link><pubDate>Sun, 22 Jun 2025 00:00:00 +0000</pubDate><guid>https://chengxiaqiucao.github.io/en/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/</guid><description>&lt;img src="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-5.webp" alt="Featured image of post Source Code Analysis of the AI Automation Tool Midscene.js" />&lt;h2 id="preface">Preface
&lt;/h2>&lt;p>In a previous article 【】we learned about the AI testing tool &lt;code>Midscene.js&lt;/code> launched by ByteDance. Whether it is intelligent project parsing, test execution, or the final report generation, it is quite impressive; moreover, in addition to browser-based web applications, it also supports the automation of Android apps.&lt;/p>
&lt;p>So how exactly does this project use AI intelligence to complete test execution tasks? In this article, we will draw on the open-source project source code of Midscene.js to conduct an in-depth analysis of the project&amp;rsquo;s implementation as well as its application of large models.&lt;/p>
&lt;h2 id="overall-project-architecture">Overall Project Architecture
&lt;/h2>&lt;p>Through the analysis of the project source code, the overall architecture of the project can be summarized by the following diagram:
&lt;img src="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/midscene_arch_hu_aacd2c6e6996adc4.webp"
width="1024"
height="467"
srcset="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/midscene_arch_hu_bb82451fd09cd442.webp 480w, https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/midscene_arch_hu_aacd2c6e6996adc4.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="219"
data-flex-basis="526px"
>
&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>User&lt;/strong>: The user is the starting point of Midscene, defining automation tasks and goals through natural language descriptions, the JavaScript SDK, or YAML scripts.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>MCP Clients&lt;/strong>: Midscene also supports other MCP clients directly using its capabilities, which indicates that it may have an API or integration point for other systems to call.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Midscene Core&lt;/strong>: This is the core logic layer of Midscene. It is responsible for parsing user instructions, interacting with AI models, and coordinating automation agents to perform operations. It also manages report generation and caching.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>AI Models&lt;/strong>: Midscene supports multiple AI models, including:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Multimodal LLM&lt;/strong>: such as GPT-4o and Gemini-2.5-Pro, used to understand more complex instructions and context.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Visual-Language Models&lt;/strong>: such as Qwen2.5-VL, Doubao-1.5-thinking-vision-pro, and UI-TARS, which are especially recommended for UI automation because they can better understand visual information. The AI model receives requests from Midscene Core and returns instructions to execute actions or retrieve information.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Automation Agent&lt;/strong>: This is a key execution layer, responsible for actually operating the target application or UI according to the instructions of Midscene Core. It can obtain the UI state and screenshots and feed them back to Midscene Core.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Target Application/UI&lt;/strong>: This is the actual object of automation operations, which can be:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Browser&lt;/strong>: Web automation through tools such as Playwright or Puppeteer.&lt;/li>
&lt;li>&lt;strong>Android App&lt;/strong>: Performing Android automation.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Visual Reports&lt;/strong>: Midscene provides visual reports to help users understand, replay, and debug the entire automation process.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Playground&lt;/strong>: The built-in Playground environment allows users to debug through natural language instructions.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Caching Mechanism&lt;/strong>: Midscene uses a caching mechanism to improve efficiency, allowing scripts to replay more quickly to obtain results.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="main-built-in-system-prompts">Main Built-in System Prompts
&lt;/h2>&lt;p>The intelligent parsing capability of &lt;code>MidScene&lt;/code> mainly relies on LLM large models, so when calling the LLM, its configured system prompts are especially critical. By analyzing the source code, we can see that MidScene has set different system prompts for different types of tasks. They are summarized as follows:&lt;/p>
&lt;h3 id="1-task-planning-system-prompts">1. Task Planning System Prompts
&lt;/h3>&lt;p>The project contains three different task planning prompts:&lt;/p>
&lt;p>&lt;strong>Task planning prompt for traditional LLM models&lt;/strong> - Used to guide traditional language models to decompose user instructions into a series of executable UI operation actions.&lt;/p>
&lt;p>&lt;code>packages/core/src/ai-model/prompt/llm-planning.ts&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;span class="lnt">46
&lt;/span>&lt;span class="lnt">47
&lt;/span>&lt;span class="lnt">48
&lt;/span>&lt;span class="lnt">49
&lt;/span>&lt;span class="lnt">50
&lt;/span>&lt;span class="lnt">51
&lt;/span>&lt;span class="lnt">52
&lt;/span>&lt;span class="lnt">53
&lt;/span>&lt;span class="lnt">54
&lt;/span>&lt;span class="lnt">55
&lt;/span>&lt;span class="lnt">56
&lt;/span>&lt;span class="lnt">57
&lt;/span>&lt;span class="lnt">58
&lt;/span>&lt;span class="lnt">59
&lt;/span>&lt;span class="lnt">60
&lt;/span>&lt;span class="lnt">61
&lt;/span>&lt;span class="lnt">62
&lt;/span>&lt;span class="lnt">63
&lt;/span>&lt;span class="lnt">64
&lt;/span>&lt;span class="lnt">65
&lt;/span>&lt;span class="lnt">66
&lt;/span>&lt;span class="lnt">67
&lt;/span>&lt;span class="lnt">68
&lt;/span>&lt;span class="lnt">69
&lt;/span>&lt;span class="lnt">70
&lt;/span>&lt;span class="lnt">71
&lt;/span>&lt;span class="lnt">72
&lt;/span>&lt;span class="lnt">73
&lt;/span>&lt;span class="lnt">74
&lt;/span>&lt;span class="lnt">75
&lt;/span>&lt;span class="lnt">76
&lt;/span>&lt;span class="lnt">77
&lt;/span>&lt;span class="lnt">78
&lt;/span>&lt;span class="lnt">79
&lt;/span>&lt;span class="lnt">80
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-typescript" data-lang="typescript">&lt;span class="line">&lt;span class="cl">&lt;span class="kr">const&lt;/span> &lt;span class="nx">llmLocateParam&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="sb">`locate: {{&amp;#34;id&amp;#34;: string, &amp;#34;prompt&amp;#34;: string}} | null`&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kr">const&lt;/span> &lt;span class="nx">systemTemplateOfLLM&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">({&lt;/span> &lt;span class="nx">pageType&lt;/span> &lt;span class="p">}&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">pageType&lt;/span>: &lt;span class="kt">PageType&lt;/span> &lt;span class="p">})&lt;/span> &lt;span class="o">=&amp;gt;&lt;/span> &lt;span class="sb">`
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">## Role
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">You are a versatile professional in software UI automation. Your outstanding contributions will impact the user experience of billions of users.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">## Objective
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- Decompose the instruction user asked into a series of actions
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- Locate the target element if possible
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- If the instruction cannot be accomplished, give a further plan.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">## Workflow
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">1. Receive the screenshot, element description of screenshot(if any), user&amp;#39;s instruction and previous logs.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">2. Decompose the user&amp;#39;s task into a sequence of actions, and place it in the \`actions\` field. There are different types of actions (Tap / Hover / Input / KeyboardPress / Scroll / FalsyConditionStatement / Sleep &lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nx">pageType&lt;/span> &lt;span class="o">===&lt;/span> &lt;span class="s1">&amp;#39;android&amp;#39;&lt;/span> &lt;span class="o">?&lt;/span> &lt;span class="s1">&amp;#39;/ AndroidBackButton / AndroidHomeButton / AndroidRecentAppsButton&amp;#39;&lt;/span> &lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;&amp;#39;&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="sb">). The &amp;#34;About the action&amp;#34; section below will give you more details.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">3. Precisely locate the target element if it&amp;#39;s already shown in the screenshot, put the location info in the \`locate\` field of the action.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">4. If some target elements is not shown in the screenshot, consider the user&amp;#39;s instruction is not feasible on this page. Follow the next steps.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">5. Consider whether the user&amp;#39;s instruction will be accomplished after all the actions
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - If yes, set \`taskWillBeAccomplished\` to true
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - If no, don&amp;#39;t plan more actions by closing the array. Get ready to reevaluate the task. Some talent people like you will handle this. Give him a clear description of what have been done and what to do next. Put your new plan in the \`furtherPlan\` field. The &amp;#34;How to compose the \`taskWillBeAccomplished\` and \`furtherPlan\` fields&amp;#34; section will give you more details.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">## Constraints
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- All the actions you composed MUST be based on the page context information you get.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- Trust the &amp;#34;What have been done&amp;#34; field about the task (if any), don&amp;#39;t repeat actions in it.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- Respond only with valid JSON. Do not write an introduction or summary or markdown prefix like \`\`\`json\`\`\`.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- If the screenshot and the instruction are totally irrelevant, set reason in the \`error\` field.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">## About the \`actions\` field
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">The \`locate\` param is commonly used in the \`param\` field of the action, means to locate the target element to perform the action, it conforms to the following scheme:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">type LocateParam = {{
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> &amp;#34;id&amp;#34;: string, // the id of the element found. It should either be the id marked with a rectangle in the screenshot or the id described in the description.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> &amp;#34;prompt&amp;#34;?: string // the description of the element to find. It can only be omitted when locate is null.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">}} | null // If it&amp;#39;s not on the page, the LocateParam should be null
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">## Supported actions
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">Each action has a \`type\` and corresponding \`param\`. To be detailed:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- type: &amp;#39;Tap&amp;#39;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> * {{ &lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nx">llmLocateParam&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="sb"> }}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- type: &amp;#39;RightClick&amp;#39;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> * {{ &lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nx">llmLocateParam&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="sb"> }}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- type: &amp;#39;Hover&amp;#39;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> * {{ &lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nx">llmLocateParam&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="sb"> }}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- type: &amp;#39;Input&amp;#39;, replace the value in the input field
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> * {{ &lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nx">llmLocateParam&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="sb">, param: {{ value: string }} }}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> * \`value\` is the final value that should be filled in the input field. No matter what modifications are required, just provide the final value user should see after the action is done.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- type: &amp;#39;KeyboardPress&amp;#39;, press a key
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> * {{ param: {{ value: string }} }}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- type: &amp;#39;Scroll&amp;#39;, scroll up or down.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> * {{
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> &lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nx">llmLocateParam&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="sb">,
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> param: {{
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> direction: &amp;#39;down&amp;#39;(default) | &amp;#39;up&amp;#39; | &amp;#39;right&amp;#39; | &amp;#39;left&amp;#39;,
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> scrollType: &amp;#39;once&amp;#39; (default) | &amp;#39;untilBottom&amp;#39; | &amp;#39;untilTop&amp;#39; | &amp;#39;untilRight&amp;#39; | &amp;#39;untilLeft&amp;#39;,
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> distance: null | number
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> }}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> }}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> * To scroll some specific element, put the element at the center of the region in the \`locate\` field. If it&amp;#39;s a page scroll, put \`null\` in the \`locate\` field.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> * \`param\` is required in this action. If some fields are not specified, use direction \`down\`, \`once\` scroll type, and \`null\` distance.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> * {{ param: {{ button: &amp;#39;Back&amp;#39; | &amp;#39;Home&amp;#39; | &amp;#39;RecentApp&amp;#39; }} }}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- type: &amp;#39;ExpectedFalsyCondition&amp;#39;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> * {{ param: {{ reason: string }} }}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> * use this action when the conditional statement talked about in the instruction is falsy.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- type: &amp;#39;Sleep&amp;#39;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> * {{ param: {{ timeMs: number }} }}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">&lt;/span>&lt;span class="si">${&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">pageType&lt;/span> &lt;span class="o">===&lt;/span> &lt;span class="s1">&amp;#39;android&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">?&lt;/span> &lt;span class="sb">`- type: &amp;#39;AndroidBackButton&amp;#39;, trigger the system &amp;#34;back&amp;#34; operation on Android devices
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> * {{ param: {{}} }}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- type: &amp;#39;AndroidHomeButton&amp;#39;, trigger the system &amp;#34;home&amp;#34; operation on Android devices
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> * {{ param: {{}} }}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- type: &amp;#39;AndroidRecentAppsButton&amp;#39;, trigger the system &amp;#34;recent apps&amp;#34; operation on Android devices
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> * {{ param: {{}} }}`&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="si">}&lt;/span>&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">`&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>&lt;strong>Task planning prompt for visual-language models&lt;/strong> - Specifically designed for AI models with visual capabilities (such as Qwen-VL and Gemini), able to directly process screenshots and plan the next action.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621_hu_6926387f76c94f6c.webp"
width="1024"
height="462"
srcset="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621_hu_f7b37730f5926b68.webp 480w, https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621_hu_6926387f76c94f6c.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="221"
data-flex-basis="532px"
>
&lt;/p>
&lt;p>&lt;strong>Task planning prompt for the UI-Tars model&lt;/strong> - A GUI agent prompt specifically designed for UI-Tars, adopting a think-act format.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-1_hu_5a6b6af294bf16.webp"
width="1024"
height="463"
srcset="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-1_hu_fd6046f84b1e202b.webp 480w, https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-1_hu_5a6b6af294bf16.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="220"
data-flex-basis="530px"
>
&lt;/p>
&lt;h3 id="2-element-locating-system-prompts">2. Element Locating System Prompts
&lt;/h3>&lt;p>&lt;strong>Element locating prompt&lt;/strong> - Used to precisely locate target elements in page screenshots and element descriptions, supporting both traditional LLM and visual-language model modes.
&lt;img src="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-2_hu_794412b4956ea81a.webp"
width="1024"
height="493"
srcset="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-2_hu_b974cd93440bf69c.webp 480w, https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-2_hu_794412b4956ea81a.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="207"
data-flex-basis="498px"
>
&lt;/p>
&lt;p>&lt;strong>Region locating prompt&lt;/strong> - Used to locate the page region containing the target element, usually an area no larger than 300x300 pixels.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-3_hu_7778d0f9d172b0af.webp"
width="1024"
height="463"
srcset="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-3_hu_e17b445ca9a858d0.webp 480w, https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-3_hu_7778d0f9d172b0af.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="220"
data-flex-basis="530px"
>
&lt;/p>
&lt;h3 id="3-data-extraction-system-prompts">3. Data Extraction System Prompts
&lt;/h3>&lt;p>&lt;strong>Data extraction prompt&lt;/strong> - Guides the AI to extract structured data from the UI, supporting multiple data types and format requirements.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-4_hu_c08d31eb5b85587c.webp"
width="1024"
height="463"
srcset="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-4_hu_b89d8169ac029c30.webp 480w, https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-4_hu_c08d31eb5b85587c.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="220"
data-flex-basis="530px"
>
&lt;/p>
&lt;h3 id="4-assertion-verification-system-prompts">4. Assertion Verification System Prompts
&lt;/h3>&lt;p>&lt;strong>Assertion verification prompt&lt;/strong> - Used to verify whether the page state meets the expected assertion conditions, supporting both the UI-Tars and ordinary model formats.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-typescript" data-lang="typescript">&lt;span class="line">&lt;span class="cl">&lt;span class="kr">const&lt;/span> &lt;span class="nx">defaultAssertionPrompt&lt;/span> &lt;span class="o">=&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s1">&amp;#39;You are a senior testing engineer. User will give an assertion and a screenshot of a page. By carefully viewing the screenshot, please tell whether the assertion is truthy.&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kr">const&lt;/span> &lt;span class="nx">defaultAssertionResponseJsonFormat&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="sb">`Return in the following JSON format:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">{
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> pass: boolean, // whether the assertion is truthy
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> thought: string | null, // string, if the result is falsy, give the reason why it is falsy. Otherwise, put null.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">}`&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="5-element-description-system-prompts">5. Element Description System Prompts
&lt;/h3>&lt;p>&lt;strong>Element description prompt&lt;/strong> - Used to generate precise element descriptions to help identify specific UI elements in the page (given elements).&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-typescript" data-lang="typescript">&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">export&lt;/span> &lt;span class="kr">const&lt;/span> &lt;span class="nx">elementDescriberInstruction&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">()&lt;/span> &lt;span class="o">=&amp;gt;&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="sb">`Describe the element in the red rectangle for precise identification. Use &lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nx">getPreferredLanguage&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="sb">.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">Rules:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">1. Start with element type (button, input, link, etc.)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">2. Include key identifiers:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - Text content: &amp;#34;with text &amp;#39;Submit&amp;#39;&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - Visual features: &amp;#34;blue background&amp;#34;, &amp;#34;icon only&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - Position: &amp;#34;top-right&amp;#34;, &amp;#34;below search bar&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">3. Keep description under 20 words
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">4. Don&amp;#39;t mention the red rectangle
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">Return JSON:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">{
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> &amp;#34;description&amp;#34;: &amp;#34;brief element type with key identifiers&amp;#34;,
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> &amp;#34;error&amp;#34;?: &amp;#34;error message if any&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">}`&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">};&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="6-code-generation-system-prompts">6. Code Generation System Prompts
&lt;/h3>&lt;p>&lt;strong>Playwright test code generation prompt&lt;/strong> - Generates executable Playwright test code based on recorded browser session events.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-typescript" data-lang="typescript">&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// Create system prompt
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="kr">const&lt;/span> &lt;span class="nx">systemPrompt&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="sb">`You are an expert test automation engineer specializing in Playwright and Midscene.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">Your task is to generate a complete, executable Playwright test using @midscene/web/playwright that reproduces a recorded browser session.
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;blockquote>
&lt;p>By adopting a modular design for these system prompts, they are dynamically adjusted according to different AI model types (traditional LLM vs. visual-language model) and page types (web vs. Android). The project also includes complete JSON schema definitions to ensure structured and consistent AI output, and supports multi-language environments &lt;code>${getPreferredLanguage()}&lt;/code>&lt;/p>&lt;/blockquote>
&lt;h2 id="supplements-and-constraints-on-user-prompts">Supplements and Constraints on User Prompts
&lt;/h2>&lt;p>Beyond the configuration of these system prompts that helps the LLM better understand the current task, the user&amp;rsquo;s input instructions — namely the &lt;code>user prompts&lt;/code> — inevitably require a certain degree of expansion and constraint supplementation during actual processing.&lt;/p>
&lt;p>Here we further analyze the handling of user prompts:&lt;/p>
&lt;h3 id="1-intelligent-generation-of-background-context">&lt;strong>1. Intelligent Generation of Background Context&lt;/strong>
&lt;/h3>&lt;p>The project adds structured background context to user instructions through the &lt;code>generateTaskBackgroundContext&lt;/code> function, including high-priority knowledge and historical execution logs, to prevent repeating the same operations.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-typescript" data-lang="typescript">&lt;span class="line">&lt;span class="cl">&lt;span class="kr">export&lt;/span> &lt;span class="kr">const&lt;/span> &lt;span class="nx">generateTaskBackgroundContext&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">userInstruction&lt;/span>: &lt;span class="kt">string&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">log?&lt;/span>: &lt;span class="kt">string&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">userActionContext?&lt;/span>: &lt;span class="kt">string&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">)&lt;/span> &lt;span class="o">=&amp;gt;&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nx">log&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="sb">`
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">Here is the user&amp;#39;s instruction:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">&amp;lt;instruction&amp;gt;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> &amp;lt;high_priority_knowledge&amp;gt;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> &lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nx">userActionContext&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> &amp;lt;/high_priority_knowledge&amp;gt;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> &lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nx">userInstruction&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">&amp;lt;/instruction&amp;gt;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">These are the logs from previous executions, which indicate what was done in the previous actions.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">Do NOT repeat these actions.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">&amp;lt;previous_logs&amp;gt;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">&lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nx">log&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">&amp;lt;/previous_logs&amp;gt;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">`&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="sb">`
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">Here is the user&amp;#39;s instruction:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">&amp;lt;instruction&amp;gt;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> &amp;lt;high_priority_knowledge&amp;gt;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> &lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nx">userActionContext&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> &amp;lt;/high_priority_knowledge&amp;gt;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> &lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nx">userInstruction&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">&amp;lt;/instruction&amp;gt;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">`&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">};&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="2-multimodal-adapted-user-prompts">&lt;strong>2. Multimodal-Adapted User Prompts&lt;/strong>
&lt;/h3>&lt;p>Depending on the capabilities of the AI model, user prompts adopt different formats. For visual-language models, the task background is passed directly; for traditional LLMs, page description information is combined.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-typescript" data-lang="typescript">&lt;span class="line">&lt;span class="cl">&lt;span class="kr">export&lt;/span> &lt;span class="kr">const&lt;/span> &lt;span class="nx">automationUserPrompt&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">vlMode&lt;/span>: &lt;span class="kt">ReturnType&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">typeof&lt;/span> &lt;span class="na">vlLocateMode&lt;/span>&lt;span class="p">&amp;gt;,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">)&lt;/span> &lt;span class="o">=&amp;gt;&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nx">vlMode&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="k">new&lt;/span> &lt;span class="nx">PromptTemplate&lt;/span>&lt;span class="p">({&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">template&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;{taskBackgroundContext}&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">inputVariables&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;taskBackgroundContext&amp;#39;&lt;/span>&lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">});&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="k">new&lt;/span> &lt;span class="nx">PromptTemplate&lt;/span>&lt;span class="p">({&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">template&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="sb">`
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">pageDescription:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">=====================================
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">{pageDescription}
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">=====================================
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">{taskBackgroundContext}`&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">inputVariables&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;pageDescription&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;taskBackgroundContext&amp;#39;&lt;/span>&lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">});&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">};&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="3-structured-json-schema-validation">&lt;strong>3. Structured JSON Schema Validation&lt;/strong>
&lt;/h3>&lt;p>The project uses OpenAI&amp;rsquo;s structured output schema to strictly constrain the AI&amp;rsquo;s response format, ensuring that the returned data conforms to a predefined structure, including necessary fields such as actions, log, and error.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt"> 10
&lt;/span>&lt;span class="lnt"> 11
&lt;/span>&lt;span class="lnt"> 12
&lt;/span>&lt;span class="lnt"> 13
&lt;/span>&lt;span class="lnt"> 14
&lt;/span>&lt;span class="lnt"> 15
&lt;/span>&lt;span class="lnt"> 16
&lt;/span>&lt;span class="lnt"> 17
&lt;/span>&lt;span class="lnt"> 18
&lt;/span>&lt;span class="lnt"> 19
&lt;/span>&lt;span class="lnt"> 20
&lt;/span>&lt;span class="lnt"> 21
&lt;/span>&lt;span class="lnt"> 22
&lt;/span>&lt;span class="lnt"> 23
&lt;/span>&lt;span class="lnt"> 24
&lt;/span>&lt;span class="lnt"> 25
&lt;/span>&lt;span class="lnt"> 26
&lt;/span>&lt;span class="lnt"> 27
&lt;/span>&lt;span class="lnt"> 28
&lt;/span>&lt;span class="lnt"> 29
&lt;/span>&lt;span class="lnt"> 30
&lt;/span>&lt;span class="lnt"> 31
&lt;/span>&lt;span class="lnt"> 32
&lt;/span>&lt;span class="lnt"> 33
&lt;/span>&lt;span class="lnt"> 34
&lt;/span>&lt;span class="lnt"> 35
&lt;/span>&lt;span class="lnt"> 36
&lt;/span>&lt;span class="lnt"> 37
&lt;/span>&lt;span class="lnt"> 38
&lt;/span>&lt;span class="lnt"> 39
&lt;/span>&lt;span class="lnt"> 40
&lt;/span>&lt;span class="lnt"> 41
&lt;/span>&lt;span class="lnt"> 42
&lt;/span>&lt;span class="lnt"> 43
&lt;/span>&lt;span class="lnt"> 44
&lt;/span>&lt;span class="lnt"> 45
&lt;/span>&lt;span class="lnt"> 46
&lt;/span>&lt;span class="lnt"> 47
&lt;/span>&lt;span class="lnt"> 48
&lt;/span>&lt;span class="lnt"> 49
&lt;/span>&lt;span class="lnt"> 50
&lt;/span>&lt;span class="lnt"> 51
&lt;/span>&lt;span class="lnt"> 52
&lt;/span>&lt;span class="lnt"> 53
&lt;/span>&lt;span class="lnt"> 54
&lt;/span>&lt;span class="lnt"> 55
&lt;/span>&lt;span class="lnt"> 56
&lt;/span>&lt;span class="lnt"> 57
&lt;/span>&lt;span class="lnt"> 58
&lt;/span>&lt;span class="lnt"> 59
&lt;/span>&lt;span class="lnt"> 60
&lt;/span>&lt;span class="lnt"> 61
&lt;/span>&lt;span class="lnt"> 62
&lt;/span>&lt;span class="lnt"> 63
&lt;/span>&lt;span class="lnt"> 64
&lt;/span>&lt;span class="lnt"> 65
&lt;/span>&lt;span class="lnt"> 66
&lt;/span>&lt;span class="lnt"> 67
&lt;/span>&lt;span class="lnt"> 68
&lt;/span>&lt;span class="lnt"> 69
&lt;/span>&lt;span class="lnt"> 70
&lt;/span>&lt;span class="lnt"> 71
&lt;/span>&lt;span class="lnt"> 72
&lt;/span>&lt;span class="lnt"> 73
&lt;/span>&lt;span class="lnt"> 74
&lt;/span>&lt;span class="lnt"> 75
&lt;/span>&lt;span class="lnt"> 76
&lt;/span>&lt;span class="lnt"> 77
&lt;/span>&lt;span class="lnt"> 78
&lt;/span>&lt;span class="lnt"> 79
&lt;/span>&lt;span class="lnt"> 80
&lt;/span>&lt;span class="lnt"> 81
&lt;/span>&lt;span class="lnt"> 82
&lt;/span>&lt;span class="lnt"> 83
&lt;/span>&lt;span class="lnt"> 84
&lt;/span>&lt;span class="lnt"> 85
&lt;/span>&lt;span class="lnt"> 86
&lt;/span>&lt;span class="lnt"> 87
&lt;/span>&lt;span class="lnt"> 88
&lt;/span>&lt;span class="lnt"> 89
&lt;/span>&lt;span class="lnt"> 90
&lt;/span>&lt;span class="lnt"> 91
&lt;/span>&lt;span class="lnt"> 92
&lt;/span>&lt;span class="lnt"> 93
&lt;/span>&lt;span class="lnt"> 94
&lt;/span>&lt;span class="lnt"> 95
&lt;/span>&lt;span class="lnt"> 96
&lt;/span>&lt;span class="lnt"> 97
&lt;/span>&lt;span class="lnt"> 98
&lt;/span>&lt;span class="lnt"> 99
&lt;/span>&lt;span class="lnt">100
&lt;/span>&lt;span class="lnt">101
&lt;/span>&lt;span class="lnt">102
&lt;/span>&lt;span class="lnt">103
&lt;/span>&lt;span class="lnt">104
&lt;/span>&lt;span class="lnt">105
&lt;/span>&lt;span class="lnt">106
&lt;/span>&lt;span class="lnt">107
&lt;/span>&lt;span class="lnt">108
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-typescript" data-lang="typescript">&lt;span class="line">&lt;span class="cl">&lt;span class="kr">export&lt;/span> &lt;span class="kr">const&lt;/span> &lt;span class="nx">planSchema&lt;/span>: &lt;span class="kt">ResponseFormatJSONSchema&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;json_schema&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">json_schema&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;action_items&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">strict&lt;/span>: &lt;span class="kt">true&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">schema&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;object&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">strict&lt;/span>: &lt;span class="kt">true&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">properties&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">actions&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// TODO
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;array&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">items&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;object&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">strict&lt;/span>: &lt;span class="kt">true&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">properties&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">thought&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;string&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">description&lt;/span>&lt;span class="o">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s1">&amp;#39;Reasons for generating this task, and why this task is feasible on this page&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;string&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">description&lt;/span>&lt;span class="o">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s1">&amp;#39;Type of action, one of &amp;#34;Tap&amp;#34;, &amp;#34;RightClick&amp;#34;, &amp;#34;Hover&amp;#34; , &amp;#34;Input&amp;#34;, &amp;#34;KeyboardPress&amp;#34;, &amp;#34;Scroll&amp;#34;, &amp;#34;ExpectedFalsyCondition&amp;#34;, &amp;#34;Sleep&amp;#34;, &amp;#34;AndroidBackButton&amp;#34;, &amp;#34;AndroidHomeButton&amp;#34;, &amp;#34;AndroidRecentAppsButton&amp;#34;&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">param&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">anyOf&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;null&amp;#39;&lt;/span> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;object&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">properties&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">value&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;string&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;number&amp;#39;&lt;/span>&lt;span class="p">]&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">required&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;value&amp;#39;&lt;/span>&lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">additionalProperties&lt;/span>: &lt;span class="kt">false&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;object&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">properties&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">timeMs&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;number&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;string&amp;#39;&lt;/span>&lt;span class="p">]&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">required&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;timeMs&amp;#39;&lt;/span>&lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">additionalProperties&lt;/span>: &lt;span class="kt">false&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;object&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">properties&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">direction&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;string&amp;#39;&lt;/span> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">scrollType&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;string&amp;#39;&lt;/span> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">distance&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;number&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;string&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;null&amp;#39;&lt;/span>&lt;span class="p">]&lt;/span> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">required&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;direction&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;scrollType&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;distance&amp;#39;&lt;/span>&lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">additionalProperties&lt;/span>: &lt;span class="kt">false&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;object&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">properties&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">reason&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;string&amp;#39;&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">required&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;reason&amp;#39;&lt;/span>&lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">additionalProperties&lt;/span>: &lt;span class="kt">false&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;object&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">properties&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">button&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;string&amp;#39;&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">required&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;button&amp;#39;&lt;/span>&lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">additionalProperties&lt;/span>: &lt;span class="kt">false&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">description&lt;/span>&lt;span class="o">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s1">&amp;#39;Parameter of the action, can be null ONLY when the type field is Tap or Hover&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">locate&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;object&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;null&amp;#39;&lt;/span>&lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">properties&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">id&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;string&amp;#39;&lt;/span> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">prompt&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;string&amp;#39;&lt;/span> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">required&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;id&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;prompt&amp;#39;&lt;/span>&lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">additionalProperties&lt;/span>: &lt;span class="kt">false&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">description&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;Location information for the target element&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">required&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;thought&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;type&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;param&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;locate&amp;#39;&lt;/span>&lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">additionalProperties&lt;/span>: &lt;span class="kt">false&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">description&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;List of actions to be performed&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">more_actions_needed_by_instruction&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;boolean&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">description&lt;/span>&lt;span class="o">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s1">&amp;#39;If all the actions described in the instruction have been covered by this action and logs, set this field to false.&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">log&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;string&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">description&lt;/span>&lt;span class="o">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s1">&amp;#39;Log what these planned actions do. Do not include further actions that have not been planned.&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">error&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">type&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;string&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;null&amp;#39;&lt;/span>&lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">description&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;Error messages about unexpected situations&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">required&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s1">&amp;#39;actions&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s1">&amp;#39;more_actions_needed_by_instruction&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s1">&amp;#39;log&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s1">&amp;#39;error&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">additionalProperties&lt;/span>: &lt;span class="kt">false&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">};&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;blockquote>
&lt;p>Through these multi-layered enhancement and constraint mechanisms, the AI model is ensured to accurately understand user intent while its behavioral boundaries are strictly controlled. Judging from the definition of the prompts, the project places great emphasis on preventing the AI from hallucinating or performing operations beyond the scope of user instructions, which is crucial for scenarios such as UI automation that require high-precision operations.&lt;/p>&lt;/blockquote>
&lt;h2 id="large-model-context-window-limitations">Large Model Context Window Limitations
&lt;/h2>&lt;p>When using various AI large models to complete intelligent tasks, a very important constraint is that large models usually have a &lt;code>context window size limit&lt;/code>; historical information exceeding this limit is discarded in order to conserve the resources of the large model and improve performance.&lt;/p>
&lt;p>For an automated testing task, however, the execution chain after decomposition is often long and usually exceeds the LLM&amp;rsquo;s context limit.&lt;/p>
&lt;p>So here we further analyze how this project handles the context window limit.&lt;/p>
&lt;h3 id="1-token-count-limit-control">1. Token Count Limit Control
&lt;/h3>&lt;p>The project sets the maximum number of tokens in the response through the &lt;code>OPENAI_MAX_TOKENS&lt;/code> environment variable&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-6_hu_7d543a71488ff914.webp"
width="1024"
height="413"
srcset="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-6_hu_eb15cf7c4eb277d3.webp 480w, https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-6_hu_7d543a71488ff914.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="248"
data-flex-basis="595px"
>
&lt;/p>
&lt;h3 id="2-image-size-limits-and-automatic-adjustment">2. Image Size Limits and Automatic Adjustment
&lt;/h3>&lt;p>The project implements image size limits for different models, especially strict size control for the GPT-4o model. When it detects that the image size exceeds the maximum input limit of GPT-4o (2000x768 or 768x2000 pixels), the system issues a warning.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-typescript" data-lang="typescript">&lt;span class="line">&lt;span class="cl">&lt;span class="kd">let&lt;/span> &lt;span class="nx">warned&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="kc">false&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kr">export&lt;/span> &lt;span class="kd">function&lt;/span> &lt;span class="nx">warnGPT4oSizeLimit&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">size&lt;/span>: &lt;span class="kt">Size&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nx">warned&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="k">return&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nx">getModelName&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">toLowerCase&lt;/span>&lt;span class="p">().&lt;/span>&lt;span class="nx">includes&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;gpt-4o&amp;#39;&lt;/span>&lt;span class="p">))&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">const&lt;/span> &lt;span class="nx">warningMsg&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="sb">`GPT-4o has a maximum image input size of 2000x768 or 768x2000, but got &lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nx">size&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">width&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="sb">x&lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nx">size&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">height&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="sb">. Please set your page to a smaller resolution. Otherwise, the result may be inaccurate.`&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nb">Math&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">max&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">size&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">width&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nx">size&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">height&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">&amp;gt;&lt;/span> &lt;span class="mi">2000&lt;/span> &lt;span class="o">||&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nb">Math&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">min&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">size&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">width&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nx">size&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">height&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">&amp;gt;&lt;/span> &lt;span class="mi">768&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">console&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">warn&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">warningMsg&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">warned&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="kc">true&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span> &lt;span class="k">else&lt;/span> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nx">size&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">width&lt;/span> &lt;span class="o">&amp;gt;&lt;/span> &lt;span class="mi">1800&lt;/span> &lt;span class="o">||&lt;/span> &lt;span class="nx">size&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">height&lt;/span> &lt;span class="o">&amp;gt;&lt;/span> &lt;span class="mi">1800&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">console&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">warn&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="sb">`The image size seems too large (&lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nx">size&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">width&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="sb">x&lt;/span>&lt;span class="si">${&lt;/span>&lt;span class="nx">size&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">height&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="sb">). It may lead to more token usage, slower response, and inaccurate result.`&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">warned&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="kc">true&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="3-image-compression-and-optimization">3. Image Compression and Optimization
&lt;/h3>&lt;p>The system reduces the amount of data transferred through image compression (&lt;code>packages/shared/src/img/transform.ts&lt;/code>), including:&lt;/p>
&lt;ul>
&lt;li>Setting the image quality to 90% to balance quality and file size&lt;/li>
&lt;li>Providing image resizing functionality&lt;/li>
&lt;li>Supporting image processing and conversion in base64 format&lt;/li>
&lt;/ul>
&lt;h3 id="4-choosing-the-right-model-architecture">4. Choosing the Right Model Architecture
&lt;/h3>&lt;p>The project supports two different types of AI models to optimize token usage:&lt;/p>
&lt;p>&lt;strong>General-purpose multimodal LLM (such as GPT-4o)&lt;/strong>: Requires sending both the screenshot and the DOM tree, resulting in higher token consumption.&lt;/p>
&lt;p>&lt;strong>Visual grounding VL model (such as Qwen-2.5-VL)&lt;/strong>: Supports visual grounding and does not need to send the DOM tree, saving 30% to 50% of tokens.&lt;/p>
&lt;p>See the explanation in the &lt;code>apps/site/docs/zh/choose-a-model.mdx&lt;/code> document&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-7_hu_913b7eab79ce8506.webp"
width="1024"
height="309"
srcset="https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-7_hu_e335fd6cdfa834bc.webp 480w, https://chengxiaqiucao.github.io/post/081-midscene%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/snap_20250621-7_hu_913b7eab79ce8506.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="331"
data-flex-basis="795px"
>
&lt;/p>
&lt;h3 id="5-token-usage-monitoring">5. Token Usage Monitoring
&lt;/h3>&lt;p>The project also provides detailed token usage tracking and debugging features, recording prompt tokens, completion tokens, and the total number of tokens.&lt;/p>
&lt;p>In summary, the project&amp;rsquo;s strategy for handling context window limits mainly focuses on three aspects:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Controlling the input data volume&lt;/strong> (through image compression and size limits)&lt;/li>
&lt;li>&lt;strong>Choosing the right model architecture&lt;/strong> (VL model vs. general-purpose LLM)&lt;/li>
&lt;li>&lt;strong>Monitoring and optimizing token usage&lt;/strong>&lt;/li>
&lt;/ul>
&lt;p>This multi-layered approach effectively reduces the need for large context windows while also maintaining functional completeness.&lt;/p>
&lt;h2 id="memory-management-for-long-chain-tasks">Memory Management for Long-Chain Tasks
&lt;/h2>&lt;p>For large models, the memory of completed steps and historical tasks is of great significance for ensuring result accuracy, avoiding unnecessary repetition, and saving costs. As introduced in our previous articles, tools such as &lt;code>Browser-Use&lt;/code> bring in memory frameworks like &lt;code>mem0&lt;/code> to implement AI memory capabilities; so how does Midscene handle this aspect?&lt;/p>
&lt;p>Based on the analysis of the Midscene code, memory management for long-chain tasks is mainly implemented through the following core mechanisms:&lt;/p>
&lt;h3 id="task-caching-mechanism">Task Caching Mechanism
&lt;/h3>&lt;p>Midscene implements an intelligent task caching system to manage the memory of AI operations. This system caches planning results and element location information to avoid repeated AI calls, thereby reducing memory consumption and improving execution efficiency.&lt;/p>
&lt;p>&lt;code>packages/web-integration/src/common/task-cache.ts&lt;/code>&lt;/p>
&lt;p>The caching system supports two types of cache:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Planning Cache (PlanningCache)&lt;/strong> is used to store the AI-planned YAML workflows&lt;/li>
&lt;li>&lt;strong>Locate Cache (LocateCache)&lt;/strong> is used to store the XPath information of elements.&lt;/li>
&lt;/ul>
&lt;h3 id="conversation-history-management">Conversation History Management
&lt;/h3>&lt;p>To prevent the conversation history in long-chain tasks from growing indefinitely and causing memory overflow, Midscene implements an intelligent conversation history management strategy. The system limits user image messages to a maximum of 4 retained entries and adopts a first-in-first-out (FIFO) strategy to automatically clean up old conversation records.&lt;/p>
&lt;p>&lt;code>packages/web-integration/src/common/tasks.ts&lt;/code>&lt;/p>
&lt;h3 id="replanning-limit-mechanism">Replanning Limit Mechanism
&lt;/h3>&lt;p>To prevent the AI from falling into an infinite replanning loop in long-chain tasks, the system sets a limit on the number of replanning attempts. When the number of replanning attempts exceeds the limit, the task proactively terminates and returns an error message.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-typescript" data-lang="typescript">&lt;span class="line">&lt;span class="cl">&lt;span class="k">while&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nx">planningTask&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nx">replanCount&lt;/span> &lt;span class="o">&amp;gt;&lt;/span> &lt;span class="nx">replanningCountLimit&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="kr">const&lt;/span> &lt;span class="nx">errorMsg&lt;/span> &lt;span class="o">=&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s1">&amp;#39;Replanning too many times, please split the task into multiple steps&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="k">this&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">appendErrorPlan&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">taskExecutor&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nx">errorMsg&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="resource-cleanup-mechanism">Resource Cleanup Mechanism
&lt;/h3>&lt;p>Midscene uses the FreeFn pattern to ensure that all resources — including network connections, temporary files, timers, and so on — are properly cleaned up after a long-chain task is completed. Even under exceptional circumstances, the resource cleanup mechanism guarantees that system resources are released.&lt;/p>
&lt;p>&lt;code>packages/web-integration/src/yaml/player.ts&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-typescript" data-lang="typescript">&lt;span class="line">&lt;span class="cl">&lt;span class="nx">freeFn&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">...(&lt;/span>&lt;span class="nx">newFreeFn&lt;/span> &lt;span class="o">||&lt;/span> &lt;span class="p">[]),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;restore-agent-onTaskStartTip&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">fn&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">()&lt;/span> &lt;span class="o">=&amp;gt;&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nx">agent&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">agent&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">onTaskStartTip&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="nx">originalOnTaskStartTip&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">];&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">....&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// free the resources
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">for&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="kr">const&lt;/span> &lt;span class="nx">fn&lt;/span> &lt;span class="k">of&lt;/span> &lt;span class="nx">freeFn&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">try&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// console.log(&amp;#39;freeing&amp;#39;, fn.name);
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="k">await&lt;/span> &lt;span class="nx">fn&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">fn&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// console.log(&amp;#39;freed&amp;#39;, fn.name);
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="k">catch&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nx">e&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// console.error(&amp;#39;error freeing&amp;#39;, fn.name, e);
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="context-optimization">Context Optimization
&lt;/h3>&lt;p>To reduce memory usage, Midscene also implements several context optimization strategies:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Visible element filtering&lt;/strong>: Only extract the visible elements on the page, reducing the size of the DOM tree&lt;/li>
&lt;li>&lt;strong>Image compression&lt;/strong>: Intelligently compress screenshots to reduce memory and transmission overhead&lt;/li>
&lt;li>&lt;strong>Viewport cropping&lt;/strong>: Crop context data according to the viewport range&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>It can be seen that although Mdscene has not introduced a dedicated memory framework to handle historical memory, it has nevertheless established a memory management mechanism to handle this collaboratively, enabling Midscene to maintain efficient memory usage when processing complex long-chain tasks. Through conversation history management to control memory growth, replanning limits to prevent infinite loops, and resource cleanup to ensure system stability, it ultimately achieves a reliable long-chain task execution system.&lt;/p>&lt;/blockquote>
&lt;hr>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;span class="lnt">46
&lt;/span>&lt;span class="lnt">47
&lt;/span>&lt;span class="lnt">48
&lt;/span>&lt;span class="lnt">49
&lt;/span>&lt;span class="lnt">50
&lt;/span>&lt;span class="lnt">51
&lt;/span>&lt;span class="lnt">52
&lt;/span>&lt;span class="lnt">53
&lt;/span>&lt;span class="lnt">54
&lt;/span>&lt;span class="lnt">55
&lt;/span>&lt;span class="lnt">56
&lt;/span>&lt;span class="lnt">57
&lt;/span>&lt;span class="lnt">58
&lt;/span>&lt;span class="lnt">59
&lt;/span>&lt;span class="lnt">60
&lt;/span>&lt;span class="lnt">61
&lt;/span>&lt;span class="lnt">62
&lt;/span>&lt;span class="lnt">63
&lt;/span>&lt;span class="lnt">64
&lt;/span>&lt;span class="lnt">65
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">graph TD
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> A[User] --&amp;gt;|Provide natural language description/JS SDK/YAML script| B(Midscene Core)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> B --&amp;gt;|Call| C{AI Model}
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> C --&amp;gt;|Return action/info| B
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> B --&amp;gt;|Control| D[Automation Agent]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> D --&amp;gt;|Operate| E[Target App/UI]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> E --&amp;gt;|Return UI state/screenshot| D
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> D --&amp;gt;|Send| B
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> B --&amp;gt;|Generate| F[Visual Reports]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> B --&amp;gt;|Provide| G[Playground&amp;lt;Debug&amp;gt; ]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> B --&amp;gt;|Use| H[Caching Mechanism]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> subgraph Target Platforms
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> E -- Web --&amp;gt; E1[Browser&amp;lt;Playwright/Puppeteer&amp;gt;]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> E -- Android --&amp;gt; E2[Android App]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> end
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> subgraph AI Model Types
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> C -- Multimodal LLM --&amp;gt; C1[GPT-4o, Gemini-2.5-Pro]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> C -- Visual-Language Model --&amp;gt; C2[Qwen2.5-VL, Doubao-1.5-thinking-vision-pro, UI-TARS]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> end
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> subgraph Auxiliary Tools
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> F --&amp;gt; F1[Report Files]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> G --&amp;gt; G1[Built-in Debug Environment]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> H --&amp;gt; H1[Improve efficiency/replay]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> end
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> I[MCP Clients] --&amp;gt;|Use capabilities directly| B
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div></description></item><item><title>A Review of the AI Automation Tool Midscene.js</title><link>https://chengxiaqiucao.github.io/en/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/</link><pubDate>Sun, 01 Jun 2025 00:00:00 +0000</pubDate><guid>https://chengxiaqiucao.github.io/en/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/</guid><description>&lt;img src="https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250521.webp" alt="Featured image of post A Review of the AI Automation Tool Midscene.js" />&lt;h2 id="introduction">Introduction
&lt;/h2>&lt;p>AI has been working its way ever more deeply into our day-to-day jobs. In the field of software testing, new AI-related testing tools and methods are emerging one after another. Previously we introduced a case of AI-driven testing combined with an mcp server; in this article we will introduce a domestically developed AI testing tool that has recently come to prominence, &lt;code>Midscene.js&lt;/code>.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250521_hu_4e0eed2c1d7f613e.webp"
width="1024"
height="972"
srcset="https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250521_hu_ed4d15700d5e45f4.webp 480w, https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250521_hu_4e0eed2c1d7f613e.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="105"
data-flex-basis="252px"
>
&lt;/p>
&lt;h2 id="introduction-to-midscenejs">Introduction to Midscene.js
&lt;/h2>&lt;p>&lt;code>MidScene.js&lt;/code> is an open-source AI automation testing tool released by the web-infra team at ByteDance. Built on multimodal large models, it understands our natural-language instructions through intelligent visual parsing of the page and then carries out automated operations. It can significantly reduce the complexity of writing automated test scripts, adapt better to changes in page structure and elements, and greatly improve the stability of automated test scripts.&lt;/p>
&lt;p>Official website: &lt;a class="link" href="https://midscenejs.com/" target="_blank" rel="noopener"
>https://midscenejs.com/&lt;/a>&lt;/p>
&lt;h2 id="how-midscene-works">How Midscene Works
&lt;/h2>&lt;p>Unlike the mcp server we discussed earlier, which used a general-purpose large model to understand the page and extended capabilities by calling local tools, Midscene uses multimodal large models such as &lt;code>ChatGPT-4o&lt;/code>, &lt;code>qwen-vl&lt;/code>, and ByteDance&amp;rsquo;s &lt;code>UI-TARS&lt;/code>-that is, large models that support visual input-to understand the page, which is much closer to the way we actually perform functional testing.&lt;/p>
&lt;p>MidScene first captures the current page screenshot along with detailed page structure information, then submits them together with the user instruction to the large model, which determines the location of the page control to be operated and decides the next action.&lt;/p>
&lt;p>Take entering &amp;ldquo;Today I will learn Playwright&amp;rdquo; into the task box on a to-do page as an example:&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250521-3_hu_1919dbe52d59b75c.webp"
width="1024"
height="359"
srcset="https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250521-3_hu_96263881e447c2c5.webp 480w, https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250521-3_hu_1919dbe52d59b75c.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="285"
data-flex-basis="684px"
>
&lt;/p>
&lt;p>MidScene&amp;rsquo;s internal operations are roughly as follows:&lt;/p>
&lt;ol>
&lt;li>Get the user instruction &amp;ldquo;Enter Learning Playwright in the task box and press Enter&amp;rdquo;&lt;/li>
&lt;li>MidScene takes a screenshot and obtains the overall element structure of the page&lt;/li>
&lt;li>Submit it to the large model to extract page features&lt;/li>
&lt;li>Obtain the large model&amp;rsquo;s analysis result and determine the next operation type (Tap) and the specific position (coordinates) of the control&lt;/li>
&lt;li>Plan the next operation&lt;/li>
&lt;li>Complete the execution&lt;/li>
&lt;/ol>
&lt;h2 id="choosing-a-large-model">Choosing a Large Model
&lt;/h2>&lt;p>From the analysis of Midscene&amp;rsquo;s principles above, MidScene mainly relies on the following capabilities of multimodal large models&lt;/p>
&lt;ol>
&lt;li>The ability to understand screenshots and  &lt;em>plan&lt;/em>  operation steps.&lt;/li>
&lt;li>The ability to give the coordinate information of a specified element (Visual Grounding).&lt;/li>
&lt;/ol>
&lt;p>The large models that support the above capabilities, as currently listed on the official site, include the following:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>OPENAI GPT-4o&lt;/strong>&lt;/li>
&lt;li>&lt;strong>Alibaba Qwen-2.5-VL&lt;/strong>&lt;/li>
&lt;li>&lt;strong>ByteDance UI-TARS&lt;/strong>&lt;/li>
&lt;li>&lt;strong>ByteDance Volcano Engine Doubao-1.5-thinking-vision-pro&lt;/strong>&lt;/li>
&lt;li>&lt;strong>Google Gemini-2.5-Pro&lt;/strong>&lt;/li>
&lt;/ul>
&lt;p>In terms of how it works, information such as screenshots and page structure has to be supplied to the large model, so the token consumption is fairly considerable. According to the official assessment, each operation usually consumes at least several thousand tokens. Among them, the model with the best cost-performance ratio recommended by the official team is QWen-VL.&lt;/p>
&lt;h2 id="using-the-chrome-extension">Using the Chrome Extension
&lt;/h2>&lt;p>The no-code Chrome extension approach can help us quickly understand how MidScene is applied.&lt;/p>
&lt;p>You can install it directly from the Chrome Web Store &lt;a class="link" href="https://chromewebstore.google.com/detail/midscenejs/gbldofcpkknbggpkmbdaefngejllnief" target="_blank" rel="noopener"
>Midscene Extension&lt;/a>&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250521-2_hu_f739d517918e3f2d.webp"
width="1024"
height="319"
srcset="https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250521-2_hu_b7c9efe7ea7afa.webp 480w, https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250521-2_hu_f739d517918e3f2d.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="320"
data-flex-basis="770px"
>
&lt;/p>
&lt;h3 id="configuring-the-large-model">Configuring the Large Model
&lt;/h3>&lt;p>After enabling the extension, you need to configure the large model to use. Here we use the Alibaba Qwen multimodal model &lt;code>qwen-vl-max-latest&lt;/code>, which consumes relatively few tokens; you can apply for the corresponding API Key through the Alibaba Cloud Bailian platform, and applications currently come with a free quota of 1 million tokens.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250520-2_hu_1e7b7a961f3d0cf4.webp"
width="1024"
height="185"
srcset="https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250520-2_hu_6291bcebb25b5578.webp 480w, https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250520-2_hu_1e7b7a961f3d0cf4.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="552"
data-flex-basis="1326px"
>
&lt;/p>
&lt;p>After the application is complete, configure the corresponding large model parameters in the extension&amp;rsquo;s model settings screen; the Qwen model requires the following four parameters&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">OPENAI_BASE_URL=&amp;#34;https://dashscope.aliyuncs.com/compatible-mode/v1&amp;#34;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">OPENAI_API_KEY=&amp;#34;sk- your API KEY&amp;#34;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">MIDSCENE_MODEL_NAME=&amp;#34;qwen-vl-max-latest&amp;#34;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">MIDSCENE_USE_QWEN_VL=1
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="operating-the-browser">Operating the Browser
&lt;/h3>&lt;p>Next you can experience Midscene&amp;rsquo;s control of the browser in the extension interface. It mainly supports four behaviors:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Action&lt;/strong>: Corresponds to AI-planned operations; Midscene automatically plans the operation steps and executes them. It is smarter but slower, and the results depend on the quality of the large model.&lt;/li>
&lt;li>&lt;strong>Query&lt;/strong>: Extracts data directly from the UI and, with the reasoning ability of multimodal AI, achieves intelligent extraction&lt;/li>
&lt;li>&lt;strong>Assert&lt;/strong>: Describes an assertion condition in natural language and lets the AI judge whether the condition is true&lt;/li>
&lt;li>&lt;strong>Tap&lt;/strong>: Corresponds to an immediate page-click operation; Midscene executes it directly, and the large model only handles low-level tasks such as element locating. It is more efficient and is suitable when the operation to perform is already determined&lt;/li>
&lt;/ul>
&lt;p>We can enter prompt instructions using AI prompts close to natural language; for different behavior modes, the extension drives the browser to perform different operations and reports the results.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250520_hu_88f879538f9c0fc9.webp"
width="1024"
height="482"
srcset="https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250520_hu_a705150c5ab15621.webp 480w, https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250520_hu_88f879538f9c0fc9.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="212"
data-flex-basis="509px"
>
&lt;/p>
&lt;p>The concrete execution process can also be seen in the video demo below.&lt;/p>
&lt;h2 id="script-integration">Script Integration
&lt;/h2>&lt;p>Besides calling Midscene through the browser extension, the more recommended approach is to integrate Midscene capabilities through test framework scripts.&lt;/p>
&lt;p>With script integration, you also need to configure the relevant model call parameters, the same variable values configured in the extension, except that the relevant variables need to be set as &lt;strong>system environment variables&lt;/strong>&lt;/p>
&lt;p>Because Midscene is a JS-based tool, integrating it with a test framework here also requires JS support. Here we take Playwright as an example&lt;/p>
&lt;h3 id="installation">Installation
&lt;/h3>&lt;p>First, of course, you need the Playwright framework; enter the project directory, initialize and install Playwright, then install Midscene&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-powershell" data-lang="powershell">&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">npm&lt;/span> &lt;span class="n">init&lt;/span> &lt;span class="n">playwright&lt;/span>&lt;span class="nv">@latest&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">npm&lt;/span> &lt;span class="n">install&lt;/span> &lt;span class="nv">@midscene&lt;/span>&lt;span class="p">/&lt;/span>&lt;span class="n">web&lt;/span> &lt;span class="p">-&lt;/span>&lt;span class="n">-save-dev&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="playwright-framework-configuration">Playwright Framework Configuration
&lt;/h3>&lt;p>In the &lt;code>playwright.config.ts&lt;/code> file, configure the framework&amp;rsquo;s test discovery directory and test scripts, load environment variables, and set basic configurations such as browser type and execution strategy&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;span class="lnt">46
&lt;/span>&lt;span class="lnt">47
&lt;/span>&lt;span class="lnt">48
&lt;/span>&lt;span class="lnt">49
&lt;/span>&lt;span class="lnt">50
&lt;/span>&lt;span class="lnt">51
&lt;/span>&lt;span class="lnt">52
&lt;/span>&lt;span class="lnt">53
&lt;/span>&lt;span class="lnt">54
&lt;/span>&lt;span class="lnt">55
&lt;/span>&lt;span class="lnt">56
&lt;/span>&lt;span class="lnt">57
&lt;/span>&lt;span class="lnt">58
&lt;/span>&lt;span class="lnt">59
&lt;/span>&lt;span class="lnt">60
&lt;/span>&lt;span class="lnt">61
&lt;/span>&lt;span class="lnt">62
&lt;/span>&lt;span class="lnt">63
&lt;/span>&lt;span class="lnt">64
&lt;/span>&lt;span class="lnt">65
&lt;/span>&lt;span class="lnt">66
&lt;/span>&lt;span class="lnt">67
&lt;/span>&lt;span class="lnt">68
&lt;/span>&lt;span class="lnt">69
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-typescript" data-lang="typescript">&lt;span class="line">&lt;span class="cl">&lt;span class="kr">import&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">defineConfig&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nx">devices&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="kr">from&lt;/span> &lt;span class="s2">&amp;#34;@playwright/test&amp;#34;&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kr">import&lt;/span> &lt;span class="nx">dotenv&lt;/span> &lt;span class="kr">from&lt;/span> &lt;span class="s2">&amp;#34;dotenv&amp;#34;&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="cm">/* Load environment variables from the .env file via dotenv */&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nx">dotenv&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">config&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kr">export&lt;/span> &lt;span class="k">default&lt;/span> &lt;span class="nx">defineConfig&lt;/span>&lt;span class="p">({&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="nx">testDir&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s2">&amp;#34;./e2e&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="nx">testMatch&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s2">&amp;#34;**/*.spec.ts&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="nx">timeout&lt;/span>: &lt;span class="kt">10&lt;/span> &lt;span class="o">*&lt;/span> &lt;span class="mi">60&lt;/span> &lt;span class="o">*&lt;/span> &lt;span class="mi">1000&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="cm">/* Run tests in files in parallel */&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="nx">fullyParallel&lt;/span>: &lt;span class="kt">false&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="cm">/* Fail the build on CI if you accidentally left test.only in the source code. */&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="nx">forbidOnly&lt;/span>: &lt;span class="kt">Boolean&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">process&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">env&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">CI&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="cm">/* Retry on CI only */&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="nx">retries&lt;/span>: &lt;span class="kt">process.env.CI&lt;/span> &lt;span class="o">?&lt;/span> &lt;span class="nx">2&lt;/span> : &lt;span class="kt">0&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="cm">/* Opt out of parallel tests on CI. */&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="nx">workers&lt;/span>: &lt;span class="kt">process.env.CI&lt;/span> &lt;span class="o">?&lt;/span> &lt;span class="nx">1&lt;/span> : &lt;span class="kt">undefined&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="cm">/* Reporter to use. See https://playwright.dev/docs/test-reporters */&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="nx">reporter&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[[&lt;/span>&lt;span class="s2">&amp;#34;line&amp;#34;&lt;/span>&lt;span class="p">],&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;@midscene/web/playwright-report&amp;#34;&lt;/span>&lt;span class="p">]],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="cm">/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="nx">use&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    &lt;span class="cm">/* Base URL to use in actions like `await page.goto(&amp;#39;/&amp;#39;)`. */&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    &lt;span class="c1">// baseURL: &amp;#39;http://127.0.0.1:3000&amp;#39;,
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    &lt;span class="cm">/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    &lt;span class="nx">trace&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s2">&amp;#34;on-first-retry&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="cm">/* Configure projects for major browsers */&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="nx">projects&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">      &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s2">&amp;#34;chromium&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">      &lt;span class="nx">use&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="p">...&lt;/span>&lt;span class="nx">devices&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;Desktop Chrome&amp;#34;&lt;/span>&lt;span class="p">]&lt;/span> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">});&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="test-scripts">Test Scripts
&lt;/h3>&lt;p>Import the Midscene library through a separate fixture script&lt;/p>
&lt;p>fixture.ts&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-typescript" data-lang="typescript">&lt;span class="line">&lt;span class="cl">&lt;span class="kr">import&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">test&lt;/span> &lt;span class="kr">as&lt;/span> &lt;span class="nx">base&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="kr">from&lt;/span> &lt;span class="s1">&amp;#39;@playwright/test&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kr">import&lt;/span> &lt;span class="kr">type&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">PlayWrightAiFixtureType&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="kr">from&lt;/span> &lt;span class="s1">&amp;#39;@midscene/web/playwright&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kr">import&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">PlaywrightAiFixture&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="kr">from&lt;/span> &lt;span class="s1">&amp;#39;@midscene/web/playwright&amp;#39;&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kr">export&lt;/span> &lt;span class="kr">const&lt;/span> &lt;span class="nx">test&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="nx">base&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">extend&lt;/span>&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">PlayWrightAiFixtureType&lt;/span>&lt;span class="p">&amp;gt;(&lt;/span>&lt;span class="nx">PlaywrightAiFixture&lt;/span>&lt;span class="p">({&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="nx">waitForNetworkIdleTimeout&lt;/span>: &lt;span class="kt">10000&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="c1">// Optional, the timeout for waiting for network idle during interaction; default is 2000ms; set to 0 to disable the timeout
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}));&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Write a script to test the &lt;code>https://todomvc.com/&lt;/code> to-do list sample project, using API methods such as &lt;code>.ai&lt;/code>, &lt;code>.aiTap&lt;/code>, &lt;code>.aiQuery&lt;/code>, and &lt;code>.aiAssert&lt;/code>, corresponding to the four typical operations mentioned earlier.&lt;/p>
&lt;p>todo_spec.ts&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;span class="lnt">46
&lt;/span>&lt;span class="lnt">47
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-typescript" data-lang="typescript">&lt;span class="line">&lt;span class="cl">&lt;span class="kr">import&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">expect&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="kr">from&lt;/span> &lt;span class="s2">&amp;#34;@playwright/test&amp;#34;&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kr">import&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">test&lt;/span> &lt;span class="p">}&lt;/span> &lt;span class="kr">from&lt;/span> &lt;span class="s2">&amp;#34;./fixture&amp;#34;&lt;/span>&lt;span class="p">;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nx">test&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">beforeEach&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="kr">async&lt;/span> &lt;span class="p">({&lt;/span> &lt;span class="nx">page&lt;/span> &lt;span class="p">})&lt;/span> &lt;span class="o">=&amp;gt;&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="k">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="kr">goto&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;https://todomvc.com/examples/react/dist/&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">});&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nx">test&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;ai todo - Chinese Prompt&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="kr">async&lt;/span> &lt;span class="p">({&lt;/span> &lt;span class="nx">ai&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nx">aiQuery&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nx">aiAssert&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nx">aiTap&lt;/span> &lt;span class="p">})&lt;/span> &lt;span class="o">=&amp;gt;&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="c1">// .ai - Generic AI operation method
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="k">await&lt;/span> &lt;span class="nx">ai&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;在任务框 input 输入 今天学习 Playwright，按回车键&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="k">await&lt;/span> &lt;span class="nx">ai&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;在任务框 input 输入 明天学习 js脚本，按回车键&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="k">await&lt;/span> &lt;span class="nx">ai&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;在任务框 input 输入 后天学习 AI测试，按回车键&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="k">await&lt;/span> &lt;span class="nx">ai&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;将鼠标移动到任务列表中的第二项&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="k">await&lt;/span> &lt;span class="nx">aiTap&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;第二项任务右边的删除按钮&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="c1">// .aiTap - Specify the operation type
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="k">await&lt;/span> &lt;span class="nx">aiTap&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;第二条任务左边的勾选按钮&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="k">await&lt;/span> &lt;span class="nx">aiTap&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;任务列表下面的 completed 状态按钮&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// .aiQuery - Page information extraction operation
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>  &lt;span class="kr">const&lt;/span> &lt;span class="nx">list&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="k">await&lt;/span> &lt;span class="nx">aiQuery&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;string[], 完整的任务列表&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="nx">expect&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">list&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">length&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="nx">toEqual&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1">// .aiAssert - Assertion operation
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">  &lt;span class="k">await&lt;/span> &lt;span class="nx">aiAssert&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;列表下方有一个区域显示有 &amp;#34;1 item left&amp;#34;&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">});&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Run the script:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-powershell" data-lang="powershell">&lt;span class="line">&lt;span class="cl">&lt;span class="n">npx&lt;/span> &lt;span class="n">playwright&lt;/span> &lt;span class="n">test&lt;/span> &lt;span class="p">-&lt;/span>&lt;span class="n">-headed&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>The execution process can be seen in the video I recorded&lt;/p>
&lt;p>【】&lt;/p>
&lt;h3 id="visual-result-report">Visual Result Report
&lt;/h3>&lt;p>The report is one of Midscene&amp;rsquo;s highlights. Through it you can replay the entire execution process, with detailed display of the AI&amp;rsquo;s spatial judgment process and concrete operation details, making it easy to debug and optimize scripts.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250520-1_hu_fb7e8fb8ed9ae66b.webp"
width="1024"
height="479"
srcset="https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250520-1_hu_adf181060651d5e3.webp 480w, https://chengxiaqiucao.github.io/post/098-midscene.js%E7%9A%84%E4%BD%BF%E7%94%A8/snap_20250520-1_hu_fb7e8fb8ed9ae66b.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="213"
data-flex-basis="512px"
>
&lt;/p>
&lt;h2 id="yaml-file-driven">YAML File-Driven
&lt;/h2>&lt;p>Besides integration through test framework scripts, Midscene also supports writing test scripts directly with YAML files, enabling no-code script driving, similar to the keyword-driven approach of traditional automation.&lt;/p>
&lt;p>In essence, this approach still converts the corresponding keywords into the relevant APIs supported by Midscene for driving.&lt;/p>
&lt;p>A format like the following, operating a weather website:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-YAML" data-lang="YAML">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">web&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">url&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">https://www.bing.com&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">tasks&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">搜索天气&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">flow&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">ai&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">搜索 &amp;#34;今日天气&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">sleep&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">3000&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">检查结果&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">flow&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">aiAssert&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">结果中展示了天气信息&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>To run YAML-format scripts, you need to install Midscene&amp;rsquo;s command-line support&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-powershell" data-lang="powershell">&lt;span class="line">&lt;span class="cl">&lt;span class="n">npm&lt;/span> &lt;span class="n">install&lt;/span> &lt;span class="nv">@midscene&lt;/span>&lt;span class="p">/&lt;/span>&lt;span class="nb">cli &lt;/span>&lt;span class="p">-&lt;/span>&lt;span class="n">-save-dev&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c"># Run&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">npx&lt;/span> &lt;span class="n">midscene&lt;/span> &lt;span class="p">./&lt;/span>&lt;span class="n">weather&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="py">yaml&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="mcp-approach">MCP Approach
&lt;/h2>&lt;p>Beyond the methods above, Midscene also offers a way to act as a local MCP server. This approach essentially wraps MidScene&amp;rsquo;s Chrome extension as a local capability inside MCP, then drives the browser by combining a large model with the mcp server.&lt;/p>
&lt;p>For an introduction to and usage of mcp server, see my earlier related article 【】&lt;/p>
&lt;p>mcp server configuration:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;mcpServers&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;mcp-midscene&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;command&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;npx&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;args&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="s2">&amp;#34;-y&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;@midscene/mcp&amp;#34;&lt;/span>&lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;env&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;MIDSCENE_MODEL_NAME&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;REPLACE_WITH_YOUR_MODEL_NAME&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;OPENAI_API_KEY&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;REPLACE_WITH_YOUR_OPENAI_API_KEY&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;MCP_SERVER_REQUEST_TIMEOUT&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;800000&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="limitations-of-the-current-version">Limitations of the Current Version
&lt;/h2>&lt;p>Although the Midsence tool has already shown considerable potential and is still being continuously updated and iterated, it still has quite a few shortcomings in practical use, mainly in the following areas:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Limited interaction types&lt;/strong>: Currently only click, drag (supported only in the UI-TARS model), input, keyboard, and scroll operations are supported.&lt;/li>
&lt;li>&lt;strong>Stability risks&lt;/strong>: The return values of AI models cannot be guaranteed to be 100% accurate. Writing good prompts is demanding&lt;/li>
&lt;li>&lt;strong>Element recognition&lt;/strong>: Some large models are not very good at recognizing elements, such as interactions with iframe and canvas elements. Moreover, Chrome&amp;rsquo;s native controls like pop-up prompts and right-click menus are not yet supported.&lt;/li>
&lt;li>&lt;strong>Higher cost&lt;/strong>: Being based on visual recognition, token consumption is considerable, and if a paid large model is used, the cost can be high.&lt;/li>
&lt;/ul>
&lt;p>But these flaws do not overshadow the merits: Midscene has already taken a solid step forward in improving UI automation testing with AI capabilities! We will continue to follow its further development!&lt;/p>
&lt;hr>
&lt;h3 id="further-reading">Further Reading:
&lt;/h3>&lt;p>【】
【】&lt;/p>
&lt;p>Join the group, outline&lt;/p></description></item><item><title>Microsoft Releases Magentic UI, a Hands-On Review of the Interactive AI Agent Assistant</title><link>https://chengxiaqiucao.github.io/en/post/096-magenticui%E8%AF%84%E6%B5%8B/</link><pubDate>Fri, 30 May 2025 00:00:00 +0000</pubDate><guid>https://chengxiaqiucao.github.io/en/post/096-magenticui%E8%AF%84%E6%B5%8B/</guid><description>&lt;img src="https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/magentic_logo.webp" alt="Featured image of post Microsoft Releases Magentic UI, a Hands-On Review of the Interactive AI Agent Assistant" />&lt;h2 id="what-is-magentic-ui">What Is Magentic UI?
&lt;/h2>&lt;p>&lt;code>Magentic UI&lt;/code> is an open-source Agent assistant that Microsoft released with much fanfare on May 19, and it just updated to its second version, 0.04, on the 24th&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526_hu_9b68e96ee9a20ceb.webp"
width="1024"
height="284"
srcset="https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526_hu_987fa047fbc9f36d.webp 480w, https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526_hu_9b68e96ee9a20ceb.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="361"
data-flex-basis="866px"
>
&lt;/p>
&lt;p>Judging from the official introduction, the goal is to build a &lt;strong>human-centered&lt;/strong> intelligent assistant, powered at its core by several different agent systems, capable of web browsing and operation, code generation and execution, and file generation and analysis.&lt;/p>
&lt;p>What mainly sets it apart from other AI browser tools is its &lt;strong>transparent and controllable interactive interface&lt;/strong>, which supports efficient human-AI collaborative participation. The system is built on Microsoft&amp;rsquo;s agent-building framework AutoGen and is currently still at the prototype research stage.&lt;/p>
&lt;p>Core features include:&lt;/p>
&lt;p>🧑‍🤝‍🧑 &lt;strong>Collaborative planning&lt;/strong>: users and the AI work together through chat and a plan editor to create and revise step-by-step execution plans.&lt;br>
🤝 &lt;strong>Collaborative tasks&lt;/strong>: users can intervene in real time and guide task execution directly through the web browser or the chat interface. Magentic-UI can proactively ask for confirmation or request assistance when needed.&lt;br>
🛡️ &lt;strong>Action guard&lt;/strong>: sensitive operations require explicit user approval before they can be executed.&lt;br>
🧠 &lt;strong>Plan learning and retrieval&lt;/strong>: it learns from past tasks to optimize future automation workflows and saves good solutions into a plan library. Stored plans can be invoked automatically or manually in subsequent tasks.&lt;br>
🔀 &lt;strong>Parallel task execution&lt;/strong>: it supports running multiple tasks in parallel, and a session status indicator shows in real time when Magentic-UI needs your input or has completed a task.&lt;/p>
&lt;h2 id="design-architecture">Design Architecture
&lt;/h2>&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526-1_hu_6105176311731903.webp"
width="1024"
height="777"
srcset="https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526-1_hu_8ee1935638f54b1e.webp 480w, https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526-1_hu_6105176311731903.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="131"
data-flex-basis="316px"
>
&lt;/p>
&lt;p>The underlying system of &lt;strong>Magentic-UI&lt;/strong> consists of a group of specialized agents adapted from AutoGen&amp;rsquo;s &lt;strong>Magentic-One&lt;/strong> system (shown in the figure above), with each agent implementing different functions through modular collaboration:&lt;/p>
&lt;h3 id="agent-functionality">Agent Functionality
&lt;/h3>&lt;h4 id="orchestrator">&lt;strong>Orchestrator&lt;/strong>
&lt;/h4>&lt;ul>
&lt;li>&lt;strong>Functional role&lt;/strong>: the main LLM-based controlling agent, responsible for collaboratively making plans with the user, deciding when to request user feedback, and assigning subtasks to other agents.&lt;/li>
&lt;li>&lt;strong>Collaboration flow&lt;/strong>:
&lt;ol>
&lt;li>Jointly create a step-by-step execution plan with the user;&lt;/li>
&lt;li>Dynamically determine the points where user intervention is needed;&lt;/li>
&lt;li>Dispatch subtasks to other agents for execution.&lt;/li>
&lt;/ol>
&lt;/li>
&lt;/ul>
&lt;h4 id="websurfer">&lt;strong>WebSurfer&lt;/strong>
&lt;/h4>&lt;ul>
&lt;li>&lt;strong>Functional role&lt;/strong>: an LLM agent equipped with a web browser, supporting multi-round web interaction operations.&lt;/li>
&lt;li>&lt;strong>Core capabilities&lt;/strong>:
&lt;ul>
&lt;li>Following the Orchestrator&amp;rsquo;s instructions, perform operations such as clicking, typing, scrolling, and page navigation;&lt;/li>
&lt;li>&lt;strong>Beyond AutoGen&amp;rsquo;s multimodal web browser&lt;/strong>: adds tab management, option selection, file upload, and multimodal query support.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h4 id="coder">&lt;strong>Coder&lt;/strong>
&lt;/h4>&lt;ul>
&lt;li>&lt;strong>Functional role&lt;/strong>: an LLM agent equipped with a Docker code execution container.&lt;/li>
&lt;li>&lt;strong>Core capabilities&lt;/strong>:
&lt;ul>
&lt;li>Write and execute Python and Shell commands;&lt;/li>
&lt;li>Feed the execution results back to the Orchestrator.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h4 id="filesurfer">**FileSurfer
&lt;/h4>&lt;p>**&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Functional role&lt;/strong>: an LLM agent integrating a Docker container with the MarkItDown package file-conversion tool.&lt;/li>
&lt;li>&lt;strong>Core capabilities&lt;/strong>:
&lt;ul>
&lt;li>Locate files in Magentic-UI&amp;rsquo;s controlled directory;&lt;/li>
&lt;li>Convert files to Markdown format and support question answering over their content.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h4 id="userproxy">&lt;strong>UserProxy&lt;/strong>
&lt;/h4>&lt;ul>
&lt;li>&lt;strong>Functional role&lt;/strong>: the agent role that interacts with the system on behalf of the user.&lt;/li>
&lt;li>&lt;strong>Collaboration mode&lt;/strong>: the Orchestrator can delegate tasks directly to the user (rather than to other agents) to complete.&lt;/li>
&lt;/ul>
&lt;h3 id="user-interaction-flow">User Interaction Flow
&lt;/h3>&lt;p>The interaction flow of a user using Magentic UI can be illustrated by the following diagram:
&lt;a class="link" href="https://mermaid.live/edit#pako:eNplVFtPGlEQ_ivkPKOyiCKYtGm9VFut9zbpwgPKqiSVNSsk2g2JNl5AUaCo0YgXLF7SVNCmliqif4Zzdvdf9OyZZcW6Tztzvm_mmzkzR0Zjol9AbjQh-aYnLcPtnqCFfq94ZfOcRIs4kVKvi2qhSK6-ei11dS8sr3n1Po2XTsj2Csn8bNB2F_HqEd67V2Ir3lYgv2bANrnXNyEEQ4GxupFui7J5SKJJHF0mFydqPouj3yIGuo2ijWMdsXrI2O2GAPVhjyYDhnK3rd6nlK24tn_sfc7GuSv19wnk5niSSCq5WwiirayT7UvQbRI5KIea4GiHSDoeEkFShuqQwUXS65Vypqq8Q2eQYok2oAFHj7TdXEPlIU82b2iN2o8c1FGLVbJ5NZ_D-ThVy047eTJfIhtnldJ3JbmML3bw13NI6zV1dTLkGx4nC3jVOCWxMzUbx3dbJL1RLegNw3XJJB7Tsrf4NgEg0BIxw3UxWLeMy2kcW4dT5aqED9ZeVuuaCY_CNOClYqWcBgxEA4D--QOSMBYKiEFLz-Cjt1sv86MwOhSWxgWJpXrLA1Upp7TsNXSwqtmktNEhBPg73rjNmz_A03tztPCM0Rn4LNRk6eFxbpH2kI5lpfTnGXpkRpD6JXF2joF7n0wHia3Rxj4VJgT91Ya9ZZT3stGGnQJOnsKgwkWabXsHQMPqeWL1mhbY79no7BSYu08msXmSiUEGvL-Ci7_-i83wNDHD9_Nq_hKXt7TNXbVQwBuHeO_ocV76GWZABqVaZl49XTAW4GyRzo4Zc6BWwyAPS25sXf4vThRqWdXGDIKQOFlMwKbV-snaN6W0z_xDvFKKkotjcr2gnK95a1NWyxgyJffVKhk2BoBk5mkIpZQmB-a19NXyu0z-MLNH6IqkjGcrFVU2Lp9yRxjoA6979w-9rchK37yAH7lDUliwoilBmvLpJpJ1vAeFJoUpwYPc9HdclISZkAd5ghHKmvYFP4niVJUoieGJSeQe932eoVZ42u8LCe0BH92gRwgdJ0FqE8PBEHJzLhYCuWU0i9yNLU31dpvLaWtq4Zycw95kRXPI7eDqHZzdaXM4XdTlbOQiVvSF5bTVu2wue6O92c412m0tDluzFQn-QEiUeuEdZ8955B-N54jD" target="_blank" rel="noopener"
>&lt;img src="https://mermaid.ink/img/pako:eNplVFtPGlEQ_ivkPKOyiCKYtGm9VFut9zbpwgPKqiSVNSsk2g2JNl5AUaCo0YgXLF7SVNCmliqif4Zzdvdf9OyZZcW6Tztzvm_mmzkzR0Zjol9AbjQh-aYnLcPtnqCFfq94ZfOcRIs4kVKvi2qhSK6-ei11dS8sr3n1Po2XTsj2Csn8bNB2F_HqEd67V2Ir3lYgv2bANrnXNyEEQ4GxupFui7J5SKJJHF0mFydqPouj3yIGuo2ijWMdsXrI2O2GAPVhjyYDhnK3rd6nlK24tn_sfc7GuSv19wnk5niSSCq5WwiirayT7UvQbRI5KIea4GiHSDoeEkFShuqQwUXS65Vypqq8Q2eQYok2oAFHj7TdXEPlIU82b2iN2o8c1FGLVbJ5NZ_D-ThVy047eTJfIhtnldJ3JbmML3bw13NI6zV1dTLkGx4nC3jVOCWxMzUbx3dbJL1RLegNw3XJJB7Tsrf4NgEg0BIxw3UxWLeMy2kcW4dT5aqED9ZeVuuaCY_CNOClYqWcBgxEA4D--QOSMBYKiEFLz-Cjt1sv86MwOhSWxgWJpXrLA1Upp7TsNXSwqtmktNEhBPg73rjNmz_A03tztPCM0Rn4LNRk6eFxbpH2kI5lpfTnGXpkRpD6JXF2joF7n0wHia3Rxj4VJgT91Ya9ZZT3stGGnQJOnsKgwkWabXsHQMPqeWL1mhbY79no7BSYu08msXmSiUEGvL-Ci7_-i83wNDHD9_Nq_hKXt7TNXbVQwBuHeO_ocV76GWZABqVaZl49XTAW4GyRzo4Zc6BWwyAPS25sXf4vThRqWdXGDIKQOFlMwKbV-snaN6W0z_xDvFKKkotjcr2gnK95a1NWyxgyJffVKhk2BoBk5mkIpZQmB-a19NXyu0z-MLNH6IqkjGcrFVU2Lp9yRxjoA6979w-9rchK37yAH7lDUliwoilBmvLpJpJ1vAeFJoUpwYPc9HdclISZkAd5ghHKmvYFP4niVJUoieGJSeQe932eoVZ42u8LCe0BH92gRwgdJ0FqE8PBEHJzLhYCuWU0i9yNLU31dpvLaWtq4Zycw95kRXPI7eDqHZzdaXM4XdTlbOQiVvSF5bTVu2wue6O92c412m0tDluzFQn-QEiUeuEdZ8955B-N54jD?type=png"
loading="lazy"
>
&lt;/a>&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;span class="lnt">46
&lt;/span>&lt;span class="lnt">47
&lt;/span>&lt;span class="lnt">48
&lt;/span>&lt;span class="lnt">49
&lt;/span>&lt;span class="lnt">50
&lt;/span>&lt;span class="lnt">51
&lt;/span>&lt;span class="lnt">52
&lt;/span>&lt;span class="lnt">53
&lt;/span>&lt;span class="lnt">54
&lt;/span>&lt;span class="lnt">55
&lt;/span>&lt;span class="lnt">56
&lt;/span>&lt;span class="lnt">57
&lt;/span>&lt;span class="lnt">58
&lt;/span>&lt;span class="lnt">59
&lt;/span>&lt;span class="lnt">60
&lt;/span>&lt;span class="lnt">61
&lt;/span>&lt;span class="lnt">62
&lt;/span>&lt;span class="lnt">63
&lt;/span>&lt;span class="lnt">64
&lt;/span>&lt;span class="lnt">65
&lt;/span>&lt;span class="lnt">66
&lt;/span>&lt;span class="lnt">67
&lt;/span>&lt;span class="lnt">68
&lt;/span>&lt;span class="lnt">69
&lt;/span>&lt;span class="lnt">70
&lt;/span>&lt;span class="lnt">71
&lt;/span>&lt;span class="lnt">72
&lt;/span>&lt;span class="lnt">73
&lt;/span>&lt;span class="lnt">74
&lt;/span>&lt;span class="lnt">75
&lt;/span>&lt;span class="lnt">76
&lt;/span>&lt;span class="lnt">77
&lt;/span>&lt;span class="lnt">78
&lt;/span>&lt;span class="lnt">79
&lt;/span>&lt;span class="lnt">80
&lt;/span>&lt;span class="lnt">81
&lt;/span>&lt;span class="lnt">82
&lt;/span>&lt;span class="lnt">83
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">graph TD
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    A[用户发起请求] --&amp;gt; B[输入文本/附加图片];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    B --&amp;gt; C{Magentic-UI 生成分步计划};
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    C -- 生成成功 --&amp;gt; D[用户进入计划编辑界面];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    C -- 生成失败 --&amp;gt; C1[提示用户重新输入];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    C1 --&amp;gt; B;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    D -- 用户编辑计划 --&amp;gt; E{编辑操作};
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    E -- 添加/删除/修改步骤 --&amp;gt; D;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    E -- 确认完成 --&amp;gt; F[总控代理存储计划];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    F --&amp;gt; G[启动计划执行引擎];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    G --&amp;gt; H{按顺序执行步骤};
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    H --&amp;gt; I{当前步骤类型?};
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    subgraph 具体步骤执行
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">        direction LR
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">        I -- WebSurfer --&amp;gt; J[执行网页操作];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">        I -- Coder --&amp;gt; K[生成并执行代码];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">        I -- FileSurfer --&amp;gt; L[处理文件];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">        I -- UserProxy --&amp;gt; M[提示用户手动操作];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    end
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    J --&amp;gt; N{步骤是否成功完成?};
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    K --&amp;gt; N;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    L --&amp;gt; N;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    M --&amp;gt; N;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    N -- 是 --&amp;gt; O{所有步骤均已完成?};
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    N -- 否 --&amp;gt; P[记录错误原因];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    P --&amp;gt; Q{是否需要重新规划?};
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    Q -- 是 --&amp;gt; R[请求用户许可重新规划];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    R -- 同意 --&amp;gt; C;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    R -- 拒绝 --&amp;gt; S[终止流程];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    Q -- 否 --&amp;gt; S;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    O -- 是 --&amp;gt; T[生成最终结果];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    O -- 否 --&amp;gt; H;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    T --&amp;gt; U[向用户呈现结果];
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">    U --&amp;gt; V[结束];
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;hr>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Input and plan generation&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>The user triggers the flow through text/images, and the system generates an initial plan. If it fails, the user is prompted to re-enter.&lt;/li>
&lt;li>The user iteratively refines the plan through the editing interface, and after confirmation, moves to the execution phase.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Plan execution logic&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>The Orchestrator assigns tasks step by step to the corresponding agents (WebSurfer/Coder/FileSurfer) or to the user.&lt;/li>
&lt;li>After each step is completed, the status is verified; if it fails, a decision is made on whether replanning is needed (requiring user authorization).&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Dynamic control and termination&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>The user can intervene at any time: pause execution, modify the plan, or terminate the flow.&lt;/li>
&lt;li>Once all steps are completed, the final result is delivered, with transparent error feedback provided in exceptional cases.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;h2 id="tool-deployment">Tool Deployment
&lt;/h2>&lt;p>&lt;strong>Magentic AI&lt;/strong> is mainly developed in Python, with the web part based on FastAPI. Its AI control primarily uses Playwright to control a virtual browser inside a &lt;strong>Docker&lt;/strong> container, which can be displayed to the user in real time. The large model behind it is mainly used through the API access methods of various open large models.&lt;/p>
&lt;p>Therefore, to deploy Magentic UI, you first need to confirm the relevant prerequisites:&lt;/p>
&lt;ul>
&lt;li>Docker is installed; if it is a Windows system, install Docker Desktop and integrate it with WSL&lt;/li>
&lt;li>Provide the &lt;strong>API KEY&lt;/strong> for accessing the large model; the default is &lt;strong>OPENAI&lt;/strong>&amp;rsquo;s API KEY&lt;/li>
&lt;li>A Python runtime environment with a version &lt;strong>&amp;gt;3.10&lt;/strong>&lt;/li>
&lt;/ul>
&lt;p>The tool was deployed in WSL. First create a Python virtual environment, then install Magentic AI and its related dependencies&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">python3 -m venv .venv
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">source&lt;/span> .venv/bin/activate
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">pip3 install magentic-ui
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Make sure Docker is started, and before running Magentic UI there should be no related containers running&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">docker ps
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>For the large model, you can use OPENAI on Microsoft Azure AI; after completing the configuration, set the corresponding api key as the environment variable &lt;code>OPENAI_API_KEY&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">&lt;span class="nb">export&lt;/span> &lt;span class="nv">OPENAI_API_KEY&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;YOUR_API_KEY&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>In addition, Magentic UI itself needs to be configured for the large model; the Azure AI configuration template is as follows:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-YAML" data-lang="YAML">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">model_config&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="cp">&amp;amp;client&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">  &lt;/span>&lt;span class="nt">provider&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">AzureOpenAIChatCompletionClient&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">  &lt;/span>&lt;span class="nt">config&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">    &lt;/span>&lt;span class="nt">model&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">gpt-4o&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">    &lt;/span>&lt;span class="nt">azure_endpoint&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;&amp;lt;YOUR ENDPOINT&amp;gt;&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">    &lt;/span>&lt;span class="nt">azure_deployment&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;&amp;lt;YOUR DEPLOYMENT&amp;gt;&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">    &lt;/span>&lt;span class="nt">api_version&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;2024-10-21&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">    &lt;/span>&lt;span class="nt">azure_ad_token_provider&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">      &lt;/span>&lt;span class="nt">provider&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">autogen_ext.auth.azure.AzureTokenProvider&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">      &lt;/span>&lt;span class="nt">config&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">        &lt;/span>&lt;span class="nt">provider_kind&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">DefaultAzureCredential&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">        &lt;/span>&lt;span class="nt">scopes&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">          &lt;/span>- &lt;span class="l">https://cognitiveservices.azure.com/.default&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">    &lt;/span>&lt;span class="nt">max_retries&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">10&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">orchestrator_client&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="cp">*client&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">coder_client&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="cp">*client&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">web_surfer_client&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="cp">*client&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">file_surfer_client&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="cp">*client&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">action_guard_client&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="cp">*client&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="running">Running
&lt;/h2>&lt;p>Then run Magentic ui, which uses port 8081 by default. The first run will download multiple different docker images and related dependencies, which takes a long time, so wait for the installation to complete&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">magentic ui --port &lt;span class="m">8081&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Once the following information appears in the running log, startup has succeeded&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl">| INFO | magentic_ui.backend.web.app:lifespan:59 - Application startup complete. Navigate to http://127.0.0.1:8081
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Access &lt;code>http://localhost:8081&lt;/code> in the browser&lt;/p>
&lt;p>You will see the following interface
&lt;img src="https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526-3_hu_ea89256ed7f35d1d.webp"
width="1024"
height="434"
srcset="https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526-3_hu_459c3f4957a6bae0.webp 480w, https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526-3_hu_ea89256ed7f35d1d.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="236"
data-flex-basis="566px"
>
&lt;/p>
&lt;p>After starting a session, for example, ask the AI to help us complete a test&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl">Please test whether the login functionality for different users on the saucedemo.com website works correctly, and summarize the issues in markdown format
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>If the installation is correct and the large model calls work normally, Magentic UI will plan the relevant task plan and ask the user to confirm&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526-5_hu_5eabeac52c2fb4c8.webp"
width="1024"
height="462"
srcset="https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526-5_hu_442cb3d2ba4e44b1.webp 480w, https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526-5_hu_5eabeac52c2fb4c8.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="221"
data-flex-basis="532px"
>
&lt;/p>
&lt;p>The user can also adjust the plan based on the feedback, and during plan execution can interact with the AI to change its execution path. For a concrete execution demonstration, see the video below.&lt;/p>
&lt;p>At this point, checking the docker runtime information in WSL, you can see that 3 containers are running, two of which are mangenti UI&amp;rsquo;s &lt;code>coder&lt;/code> and &lt;code>file surfer&lt;/code> agents, and the other is a remotely viewable &lt;code>vnc_browser&lt;/code> container&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526-2_hu_3fe0d746923ab871.webp"
width="1024"
height="243"
srcset="https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526-2_hu_1150e5ae89cc54be.webp 480w, https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526-2_hu_3fe0d746923ab871.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="420"
data-flex-basis="1009px"
>
&lt;/p>
&lt;p>After the series of steps is completed, Magentic UI obtains the following markdown-format result summary based on the initial instruction.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-markdown" data-lang="markdown">&lt;span class="line">&lt;span class="cl">以下是对saucedemo.com网站不同用户登录功能测试的结果汇总：
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">1.&lt;/span> &lt;span class="gs">**标准用户**&lt;/span> (&lt;span class="sb">`standard_user`&lt;/span>):
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> 登录成功。
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> 无问题，用户可以正常访问库存页面并浏览产品。
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">2.&lt;/span> &lt;span class="gs">**被锁定用户**&lt;/span> (&lt;span class="sb">`locked_out_user`&lt;/span>):
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> 登录失败。
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> 显示错误消息 &amp;#34;Epic sadface: Sorry, this user has been locked out.&amp;#34; 账户已被锁定，无法访问。
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">3.&lt;/span> &lt;span class="gs">**问题用户**&lt;/span> (&lt;span class="sb">`problem_user`&lt;/span>):
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> 登录成功。
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> 产品图像存在不匹配的问题，图像错误是已知问题。
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">4.&lt;/span> &lt;span class="gs">**性能故障用户**&lt;/span> (&lt;span class="sb">`performance_glitch_user`&lt;/span>):
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> 登录成功。
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">-&lt;/span> 无明显系统减慢或异常，用户可以正常导航。
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">这些结果表明网站能够正确处理不同账户类型的登录场景。如果您想亲自测试，可以访问 [&lt;span class="nt">saucedemo.com&lt;/span>](&lt;span class="na">https://www.saucedemo.com/&lt;/span>)。
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="hands-on-impressions">Hands-On Impressions
&lt;/h2>&lt;p>Overall, after using it, repositioning AI as an assistant role is clearly more in line with the reality of current AI applications, and displaying the AI&amp;rsquo;s operation process in real time through the container makes AI task execution no longer a black box, which is indeed much friendlier.&lt;/p>
&lt;p>However, in use I still feel the practicality is not very good. Although the official statement says it is still research-oriented at this stage, there is still considerable room for improvement.&lt;/p>
&lt;ol>
&lt;li>Installation and configuration are relatively complex, with numerous dependency packages, and it takes a long time&lt;/li>
&lt;li>The capability of the large model itself has a large impact on the execution process, including whether interactions can be completed normally. There are many call failures and exceptions.&lt;/li>
&lt;li>The token consumption of the large model is considerable; to complete one task, it actually breaks down into dozens of different requests, and the token consumption of each request is also in the thousands, so with a paid model the cost is high&lt;/li>
&lt;/ol>
&lt;p>The figure below shows the token consumption during my trial as viewed in the Azure backend, which is quite considerable.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526-4_hu_e098ae694e9d64ff.webp"
width="1024"
height="261"
srcset="https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526-4_hu_97df20c8bdae3d29.webp 480w, https://chengxiaqiucao.github.io/post/096-magenticui%E8%AF%84%E6%B5%8B/snap_20250526-4_hu_e098ae694e9d64ff.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="392"
data-flex-basis="942px"
>
&lt;/p>
&lt;p>In short, the development direction of Magentic UI is worth looking forward to, but for now we still need to wait for its further refinement.&lt;/p>
&lt;hr></description></item><item><title>mem0, Giving AI Memory, the Cornerstone of Building Personalized Assistants</title><link>https://chengxiaqiucao.github.io/en/post/097-mem0/</link><pubDate>Tue, 27 May 2025 00:00:00 +0000</pubDate><guid>https://chengxiaqiucao.github.io/en/post/097-mem0/</guid><description>&lt;img src="https://chengxiaqiucao.github.io/post/097-mem0/Pasted-20250722.webp" alt="Featured image of post mem0, Giving AI Memory, the Cornerstone of Building Personalized Assistants" />&lt;p>In today&amp;rsquo;s world of rapidly evolving AI large models, all kinds of intelligent applications are emerging one after another. However, many current large language models (LLMs) still face one core challenge: &lt;strong>the lack of memory&lt;/strong>. That is, they are often &amp;ldquo;stateless&amp;rdquo;; for performance reasons, many AI tools impose fairly strict context window limits, and historical interaction information beyond that window gets discarded. As a result, AI cannot continuously remember context across different sessions, or even within complex interactions in the same session; conversations lack coherence, information is frequently repeated, and long-term tasks cannot be handled.&lt;/p>
&lt;p>For a personalized AI assistant, if it &amp;ldquo;forgets&amp;rdquo; everything with every exchange and cannot be guided by your preferences and habits, the experience is undoubtedly frustrating. It is precisely to solve this pain point that an open-source project called &lt;code>Mem0&lt;/code> came into being. It aims to provide AI applications with scalable, persistent, and pluggable memory capabilities, giving your AI a real &amp;ldquo;brain&amp;rdquo;.&lt;/p>
&lt;p>In fact, the open-source project Browser-Use, which we introduced in a previous article, uses &lt;code>Mem0&lt;/code> to implement task memory.&lt;/p>
&lt;p>In this article, we will take a detailed look at &lt;code>Mem0&lt;/code>&amp;rsquo;s core philosophy and technical features.&lt;/p>
&lt;h2 id="why-does-ai-need-memory">Why Does AI Need &amp;ldquo;Memory&amp;rdquo;?
&lt;/h2>&lt;p>The power of current LLMs is mainly reflected in their efficient processing of a single input. They can generate fluent text and answer complex questions, but these capabilities are often confined to the current &amp;ldquo;prompt&amp;rdquo; window. Once the conversation ends or the context exceeds the window limit, previous interaction information is forgotten.&lt;/p>
&lt;p>This &amp;ldquo;stateless&amp;rdquo; nature leads to the following problems:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Context loss&lt;/strong>: in long conversations, AI cannot remember earlier content, leading to repeated questions or misunderstanding.&lt;/li>
&lt;li>&lt;strong>Lack of personalization&lt;/strong>: AI cannot provide customized services based on the user&amp;rsquo;s historical behavior and preferences.&lt;/li>
&lt;li>&lt;strong>Limited long-term tasks&lt;/strong>: for tasks that require multiple rounds of interaction and accumulated information to complete (such as project management and complex planning), a memoryless AI is hard pressed to cope.&lt;/li>
&lt;li>&lt;strong>Low efficiency&lt;/strong>: users have to repeatedly provide background information, reducing interaction efficiency.&lt;/li>
&lt;/ul>
&lt;p>The emergence of Mem0 bridges this &amp;ldquo;memory gap&amp;rdquo;, allowing AI to accumulate experience and learn and grow.&lt;/p>
&lt;h2 id="what-is-mem0">What Is Mem0?
&lt;/h2>&lt;p>&lt;strong>Mem0&lt;/strong> is an open-source, modular framework designed specifically to give LLMs &lt;strong>scalable, persistent, and pluggable&lt;/strong> memory capabilities. It abstracts AI memory into different layers and provides a unified API, enabling developers to easily add memory functionality to any LLM application.&lt;/p>
&lt;p>Simply put, Mem0 is an external &amp;ldquo;memory bank&amp;rdquo; for AI applications. It can capture, store, and retrieve all relevant information generated during interactions between the AI and the user, and inject it into the LLM&amp;rsquo;s context when needed, thereby enabling more coherent and intelligent conversations and task execution.&lt;/p>
&lt;h2 id="explanation-of-mem0s-core-features">Explanation of Mem0&amp;rsquo;s Core Features
&lt;/h2>&lt;p>The strength of Mem0 lies in its carefully designed architecture and rich feature set:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Layered memory architecture&lt;/strong>: Mem0 divides memory into different types to suit different needs:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Ephemeral Memory&lt;/strong>: stores short-term, in-session contextual information, similar to human short-term memory.&lt;/li>
&lt;li>&lt;strong>Long-Term Memory&lt;/strong>: stores important knowledge and experience that needs to be retained long term, with efficient retrieval achieved through semantic embeddings.&lt;/li>
&lt;li>&lt;strong>Archival Memory&lt;/strong>: used for backup and auditing, ensuring every interaction is traceable.&lt;/li>
&lt;li>&lt;strong>Knowledge Memory&lt;/strong>: designed specifically for storing external knowledge bases, such as documents and web pages.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Highly pluggable (Pluggable)&lt;/strong>: Mem0 offers flexible integration capabilities, supporting seamless collaboration with a variety of mainstream LLM services (such as OpenAI, Anthropic, Groq, etc.) and vector databases (such as Qdrant, Pinecone, ChromaDB, etc.). This means developers can freely choose backend services according to their own needs and preferences.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Multi-tenancy support&lt;/strong>: Mem0 supports a multi-tenant architecture, allowing independent memory spaces to be created for different users or application instances, ensuring data isolation and security, which is especially important for building SaaS products.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Developer friendly&lt;/strong>: it provides a concise and easy-to-use Python SDK, with plans to support JavaScript/TypeScript, greatly lowering the barrier for developers to integrate memory functionality.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Integration with mainstream frameworks&lt;/strong>: native support for popular LLM application development frameworks such as LangChain and LlamaIndex, accelerating the development process.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="analysis-of-browser-uses-application-of-mem0">Analysis of Browser-Use&amp;rsquo;s Application of Mem0
&lt;/h2>&lt;p>&lt;strong>Browser-Use&lt;/strong> aims to enable AI agents to perform complex tasks in the browser just as humans do. It leverages Mem0 to give AI agents &amp;ldquo;memory&amp;rdquo; capabilities; when executing tasks, it can, as configured, record the detailed information of up to 100 or even more operation steps as a reference for subsequent steps.&lt;/p>
&lt;p>By integrating Mem0, the AI agents in the Browser-Use project gain the following key capabilities:&lt;/p>
&lt;h3 id="browsing-history-memory-and-navigation-optimization">&lt;strong>Browsing History Memory and Navigation Optimization&lt;/strong>
&lt;/h3>&lt;p>Every URL visited and every interaction (click, input) by the AI agent can be stored via Mem0 as &lt;strong>ephemeral memory&lt;/strong> or transformed into &lt;strong>long-term memory&lt;/strong>.&lt;/p>
&lt;p>When a user asks the agent to &amp;ldquo;&lt;code>go back to the previously searched results page&lt;/code>&amp;rdquo;, the agent no longer needs to search from scratch, but can directly retrieve the historical URL from Mem0 and navigate to it, greatly improving efficiency and user experience.&lt;/p>
&lt;h3 id="context-maintenance-for-complex-tasks">&lt;strong>Context Maintenance for Complex Tasks&lt;/strong>
&lt;/h3>&lt;p>For example, an AI agent needs to complete an online shopping flow spanning multiple pages: search for products -&amp;gt; add to cart -&amp;gt; fill in address -&amp;gt; pay.&lt;/p>
&lt;p>Mem0 can store the current page state, user input, product details, and other &lt;strong>ephemeral memory&lt;/strong> at every step. Even if the flow is interrupted, the agent can load the previous context from Mem0 and accurately continue from where it left off, rather than &amp;ldquo;forgetting&amp;rdquo; and starting over.&lt;/p>
&lt;p>For example, the agent can remember the color and size the user selected on a certain product page, and this information still exists even after jumping to the cart page and back.&lt;/p>
&lt;h3 id="user-operation-pattern-and-preference-learning">&lt;strong>User Operation Pattern and Preference Learning&lt;/strong>
&lt;/h3>&lt;p>If a user often has the AI agent perform similar tasks on a particular website (such as checking the headlines of a news site every morning), Mem0 can transform these high-frequency behavior patterns into &lt;strong>long-term memory&lt;/strong>.&lt;/p>
&lt;p>In the future, the AI agent can more intelligently predict user needs, and even proactively recommend or preload related content, achieving a truly personalized browser operation experience.&lt;/p>
&lt;h3 id="persistence-of-multi-session-tasks">&lt;strong>Persistence of Multi-Session Tasks&lt;/strong>
&lt;/h3>&lt;p>For complex research tasks that take several days to complete (such as collecting material on a topic), the AI agent can store the key findings, visited resources, and task progress from each browsing session in Mem0&amp;rsquo;s &lt;strong>long-term memory&lt;/strong>.&lt;/p>
&lt;p>Even after closing the browser, on the next startup the agent can load these memories and continue the previous research, ensuring task continuity and completeness.&lt;/p>
&lt;blockquote>
&lt;p>Through the above analysis, we can clearly see how Mem0 helps the AI agent in the Browser-Use project transform from a &amp;ldquo;use-and-discard&amp;rdquo; tool into an intelligent assistant that understands the browser environment, remembers historical operations, and continuously executes complex tasks.
It makes the AI agent no longer merely mechanically execute instructions, but able to accumulate experience, adapt to the environment, and provide a smoother, more humanized automated browsing experience.&lt;/p>&lt;/blockquote>
&lt;h3 id="summary">Summary
&lt;/h3>&lt;p>When building truly intelligent AI applications capable of complex interactions, memory capability is an indispensable part. &lt;strong>Mem0&lt;/strong>, as an open-source framework focused on providing LLMs with scalable, persistent, and pluggable memory, undoubtedly offers developers a powerful tool. Through layered memory, flexible integration capabilities, and developer-friendly design, it greatly simplifies the implementation of AI memory functionality.&lt;/p>
&lt;p>Whether it is empowering an AI browser agent like Browser-Use to have persistent memory in complex web interactions, or building smarter personal assistants and customer service bots, Mem0 can provide a solid foundation.&lt;/p>
&lt;p>For those who want to build personalized assistants or make their AI Agent better fit real application scenarios, Mem0 is an AI ecosystem tool you cannot afford not to know.&lt;/p></description></item><item><title>Building a Personal Knowledge Base - Deploying DeepSeek with WSL + Ollama and Integrating It with VS Code</title><link>https://chengxiaqiucao.github.io/en/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/</link><pubDate>Thu, 15 May 2025 00:00:00 +0000</pubDate><guid>https://chengxiaqiucao.github.io/en/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/</guid><description>&lt;img src="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/snap_20250419-3.webp" alt="Featured image of post Building a Personal Knowledge Base - Deploying DeepSeek with WSL + Ollama and Integrating It with VS Code" />&lt;p>At present, large-model applications are in full swing. Major LLMs such as &lt;code>Deepseek&lt;/code> also provide online assistant services, and combined with &lt;code>mcp-server&lt;/code> they can further extend into local tool capabilities.&lt;/p>
&lt;p>But for materials strongly tied to local business and data, online large-model training datasets generally cannot cover them, especially some sensitive data or data with high security requirements, for which using online large models is impractical. Therefore, in both personal use and real work, deploying large models locally and adding a local knowledge base is also a rigid requirement.&lt;/p>
&lt;p>This article records and shares the process of building a local large model in WSL through Ollama and CherryStudio, and integrating the local model into VS Code&amp;rsquo;s AI assistant.&lt;/p>
&lt;h2 id="ollama-introduction">Ollama Introduction
&lt;/h2>&lt;p>Ollama is a simple, easy-to-use local large language model runtime framework developed in Go, designed specifically for conveniently deploying and running large language models (LLMs) on local machines. Ollama is short for &lt;strong>Omni-Layer Learning Language Acquisition Model (all-round learning language acceptance model)&lt;/strong>.&lt;/p>
&lt;h2 id="deepseek-local-models-and-runtime-configuration">Deepseek Local Models and Runtime Configuration
&lt;/h2>&lt;p>Deepseek currently comes in multiple versions based on the size of the parameter set used for local deployment, ranging from &lt;strong>1.5B&lt;/strong> to &lt;strong>671B&lt;/strong> and beyond. The larger the parameter set, the more intelligent the AI, but the higher the hardware requirements accordingly.&lt;/p>
&lt;p>Generally, the recommended hardware configurations for different Deepseek model versions are as follows:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Model&lt;/th>
&lt;th>CPU&lt;/th>
&lt;th>Memory&lt;/th>
&lt;th>Disk&lt;/th>
&lt;th>VRAM&lt;/th>
&lt;th>Use Case&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>DeepSeek-R1-1.5B&lt;/td>
&lt;td>4 cores&lt;/td>
&lt;td>8 GB+&lt;/td>
&lt;td>3 GB+&lt;/td>
&lt;td>Not required (GTX 1650 optional for CPU acceleration)&lt;/td>
&lt;td>Personal use, such as laptops and desktops&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>DeepSeek-R1-7B&lt;/td>
&lt;td>8 cores&lt;/td>
&lt;td>16 GB+&lt;/td>
&lt;td>8 GB+&lt;/td>
&lt;td>8 GB+ VRAM (e.g. RTX 3070/4060)&lt;/td>
&lt;td>Local development for small and medium enterprises&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>DeepSeek-R1-8B&lt;/td>
&lt;td>8 cores&lt;/td>
&lt;td>16 GB+&lt;/td>
&lt;td>8 GB+&lt;/td>
&lt;td>8 GB+ VRAM&lt;/td>
&lt;td>Local development for SMEs (lightweight tasks with improved accuracy)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>DeepSeek-R1-14B&lt;/td>
&lt;td>12 cores&lt;/td>
&lt;td>32 GB+&lt;/td>
&lt;td>15 GB+&lt;/td>
&lt;td>16 GB+ VRAM (e.g. RTX 4090 or A5000)&lt;/td>
&lt;td>Local development for SMEs (medium-weight tasks)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>DeepSeek-R1-32B&lt;/td>
&lt;td>16 cores&lt;/td>
&lt;td>64 GB+&lt;/td>
&lt;td>30 GB+&lt;/td>
&lt;td>24 GB+ VRAM (e.g. A100 40 GB or RTX 3090)&lt;/td>
&lt;td>Professional domain tasks, such as healthcare, research, and law&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>DeepSeek-R1-70B&lt;/td>
&lt;td>32 cores&lt;/td>
&lt;td>128 GB+&lt;/td>
&lt;td>70 GB+&lt;/td>
&lt;td>Multi-GPU parallel (e.g. 2x A100 80GB or 4x RTX 4090)&lt;/td>
&lt;td>Large enterprises or research institutions, professional domain tasks&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>DeepSeek-R1-671B (Full Version)&lt;/td>
&lt;td>64 cores&lt;/td>
&lt;td>512 GB+&lt;/td>
&lt;td>300 GB+&lt;/td>
&lt;td>Multi-GPU parallel (e.g. 8x A100/H100)&lt;/td>
&lt;td>National-level research tasks&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>For individual users like us, we usually choose from 1.5B to 14B based on our own computer configuration. Of course, if you do not use local models frequently, my personal suggestion is to match one tier lower in both configuration and recommended model.&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="deploying-local-deepseek-in-wsl-with-ollama">Deploying Local Deepseek in WSL with Ollama
&lt;/h2>&lt;p>Because the author currently mainly wants to connect some local data to Deepseek and has no need to use local LLMs frequently, here I choose to deploy &lt;strong>DeepSeek-R1-14B&lt;/strong>. In addition, to avoid the LLM consuming large amounts of resources every time the computer starts up, I want to run the LLM under WSL on a Windows machine.&lt;/p>
&lt;h3 id="wsl-configuration">WSL Configuration
&lt;/h3>&lt;p>If WSL is not yet enabled on the current system, you can enable it first (the process will not be described in detail; in Windows 11, running WSL install [corresponding Linux distribution] is sufficient to install it).&lt;/p>
&lt;p>Check the &lt;strong>WSL&lt;/strong> status from the command line:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-batch" data-lang="batch">&lt;span class="line">&lt;span class="cl">C&lt;span class="p">:&lt;/span>&lt;span class="nl">\qiucao&lt;/span>&lt;span class="c1">&amp;gt;wsl --status&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Default Distribution: Ubuntu-24.04
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Default Version: 2
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>WSL&amp;rsquo;s default network mode is NAT. Here you can use the &lt;code>WSL Setting&lt;/code> program to modify the current configuration and change it to &lt;code>Mirrored&lt;/code> mode, sharing the host network.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/snap_20250419-1_hu_c0aec88b4901f7c9.webp"
width="1024"
height="617"
srcset="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/snap_20250419-1_hu_c9a189f1a5c9e75c.webp 480w, https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/snap_20250419-1_hu_c0aec88b4901f7c9.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="165"
data-flex-basis="398px"
>
&lt;/p>
&lt;h3 id="installing-ollama">Installing Ollama
&lt;/h3>&lt;p>Go to the Ollama official website (&lt;a class="link" href="https://ollama.com/" target="_blank" rel="noopener"
>https://ollama.com/&lt;/a>) download page. Because we are deploying in WSL, choose the Linux installation.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/snap_20250419_hu_384914324e87dc5e.webp"
width="1024"
height="508"
srcset="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/snap_20250419_hu_cd1b689f9bb6a91b.webp 480w, https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/snap_20250419_hu_384914324e87dc5e.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="201"
data-flex-basis="483px"
>
&lt;/p>
&lt;p>Execute the following command and wait for the download and automatic installation to complete.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">curl -fsSL https://ollama.com/install.sh &lt;span class="p">|&lt;/span> sh
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Check the version after installation&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">~$ ollama --version
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">ollama version is 0.6.5
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="deploying-deepseek">Deploying Deepseek
&lt;/h3>&lt;p>After Ollama is installed, you can select the corresponding large model to install from the list of large models provided by Ollama. The currently supported model list can be found at the following address on the official website: &lt;a class="link" href="https://ollama.com/library" target="_blank" rel="noopener"
>https://ollama.com/library&lt;/a>&lt;/p>
&lt;p>Execute the following command to download and run Deepseek.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">ollama run deepseek-r1:14b
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/ollama_deepseek_hu_658fb0f6c9a8fd17.webp"
width="1024"
height="209"
srcset="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/ollama_deepseek_hu_72e5171ab0ef0d81.webp 480w, https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/ollama_deepseek_hu_658fb0f6c9a8fd17.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="490"
data-flex-basis="1178px"
>
&lt;/p>
&lt;p>After a successful installation, you can ask a question to test whether Deepseek is providing service normally.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/snap_20250419-2_hu_4bae2e8f62d8f2bf.webp"
width="1024"
height="115"
srcset="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/snap_20250419-2_hu_808f18f03c643d04.webp 480w, https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/snap_20250419-2_hu_4bae2e8f62d8f2bf.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="888"
data-flex-basis="2132px"
>
&lt;/p>
&lt;h3 id="adding-a-knowledge-base-analysis-model">Adding a Knowledge Base Analysis Model
&lt;/h3>&lt;p>At this point, Deepseek is actually deployed locally. But if we want to use local data and documents through Deepseek, we also need to deploy a &lt;strong>semantic vector model&lt;/strong> (Embedding Model) to convert local data into knowledge base data that the large model can analyze. Here we choose the &lt;strong>bge-m3&lt;/strong> model, a general-purpose vector model that supports multiple languages, long texts, and a variety of retrieval methods.&lt;/p>
&lt;p>Execute:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-shell" data-lang="shell">&lt;span class="line">&lt;span class="cl">ollama pull bge-m3
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/ollama_bge_hu_d88878aa76f5f5ad.webp"
width="1024"
height="178"
srcset="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/ollama_bge_hu_a53ecd7c9e2fb6b6.webp 480w, https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/ollama_bge_hu_d88878aa76f5f5ad.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="576"
data-flex-basis="1383px"
>
&lt;/p>
&lt;h2 id="managing-the-knowledge-base-and-providing-a-local-interface-with-cherry-studio">Managing the Knowledge Base and Providing a Local Interface with Cherry Studio
&lt;/h2>&lt;p>After installing Deepseek, although we can interact with Deepseek from the command line, it is still not friendly enough, and managing the local knowledge base is not convenient either. So here we can also install Cherry Studio, an open-source local AI assistant and knowledge base client. Just download the Windows version from the official website (&lt;a class="link" href="https://cherry-ai.com" target="_blank" rel="noopener"
>https://cherry-ai.com&lt;/a>) and install it.
&lt;img src="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/snap_20250419-3_hu_5bc6c662290996b6.webp"
width="1024"
height="472"
srcset="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/snap_20250419-3_hu_dfe9fd0678b8fbb1.webp 480w, https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/snap_20250419-3_hu_5bc6c662290996b6.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="217"
data-flex-basis="520px"
>
&lt;/p>
&lt;p>Open Cherry Studio and follow the steps below to add the Deepseek we just deployed through Ollama.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/cherry_hu_8f63401f090a0a07.webp"
width="1024"
height="629"
srcset="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/cherry_hu_49a630e5e64cbdfe.webp 480w, https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/cherry_hu_8f63401f090a0a07.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="162"
data-flex-basis="390px"
>
&lt;/p>
&lt;p>You will see the already installed model; add it in.
&lt;img src="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/cherry_model_hu_85f7b6ff325ab5da.webp"
width="1024"
height="694"
srcset="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/cherry_model_hu_2086e4f3a5e5df0e.webp 480w, https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/cherry_model_hu_85f7b6ff325ab5da.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="147"
data-flex-basis="353px"
>
Then you can use Cherry Studio&amp;rsquo;s knowledge base management to bring the local documents we want to add into the large model&amp;rsquo;s dataset. This includes methods such as adding files directly, specifying a directory directly, and collecting from websites, which is very convenient.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/add_knowledge_hu_b3fb53dfd217be9e.webp"
width="1024"
height="629"
srcset="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/add_knowledge_hu_78d09a45838d4d91.webp 480w, https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/add_knowledge_hu_b3fb53dfd217be9e.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="162"
data-flex-basis="390px"
>
&lt;/p>
&lt;h2 id="integrating-local-deepseek-into-vs-code">Integrating Local Deepseek into VS Code
&lt;/h2>&lt;p>Once we have a local LLM, if we want to use it in VS Code, we can use VS Code&amp;rsquo;s &lt;code>AI Toolkit&lt;/code> extension to add the local LLM as follows.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/vs_code_1_hu_1ae13ebc1a2661dd.webp"
width="1024"
height="513"
srcset="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/vs_code_1_hu_230244637f7e1dfa.webp 480w, https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/vs_code_1_hu_1ae13ebc1a2661dd.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="199"
data-flex-basis="478px"
>
&lt;/p>
&lt;p>Test the capabilities of the local library in VS Code.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/vs_code_2_hu_db60771e5812785.webp"
width="1024"
height="721"
srcset="https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/vs_code_2_hu_7b2b7e3e9d687df6.webp 480w, https://chengxiaqiucao.github.io/post/093-deepseek%E6%9C%AC%E5%9C%B0%E9%83%A8%E7%BD%B2/vs_code_2_hu_db60771e5812785.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="142"
data-flex-basis="340px"
>
&lt;/p>
&lt;p>The above is our hands-on sharing of deploying local Deepseek.&lt;/p></description></item><item><title>How Can Test Developers Make Good Use of Cursor?</title><link>https://chengxiaqiucao.github.io/en/post/092-cursor%E7%9A%8412rules/</link><pubDate>Tue, 13 May 2025 00:00:00 +0000</pubDate><guid>https://chengxiaqiucao.github.io/en/post/092-cursor%E7%9A%8412rules/</guid><description>&lt;img src="https://chengxiaqiucao.github.io/post/092-cursor%E7%9A%8412rules/cursor.webp" alt="Featured image of post How Can Test Developers Make Good Use of Cursor?" />&lt;h2 id="preface">Preface
&lt;/h2>&lt;p>Many people who are new to AI-assisted programming have probably heard of how powerful &lt;code>Cursor&lt;/code> is. For beginners, the free quota of the free version of Cursor is more than enough to let everyone experience its formidable capabilities.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/092-cursor%E7%9A%8412rules/cursor_hu_781815639c7e7dae.webp"
width="1024"
height="464"
srcset="https://chengxiaqiucao.github.io/post/092-cursor%E7%9A%8412rules/cursor_hu_4f511162cee92d8f.webp 480w, https://chengxiaqiucao.github.io/post/092-cursor%E7%9A%8412rules/cursor_hu_781815639c7e7dae.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="220"
data-flex-basis="529px"
>
&lt;/p>
&lt;p>However, in real-world use — based on my own experience — if you simply treat it as a conversation partner and complete development tasks the way you would communicate with a person, you will waste a great deal of time correcting its misunderstandings, and there is a very high chance that after some conversation it will alter your original work beyond recognition, wasting a large amount of effort.&lt;/p>
&lt;h2 id="cursors-12-rules">Cursor&amp;rsquo;s 12 Rules
&lt;/h2>&lt;p>In fact, whether Cursor can work more effectively has a lot to do with how you use it. Cursor&amp;rsquo;s chief designer &lt;strong>Ryo Lu&lt;/strong> earlier shared on X 12 rules for making good use of Cursor:&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/092-cursor%E7%9A%8412rules/cursor_12_rules_hu_2dfe3009b7e98df0.webp"
width="1024"
height="2035"
srcset="https://chengxiaqiucao.github.io/post/092-cursor%E7%9A%8412rules/cursor_12_rules_hu_8048ba0d67a4cf92.webp 480w, https://chengxiaqiucao.github.io/post/092-cursor%E7%9A%8412rules/cursor_12_rules_hu_2dfe3009b7e98df0.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="50"
data-flex-basis="120px"
>
&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Set clear project rules:&lt;/strong> Before starting a project, define 5-10 clear project rules so Cursor understands your code structure and constraints. For existing codebases, you can try the &lt;code>/generate rules&lt;/code> command to generate rules.&lt;/li>
&lt;li>&lt;strong>Be specific in prompts:&lt;/strong> Be very specific in your prompts, detailing the tech stack, expected behavior, and constraints, just like writing a mini spec.&lt;/li>
&lt;li>&lt;strong>Work file by file:&lt;/strong> Handle a small portion each time; generate, test, and review while staying focused.&lt;/li>
&lt;li>&lt;strong>Tests first:&lt;/strong> Write tests first, lock down the test cases, then generate code until all tests pass.&lt;/li>
&lt;li>&lt;strong>Strict review and correction:&lt;/strong> Always review the AI&amp;rsquo;s output and manually fix any errors, then tell Cursor to use those corrections as examples.&lt;/li>
&lt;li>&lt;strong>Limit the scope:&lt;/strong> Use commands such as &lt;code>@ file&lt;/code>, &lt;code>@ folders&lt;/code>, and &lt;code>@ git&lt;/code> to restrict Cursor&amp;rsquo;s attention to specific parts of the codebase.&lt;/li>
&lt;li>&lt;strong>Provide full context:&lt;/strong> Keep design documents and checklists in the &lt;code>.cursor/&lt;/code> directory so the Cursor agent can fully understand what needs to be done next.&lt;/li>
&lt;li>&lt;strong>Fix wrong code directly:&lt;/strong> If the generated code is wrong, just modify it manually. Cursor learns faster from edits than from explanations.&lt;/li>
&lt;li>&lt;strong>Leverage chat history:&lt;/strong> Use chat history to iterate on old prompts without starting from scratch.&lt;/li>
&lt;li>&lt;strong>Choose models wisely:&lt;/strong> Select models purposefully according to your needs. For example, Gemini suits the pursuit of precision, while Claude suits scenarios requiring broader knowledge.&lt;/li>
&lt;li>&lt;strong>Handle new or unfamiliar stacks:&lt;/strong> When working with a new or unfamiliar tech stack, paste in links to the relevant documentation. Have Cursor explain all errors and fixes line by line.&lt;/li>
&lt;li>&lt;strong>Optimize performance for large projects:&lt;/strong> For large projects, let it index overnight and limit the context scope to keep performance smooth.&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl">Using Cursor well = fast, clean code.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Using it wrong = AI spaghetti you’ll be cleaning up all week.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Here’s how to actually use it right:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">1. Set 5-10 clear project rules upfront so Cursor knows your structure and constraints. Try /generate rules for existing codebases.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">2. Be specific in prompts. Spell out tech stack, behavior, and constraints like a mini spec.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">3. Work file by file; generate, test, and review in small, focused chunks.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">4. Write tests first, lock them, and generate code until all tests pass.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">5. Always review AI output and hard‑fix anything that breaks, then tell Cursor to use them as examples.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">6. Use @ file, @ folders, @ git to scope Cursor’s attention to the right parts of your codebase.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">7. Keep design docs and checklists in .cursor/ so the agent has full context on what to do next.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">8. If code is wrong, just write it yourself. Cursor learns faster from edits than explanations.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">9. Use chat history to iterate on old prompts without starting over.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">10. Choose models intentionally. Gemini for precision, Claude for breadth.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">11. In new or unfamiliar stacks, paste in link to documentation. Make Cursor explain all errors and fixes line by line.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">12.Let big projects index overnight and limit context scope to keep performance snappy.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Structure and control wins (for now)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Treat Cursor agent like a powerful junior — it can go far, fast, if you show it the way.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="how-can-test-developers-make-good-use-of-cursor">How Can Test Developers Make Good Use of Cursor?
&lt;/h2>&lt;p>As a test developer or test automation engineer, how can we make good use of Cursor when writing test scripts or tools to better improve our efficiency and output? In this article, referring to the 12 rules above, we summarize a set of relevant practical guidelines.&lt;/p>
&lt;h3 id="initialization-and-context-building---training-cursor-into-a-test-domain-expert">Initialization and Context Building - Training Cursor into a &amp;ldquo;Test Domain Expert&amp;rdquo;
&lt;/h3>&lt;p>At the start of a project or when joining it midway, the first priority is to let Cursor fully understand the standards and constraints of the current testing environment. High-quality context input is the prerequisite for high-quality code output.&lt;/p>
&lt;h4 id="define-project-testing-rules-and-conventions-rule-1">Define Project Testing Rules and Conventions (Rule 1)
&lt;/h4>&lt;p>In test automation projects, consistency in coding standards, framework selection, and design patterns is crucial. Based on &lt;code>Rule 1: Set clear project rules&lt;/code>, we can use the &lt;code>.cursor/rules.md&lt;/code> file to make this tacit team knowledge explicit and provide Cursor with a clear program of action. For existing projects, you can first use the &lt;code>/generate rules&lt;/code> command to initially extract the rules, and then add to them manually.&lt;/p>
&lt;p>&lt;strong>Practical example&lt;/strong>: In a Python Flask-based web project, the testing stack is Pytest and Selenium. You can define the following rules in &lt;code>.cursor/rules.md&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-mysql" data-lang="mysql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># .cursor/rules.md
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">cite_start&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="k">All&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">unit&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">test&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">files&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">are&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">named&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="n">test_&lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">py&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">UI&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">test&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">files&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">are&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">named&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="n">ui_test_&lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">py&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">cite_start&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="n">Test&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">functions&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">must&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">start&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">with&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="n">test_&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">cite_start&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="k">Use&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Pytest&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">fixtures&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">test&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">environment&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">setup&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">and&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">teardown&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">cite_start&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="n">UI&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">tests&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">follow&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Page&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Object&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">pattern&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">with&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">page&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">objects&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">encapsulated&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">cite_start&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="n">Avoid&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">hard&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="n">coded&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">waits&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">prefer&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">WebDriver&lt;/span>&lt;span class="s1">&amp;#39;s explicit wait mechanism
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s1">- [cite_start]Test reports are generated uniformly with the Allure framework
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h4 id="provide-detailed-instructions-to-simulate-test-scenarios-rule-2">Provide Detailed Instructions to Simulate &amp;ldquo;Test Scenarios&amp;rdquo; (Rule 2)
&lt;/h4>&lt;p>The quality of your interaction with AI directly determines the quality of the output code. Instructions for test automation especially demand precision, because they must fully describe the feature under test, input data, expected behavior, and even exceptional paths.&lt;/p>
&lt;p>&lt;strong>Practical example&lt;/strong>: Write integration tests for the user login feature.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Ineffective instruction&lt;/strong>: &lt;code>Write a login test.&lt;/code>&lt;/li>
&lt;li>&lt;strong>Well-structured instruction&lt;/strong>:&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl">Please use the Pytest framework to write integration tests for the user login feature of a Flask application (endpoint POST /api/login, accepting username and password). The following three scenarios need to be covered:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">1. Successful login (using admin/password123);
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">2. Incorrect password (using admin/wrongpass);
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">3. User does not exist (using nonexistent/anypass). For the success scenario, assert that the HTTP status code is 200 and the response contains a non-empty token. For the failure scenarios, assert that the status code is 401.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="iterative-development-and-correction---achieving-continuous-integration-of-test-code">Iterative Development and Correction - Achieving &amp;ldquo;Continuous Integration of Test Code&amp;rdquo;
&lt;/h3>&lt;p>Breaking down complex testing tasks and developing through an agile loop of &amp;ldquo;generate - verify - correct&amp;rdquo; is an effective strategy for ensuring code quality and project progress.&lt;/p>
&lt;h4 id="small-steps-incremental-verification-rule-3">Small Steps, Incremental Verification (Rule 3)
&lt;/h4>&lt;p>You should resist the temptation to generate all the tests for an entire complex module in one go.&lt;/p>
&lt;p>The right approach is to break the task down into the smallest verifiable units and tackle them one by one.&lt;/p>
&lt;p>For example, when writing tests for a set of RESTful APIs, you should follow the logical order of &amp;ldquo;create user -&amp;gt; get user -&amp;gt; update user -&amp;gt; delete user&amp;rdquo;, generating and verifying the test code one at a time&lt;/p>
&lt;p>This approach helps locate problems quickly and avoids the accumulation of errors.&lt;/p>
&lt;h4 id="applying-test-driven-development-tdd-rule-4">Applying Test-Driven Development (TDD) (Rule 4)
&lt;/h4>&lt;p>Test-driven development is a classic model for ensuring code quality, and Cursor can be a powerful accelerator for it. Engineers first define the expected behavior of a function (that is, write the test cases), then have the AI generate implementation code that satisfies those tests.&lt;/p>
&lt;p>&lt;strong>Practical example&lt;/strong>: Implement a discount calculation function &lt;code>calculate_discount(price, discount_rate)&lt;/code>.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Define the test&lt;/strong>: First ask Cursor: &lt;code>Generate a Pytest test case for the calculate_discount function. When price=100 and discount_rate=0.1, the expected return value is 90; when discount_rate is negative, a ValueError exception should be raised.&lt;/code>&lt;/li>
&lt;li>&lt;strong>Generate the implementation&lt;/strong>: After the test code &lt;code>test_calculate_discount.py&lt;/code> is generated, run it (it will fail at this point), then give Cursor a new instruction: &lt;code>Based on the test cases just generated, implement the calculate_discount function.&lt;/code>&lt;/li>
&lt;li>&lt;strong>Close the verification loop&lt;/strong>: Once Cursor generates the function implementation, run the tests again until they all pass.&lt;/li>
&lt;/ol>
&lt;h4 id="proactive-correction-and-mutual-learning-rule-5">Proactive Correction and Mutual Learning (Rule 5)
&lt;/h4>&lt;p>It is worth noting that AI-generated code is not always correct, and the engineer&amp;rsquo;s review and correction is the last line of defense. Fixing errors directly in the code is the most effective way to train Cursor, far better than explaining to it in natural language.&lt;/p>
&lt;p>&lt;strong>Practical example&lt;/strong>:
For example, in a UI test generated by Cursor, it used an unstable and incorrect XPath locator &lt;code>//button[@id='submit']&lt;/code>. After the test run fails, we can directly change it manually to a correct locator, such as &lt;code>//input[@value='Login']&lt;/code>. After the correction, you can leave a note in the chat to reinforce its learning: &lt;code>&amp;quot;I have fixed the locator for the login button; the new locator is more accurate. Please refer to this pattern in subsequent tasks.&amp;quot;&lt;/code> .&lt;/p>
&lt;h3 id="fine-grained-management---achieving-intelligent-scheduling-of-test-resources">Fine-Grained Management - Achieving &amp;ldquo;Intelligent Scheduling of Test Resources&amp;rdquo;
&lt;/h3>&lt;p>In large projects, how to keep Cursor focused on the right information is key to determining its efficiency and relevance.&lt;/p>
&lt;h4 id="precisely-limit-the-context-scope-rule-6">Precisely Limit the Context Scope (Rule 6)
&lt;/h4>&lt;p>In a large codebase, testing tasks are often related only to a specific module or service. By using the &lt;code>@folders&lt;/code> or &lt;code>@file&lt;/code> commands, you can significantly narrow Cursor&amp;rsquo;s analysis scope and keep it focused on the necessary context.&lt;/p>
&lt;p>&lt;strong>Practical example&lt;/strong>:
When writing API tests for the &lt;code>user_service&lt;/code> microservice, all relevant code resides in the &lt;code>services/user_service/&lt;/code> directory. In this case, you should first enter &lt;code>@folders services/user_service/&lt;/code> before asking, and then describe the specific testing requirements.&lt;/p>
&lt;h4 id="accumulate-project-knowledge-to-support-decisions-rule-7">Accumulate Project Knowledge to Support Decisions (Rule 7)
&lt;/h4>&lt;p>You can distill key information such as testing strategy, UI locator priorities, and data mocking conventions into documents stored in the &lt;code>.cursor/&lt;/code> directory. This is equivalent to providing Cursor with a &amp;ldquo;project-level knowledge base&amp;rdquo;.&lt;/p>
&lt;p>&lt;strong>Practical example&lt;/strong>:
Create a &lt;code>.cursor/ui_locators_priority.md&lt;/code> file with the content: &amp;ldquo;UI element locator priority order: ID &amp;gt; Name &amp;gt; CSS Selector &amp;gt; XPath&amp;rdquo;. You can then reference it when asking: &lt;code>Please refer to the strategy in .cursor/ui_locators_priority.md and generate Selenium locator code for the 'Submit' button on the registration page.&lt;/code>.&lt;/p>
&lt;h3 id="problem-solving-and-efficiency-optimization---becoming-a-test-efficiency-accelerator">Problem Solving and Efficiency Optimization - Becoming a &amp;ldquo;Test Efficiency Accelerator&amp;rdquo;
&lt;/h3>&lt;p>Mastering advanced usage can further transform Cursor from an everyday assistant into a powerful tool for solving complex problems and accelerating learning.&lt;/p>
&lt;h4 id="choose-ai-models-wisely-rule-10">Choose AI Models Wisely (Rule 10)
&lt;/h4>&lt;p>Different AI models have different strengths. Choosing the right model based on the characteristics of the testing task can get you twice the result with half the effort.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Gemini (precision first)&lt;/strong>: suited to generating unit tests with strict syntax requirements, algorithm validation, or fine-grained test code using specific frameworks (such as React Testing Library).&lt;/li>
&lt;li>&lt;strong>Claude (breadth first)&lt;/strong>: better suited to scenarios that require understanding large amounts of context, such as generating comprehensive integration tests from API documentation, designing end-to-end (E2E) test scenarios, or exploring and suggesting test points in an unfamiliar codebase.&lt;/li>
&lt;/ul>
&lt;h4 id="use-documentation-to-quickly-master-new-technologies-rule-11">Use Documentation to Quickly Master New Technologies (Rule 11)
&lt;/h4>&lt;p>When a team introduces a new testing framework (such as Playwright), engineers can use Cursor to quickly get over the learning curve.&lt;/p>
&lt;p>&lt;strong>Practical example&lt;/strong>:
Provide Cursor directly with a link to the official Playwright documentation and ask it to generate example code. When the generated code throws an error at runtime, you can paste the error message and ask: &amp;ldquo;This is an error that occurred while running a Playwright script; please explain the cause of the error line by line based on the official documentation and provide suggestions for fixing it.&amp;rdquo;.&lt;/p>
&lt;h4 id="limit-the-context-scope-rule-12">Limit the Context Scope (Rule 12)
&lt;/h4>&lt;p>When the project codebase is large, index it overnight and limit the context scope.&lt;/p>
&lt;p>&lt;strong>Practical example&lt;/strong>:&lt;/p>
&lt;p>When working on a large testing project, allow Cursor to handle indexing in the background and do the actual code generation the next day, so as to keep performance smooth.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Prioritize indexing core modules&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">@folder tests/unit
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Defer loading integration tests&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">@defer tests/integration
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="conclusion">Conclusion
&lt;/h2>&lt;p>For our actual work, the essence of successfully using Cursor is a process of shifting from an &amp;ldquo;instruction giver&amp;rdquo; to an &amp;ldquo;intelligent collaborator&amp;rdquo; and a &amp;ldquo;knowledge guide&amp;rdquo;. The emphasis is on highlighting its systematic role in &lt;strong>intelligent collaboration, knowledge accumulation, and efficiency improvement&lt;/strong>.&lt;/p></description></item><item><title>W3C ARIA Roles and Their Role in AI-Driven Test Automation</title><link>https://chengxiaqiucao.github.io/en/post/084-aria%E4%BB%8B%E7%BB%8D/</link><pubDate>Sun, 27 Apr 2025 00:00:00 +0000</pubDate><guid>https://chengxiaqiucao.github.io/en/post/084-aria%E4%BB%8B%E7%BB%8D/</guid><description>&lt;img src="https://chengxiaqiucao.github.io/post/084-aria%E4%BB%8B%E7%BB%8D/-20250417.webp" alt="Featured image of post W3C ARIA Roles and Their Role in AI-Driven Test Automation" />&lt;h2 id="preface">Preface
&lt;/h2>&lt;p>In the field of test automation, the hottest automation framework today is undoubtedly &lt;code>Playwright&lt;/code>. When it comes to page element location — extremely critical in test automation — compared with traditional tools such as &lt;code>Selenium&lt;/code>, it introduces a new element-location method, &lt;code>getByRole&lt;/code>, which fully leverages the ARIA Roles objects defined by the W3C to identify elements. While improving the flexibility and efficiency of element identification, it simultaneously verifies the accessibility compliance of the page. For example:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-javascript" data-lang="javascript">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Locate the button named &amp;#34;Search&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;button&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;搜索&amp;#39;&lt;/span> &lt;span class="p">}).&lt;/span>&lt;span class="nx">click&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Locate the checkbox and check it
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;checkbox&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;同意条款&amp;#39;&lt;/span> &lt;span class="p">}).&lt;/span>&lt;span class="nx">check&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Locate the text input and fill in content
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;textbox&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;用户名&amp;#39;&lt;/span> &lt;span class="p">}).&lt;/span>&lt;span class="nx">fill&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;testuser&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Locate the dropdown and select an option
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;combobox&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;国家&amp;#39;&lt;/span> &lt;span class="p">}).&lt;/span>&lt;span class="nx">selectOption&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;中国&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Today, AI is increasingly taking part in our daily work. As shown in the earlier 【】 article, driving a page through an &lt;code>mcp server&lt;/code> to complete automated testing with AI has become quite feasible in practice. After that article, many readers remained skeptical about how AI actually recognizes and locates page elements, drives execution through tools, and whether the results in real use can meet expectations.&lt;/p>
&lt;p>In fact, the &lt;code>ARIA&lt;/code> standard within the &lt;code>W3C&lt;/code> web specifications plays an important role here: it presents page objects to AI in a structured form, making it easier for AI to analyze the page. In this article, we will explore the &lt;code>ARIA&lt;/code> standard and its important role in AI-driven test automation.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/084-aria%E4%BB%8B%E7%BB%8D/-20250417_hu_2f6c810144873078.webp"
width="1024"
height="374"
srcset="https://chengxiaqiucao.github.io/post/084-aria%E4%BB%8B%E7%BB%8D/-20250417_hu_cd314db8f3c0cf27.webp 480w, https://chengxiaqiucao.github.io/post/084-aria%E4%BB%8B%E7%BB%8D/-20250417_hu_2f6c810144873078.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="274"
data-flex-basis="657px"
>
&lt;/p>
&lt;h2 id="what-is-aria">What is ARIA?
&lt;/h2>&lt;h3 id="definition">Definition
&lt;/h3>&lt;p>&lt;strong>WAI-ARIA&lt;/strong> (Web Accessibility Initiative – Accessible Rich Internet Applications), i.e. the &lt;strong>Web Accessibility Initiative – Accessible Rich Internet Applications standard&lt;/strong>, is a specification that enables web applications to better support use by people with disabilities.&lt;/p>
&lt;p>&lt;strong>ARIA Roles&lt;/strong> are a set of attributes defined in the W3C &lt;strong>WAI-ARIA&lt;/strong> specification, used to describe the function and purpose of web elements and to help assistive technologies (such as screen readers) understand and convey page content more accurately. **ARIA Roles ** are added to HTML elements through the &lt;code>role&lt;/code> attribute; for example, &lt;code>&amp;lt;div role=&amp;quot;button&amp;quot;&amp;gt;&lt;/code> indicates that the div element should be treated as a button.&lt;/p>
&lt;h3 id="evolution-of-the-standard-and-the-advantages-of-aria">Evolution of the Standard and the Advantages of ARIA
&lt;/h3>&lt;p>This standard has gone through three important stages of development:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>2008&lt;/strong>: W3C first released ARIA 1.0&lt;/li>
&lt;li>&lt;strong>2014&lt;/strong>: ARIA 1.1 introduced new roles such as &lt;code>searchbox&lt;/code>, &lt;code>switch&lt;/code>&lt;/li>
&lt;li>&lt;strong>2021&lt;/strong>: ARIA 1.2 added &lt;code>comment&lt;/code>, &lt;code>mark&lt;/code>, and other roles related to digital content&lt;/li>
&lt;/ul>
&lt;p>Comparison with traditional UI test automation:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Dimension&lt;/th>
&lt;th>Traditional UI Testing&lt;/th>
&lt;th>ARIA-Based Testing&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Element Identification Basis&lt;/td>
&lt;td>DOM Structure / Visual Features&lt;/td>
&lt;td>Semantic Roles / Functional Attributes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Maintenance Cost&lt;/td>
&lt;td>High (frequent updates as UI changes)&lt;/td>
&lt;td>Low (role definitions are more stable)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Cross-Platform Consistency&lt;/td>
&lt;td>Depends on the rendering engine&lt;/td>
&lt;td>Standardized behavior&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Accessibility Support&lt;/td>
&lt;td>Requires additional verification&lt;/td>
&lt;td>Built-in support&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="categories-of-aria-roles">Categories of ARIA Roles
&lt;/h3>&lt;p>According to the W3C specification, ARIA Roles can be divided into the following major categories:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Widget Roles&lt;/strong>: describe interactive UI components&lt;/p>
&lt;ul>
&lt;li>&lt;code>button&lt;/code>: a clickable button&lt;/li>
&lt;li>&lt;code>checkbox&lt;/code>: a checkbox&lt;/li>
&lt;li>&lt;code>radio&lt;/code>: a radio button&lt;/li>
&lt;li>&lt;code>textbox&lt;/code>: a text input box&lt;/li>
&lt;li>&lt;code>combobox&lt;/code>: a dropdown combo box&lt;/li>
&lt;li>&lt;code>slider&lt;/code>: a slider control&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Document Structure Roles&lt;/strong>: describe the structure of page content&lt;/p>
&lt;ul>
&lt;li>&lt;code>heading&lt;/code>: a heading (alternative to h1-h6)&lt;/li>
&lt;li>&lt;code>list&lt;/code>/&lt;code>listitem&lt;/code>: a list and list items&lt;/li>
&lt;li>&lt;code>table&lt;/code>/&lt;code>row&lt;/code>/&lt;code>cell&lt;/code>: table structure&lt;/li>
&lt;li>&lt;code>img&lt;/code>: an image&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Landmark Roles&lt;/strong>: identify the main regions of a page&lt;/p>
&lt;ul>
&lt;li>&lt;code>banner&lt;/code>: page header&lt;/li>
&lt;li>&lt;code>navigation&lt;/code>: navigation region&lt;/li>
&lt;li>&lt;code>main&lt;/code>: main content&lt;/li>
&lt;li>&lt;code>search&lt;/code>: search region&lt;/li>
&lt;li>&lt;code>contentinfo&lt;/code>: footer information&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Live Region Roles&lt;/strong>: regions for dynamic content updates&lt;/p>
&lt;ul>
&lt;li>&lt;code>alert&lt;/code>: important information that needs immediate notification&lt;/li>
&lt;li>&lt;code>status&lt;/code>: feedback on operation status&lt;/li>
&lt;li>&lt;code>timer&lt;/code>: a timer or counter&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;p>In addition to the basic Roles, advanced roles commonly used in modern web applications also include:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Composite component roles&lt;/strong>:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-html" data-lang="html">&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">div&lt;/span> &lt;span class="na">role&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;tree&amp;#34;&lt;/span> &lt;span class="na">aria-label&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;文件浏览器&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">div&lt;/span> &lt;span class="na">role&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;treeitem&amp;#34;&lt;/span> &lt;span class="na">aria-expanded&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;true&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>Documents
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">div&lt;/span> &lt;span class="na">role&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;group&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">div&lt;/span> &lt;span class="na">role&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;treeitem&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>工作文档.docx&lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">div&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">div&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">div&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">div&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;li>
&lt;p>&lt;strong>Real-time communication roles&lt;/strong>:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-html" data-lang="html">&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">div&lt;/span> &lt;span class="na">role&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;feed&amp;#34;&lt;/span> &lt;span class="na">aria-busy&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;false&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">article&lt;/span> &lt;span class="na">role&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;article&amp;#34;&lt;/span> &lt;span class="na">aria-posinset&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;1&amp;#34;&lt;/span> &lt;span class="na">aria-setsize&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;10&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>...&lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">article&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">div&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;li>
&lt;p>&lt;strong>Drag-and-drop roles&lt;/strong>:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-html" data-lang="html">&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">div&lt;/span> &lt;span class="na">role&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;draggable&amp;#34;&lt;/span> &lt;span class="na">aria-grabbed&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;false&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>Draggable item&lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">div&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">div&lt;/span> &lt;span class="na">role&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;droppable&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&amp;lt;/&lt;/span>&lt;span class="nt">div&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;/ul>
&lt;h2 id="the-core-role-of-aria-in-ai-driven-testing">The Core Role of ARIA in AI-Driven Testing
&lt;/h2>&lt;h3 id="enhanced-semantic-understanding">Enhanced Semantic Understanding
&lt;/h3>&lt;p>An AI test system, through the semantic network built by ARIA roles, can understand UI functions more accurately:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">graph TD
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> A[Raw DOM] --&amp;gt; B(Visual Feature Analysis)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> A --&amp;gt; C(ARIA Role Parsing)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> C --&amp;gt; D[Semantic Understanding Layer]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> B --&amp;gt; D
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> D --&amp;gt; E[Component Function Classification]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> D --&amp;gt; F[Operation Intent Inference]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>&lt;strong>Typical application scenarios&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Automatically identify unmarked required form fields (via &lt;code>aria-required&lt;/code>)&lt;/li>
&lt;li>Detect the priority of dynamic content updates (via &lt;code>aria-live&lt;/code> values &lt;code>polite&lt;/code>/&lt;code>assertive&lt;/code>)&lt;/li>
&lt;li>Identify the interaction boundaries of composite components (such as the modal scope of &lt;code>role=&amp;quot;dialog&amp;quot;&lt;/code>)&lt;/li>
&lt;/ul>
&lt;h3 id="intelligent-test-case-generation">Intelligent Test Case Generation
&lt;/h3>&lt;p>The ARIA-based AI test generation workflow:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Role graph construction&lt;/strong>:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">build_role_graph&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">page&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">graph&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">{}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">for&lt;/span> &lt;span class="n">element&lt;/span> &lt;span class="ow">in&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">query_selector_all&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;[role]&amp;#39;&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">role&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">element&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">get_attribute&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;role&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">related&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">get_related_aria_attributes&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">element&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">graph&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">element&lt;/span>&lt;span class="p">]&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="s1">&amp;#39;role&amp;#39;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">role&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;attributes&amp;#39;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">related&lt;/span>&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">graph&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;li>
&lt;p>&lt;strong>Test strategy matching&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Button-type roles (&lt;code>button&lt;/code>, &lt;code>switch&lt;/code>) → click action sequences&lt;/li>
&lt;li>Input-type roles (&lt;code>textbox&lt;/code>, &lt;code>spinbutton&lt;/code>) → input validation tests&lt;/li>
&lt;li>Status-type roles (&lt;code>progressbar&lt;/code>, &lt;code>timer&lt;/code>) → dynamic monitoring tests&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Edge case derivation&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>When &lt;code>role=&amp;quot;combobox&amp;quot;&lt;/code> is detected but &lt;code>aria-controls&lt;/code> is missing&lt;/li>
&lt;li>When child items in &lt;code>role=&amp;quot;tablist&amp;quot;&lt;/code> do not have &lt;code>aria-selected&lt;/code> set correctly&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;h3 id="23-self-healing-test-maintenance">2.3 Self-Healing Test Maintenance
&lt;/h3>&lt;p>The self-healing test mechanism implemented by an AI system using ARIA:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">sequenceDiagram
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Test Case-&amp;gt;&amp;gt;+AI Engine: Location failed (old selector)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> AI Engine-&amp;gt;&amp;gt;+DOM: Query elements with the same role
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> DOM--&amp;gt;&amp;gt;-AI Engine: Return candidate elements
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> AI Engine-&amp;gt;&amp;gt;+ARIA Analyzer: Validate name/state
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ARIA Analyzer--&amp;gt;&amp;gt;-AI Engine: Best match result
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> AI Engine-&amp;gt;&amp;gt;Test Case: Update locator
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>&lt;strong>Expected effects&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Reduced selector maintenance effort&lt;/li>
&lt;li>Lower false-positive rate compared with traditional methods&lt;/li>
&lt;li>Improved cross-platform test consistency&lt;/li>
&lt;/ul>
&lt;h2 id="synergy-between-aria-and-computer-vision-testing">Synergy Between ARIA and Computer Vision Testing
&lt;/h2>&lt;h3 id="31-multimodal-test-fusion">3.1 Multimodal Test Fusion
&lt;/h3>&lt;p>The advantages of combining ARIA and CV in modern AI test platforms:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Detection Dimension&lt;/th>
&lt;th>Information Provided by ARIA&lt;/th>
&lt;th>Supplementary Information from CV&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Element Function&lt;/td>
&lt;td>Explicit role definition&lt;/td>
&lt;td>Visual style verification&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Interaction State&lt;/td>
&lt;td>Attributes such as aria-pressed&lt;/td>
&lt;td>Actual rendered state&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Hierarchical Relationship&lt;/td>
&lt;td>Attributes such as aria-owns&lt;/td>
&lt;td>Spatial position relationship&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Dynamic Changes&lt;/td>
&lt;td>aria-live regions&lt;/td>
&lt;td>Pixel-level change detection&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;strong>Example collaborative workflow&lt;/strong>:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">validate_accessible_button&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">element&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># ARIA verification&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">assert&lt;/span> &lt;span class="n">element&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">get_attribute&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;role&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="s1">&amp;#39;button&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">assert&lt;/span> &lt;span class="n">element&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">get_attribute&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;aria-label&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="ow">is&lt;/span> &lt;span class="ow">not&lt;/span> &lt;span class="kc">None&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># CV verification&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">screenshot&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">element&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">screenshot&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">cv_result&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">analyze_button_visuals&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">screenshot&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">assert&lt;/span> &lt;span class="n">cv_result&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;contrast_ratio&amp;#39;&lt;/span>&lt;span class="p">]&lt;/span> &lt;span class="o">&amp;gt;=&lt;/span> &lt;span class="mf">4.5&lt;/span> &lt;span class="c1"># WCAG AA standard&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="intelligent-accessibility-auditing">Intelligent Accessibility Auditing
&lt;/h3>&lt;p>Architecture of an AI-driven ARIA audit system:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">[Page Crawling Module]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ↓
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">[ARIA Attribute Extractor]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ↓
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">[Rule Engine]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">├── WCAG 2.1 rule set
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">├── Custom business rules
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">└── Machine-learning anomaly detection
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ↓
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">[Fix Suggestion Generation]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">├── Automatic fix solutions
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">├── Design pattern recommendations
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">└── Code completion hints
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="ai-test-automation-application-scenarios">AI Test Automation Application Scenarios
&lt;/h2>&lt;h3 id="large-language-model-llm-integration">Large Language Model (LLM) Integration
&lt;/h3>&lt;p>The structured context that ARIA can provide to an LLM:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-markdown" data-lang="markdown">&lt;span class="line">&lt;span class="cl">Given the following ARIA context:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">-&lt;/span> Currently focused element: role=&amp;#34;combobox&amp;#34;, aria-expanded=&amp;#34;false&amp;#34;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">-&lt;/span> Related elements:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">*&lt;/span> role=&amp;#34;listbox&amp;#34; (hidden)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">*&lt;/span> role=&amp;#34;option&amp;#34; x3 (hidden)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Test action sequence generated by the LLM:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">1.&lt;/span> Trigger the expand action of the combobox
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">2.&lt;/span> Verify that the listbox visibility becomes true
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">3.&lt;/span> Get the option list and select the second item
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">4.&lt;/span> Verify that the combobox&amp;#39;s aria-activedescendant is updated
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="scriptless-test-automation">Scriptless Test Automation
&lt;/h3>&lt;p>Combining ARIA and MCP to achieve zero-code testing:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Recording phase&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Listen for ARIA role changes across all interaction events&lt;/li>
&lt;li>Build an action-state transition graph&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Replay phase&lt;/strong>:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">replay_by_aria&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">flow&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">for&lt;/span> &lt;span class="n">step&lt;/span> &lt;span class="ow">in&lt;/span> &lt;span class="n">flow&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">target&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">find_element_by_role_state&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">step&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;role&amp;#39;&lt;/span>&lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">step&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;attributes&amp;#39;&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">execute_action&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">target&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">step&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;action&amp;#39;&lt;/span>&lt;span class="p">])&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">validate_aria_states&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">step&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;expected_states&amp;#39;&lt;/span>&lt;span class="p">])&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;/ol>
&lt;h3 id="cross-device-test-adaptation">Cross-Device Test Adaptation
&lt;/h3>&lt;p>Mapping strategies for ARIA roles across different devices:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Desktop Role&lt;/th>
&lt;th>Mobile Equivalent Mode&lt;/th>
&lt;th>AI Handling Strategy&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>tablist&lt;/td>
&lt;td>Bottom navigation bar&lt;/td>
&lt;td>Automatic adaptation based on aria-orientation&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>tooltip&lt;/td>
&lt;td>Long-press hint&lt;/td>
&lt;td>Automatic adjustment of interaction timeout&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>slider&lt;/td>
&lt;td>Touch slider&lt;/td>
&lt;td>Step size optimized based on screen size&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="future-directions">Future Directions
&lt;/h2>&lt;h3 id="deep-integration-of-aria-and-testing-ai">Deep Integration of ARIA and Testing AI
&lt;/h3>&lt;ul>
&lt;li>Role-driven autonomous exploratory testing&lt;/li>
&lt;li>Transfer learning based on role similarity&lt;/li>
&lt;/ul>
&lt;h3 id="integration-with-other-emerging-test-technologies">Integration with Other Emerging Test Technologies
&lt;/h3>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">graph LR
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> A[ARIA Semantics] --&amp;gt; B[VR/AR Testing]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> A --&amp;gt; C[Voice Interaction Testing]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> A --&amp;gt; D[IoT Interface Testing]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="standardization-evolution">Standardization Evolution
&lt;/h3>&lt;p>The ARIA 2.0 specification currently being drafted will add:&lt;/p>
&lt;ul>
&lt;li>More fine-grained state descriptions&lt;/li>
&lt;li>Enhanced AI-assisted attributes&lt;/li>
&lt;li>Three-dimensional interface support&lt;/li>
&lt;/ul>
&lt;h2 id="conclusion">Conclusion
&lt;/h2>&lt;p>The ARIA standard is becoming key infrastructure for intelligent test automation. The rich semantic layer it provides enables AI systems to understand the interaction logic of web applications much as humans do. As the W3C continues to refine the standard and the testing toolchain evolves, ARIA-based, AI-driven testing is bound to become a core pillar in the field of web test automation.&lt;/p>
&lt;hr>
&lt;h1 id="w3c-aria-roles-and-their-application-in-playwright-test-automation">W3C ARIA Roles and Their Application in Playwright Test Automation
&lt;/h1>&lt;p>As a test automation engineer, understanding and correctly applying ARIA (Accessible Rich Internet Applications) Roles from the W3C standard is essential for building accessible web applications and writing reliable automated test scripts. This article introduces the core concepts, categories, and best practices of ARIA Roles in detail, with a focus on how to effectively leverage these roles for element location and verification within the Playwright testing framework.&lt;/p>
&lt;h2 id="i-overview-of-aria-roles">I. Overview of ARIA Roles
&lt;/h2>&lt;h3 id="11-what-are-aria-roles">1.1 What Are ARIA Roles
&lt;/h3>&lt;p>ARIA Roles are a set of attributes defined in the W3C WAI-ARIA specification, used to describe the function and purpose of web elements and to help assistive technologies (such as screen readers) understand and convey page content more accurately. ARIA Roles are added to HTML elements through the &lt;code>role&lt;/code> attribute; for example, &lt;code>&amp;lt;div role=&amp;quot;button&amp;quot;&amp;gt;&lt;/code> indicates that the div element should be treated as a button.&lt;/p>
&lt;h3 id="12-the-importance-of-aria-roles">1.2 The Importance of ARIA Roles
&lt;/h3>&lt;p>In web test automation, ARIA Roles offer the following advantages:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Enhanced element semantics&lt;/strong>: provide clear semantics for custom controls or non-standard HTML elements&lt;/li>
&lt;li>&lt;strong>Improved test reliability&lt;/strong>: compared with fragile CSS selectors or XPath, role-based location is more stable&lt;/li>
&lt;li>&lt;strong>Accessibility testing support&lt;/strong>: verify whether the application complies with accessibility standards (WCAG)&lt;/li>
&lt;li>&lt;strong>Cross-browser consistency&lt;/strong>: ARIA Roles behave consistently across different browsers, reducing test discrepancies&lt;/li>
&lt;/ol>
&lt;h2 id="ii-categories-of-aria-roles-and-common-roles">II. Categories of ARIA Roles and Common Roles
&lt;/h2>&lt;h3 id="21-main-categories-of-aria-roles">2.1 Main Categories of ARIA Roles
&lt;/h3>&lt;p>According to the W3C specification, ARIA Roles can be divided into the following major categories:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Widget Roles&lt;/strong>: describe interactive UI components&lt;/p>
&lt;ul>
&lt;li>&lt;code>button&lt;/code>: a clickable button&lt;/li>
&lt;li>&lt;code>checkbox&lt;/code>: a checkbox&lt;/li>
&lt;li>&lt;code>radio&lt;/code>: a radio button&lt;/li>
&lt;li>&lt;code>textbox&lt;/code>: a text input box&lt;/li>
&lt;li>&lt;code>combobox&lt;/code>: a dropdown combo box&lt;/li>
&lt;li>&lt;code>slider&lt;/code>: a slider control&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Document Structure Roles&lt;/strong>: describe the structure of page content&lt;/p>
&lt;ul>
&lt;li>&lt;code>heading&lt;/code>: a heading (alternative to h1-h6)&lt;/li>
&lt;li>&lt;code>list&lt;/code>/&lt;code>listitem&lt;/code>: a list and list items&lt;/li>
&lt;li>&lt;code>table&lt;/code>/&lt;code>row&lt;/code>/&lt;code>cell&lt;/code>: table structure&lt;/li>
&lt;li>&lt;code>img&lt;/code>: an image&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Landmark Roles&lt;/strong>: identify the main regions of a page&lt;/p>
&lt;ul>
&lt;li>&lt;code>banner&lt;/code>: page header&lt;/li>
&lt;li>&lt;code>navigation&lt;/code>: navigation region&lt;/li>
&lt;li>&lt;code>main&lt;/code>: main content&lt;/li>
&lt;li>&lt;code>search&lt;/code>: search region&lt;/li>
&lt;li>&lt;code>contentinfo&lt;/code>: footer information&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Live Region Roles&lt;/strong>: regions for dynamic content updates&lt;/p>
&lt;ul>
&lt;li>&lt;code>alert&lt;/code>: important information that needs immediate notification&lt;/li>
&lt;li>&lt;code>status&lt;/code>: feedback on operation status&lt;/li>
&lt;li>&lt;code>timer&lt;/code>: a timer or counter&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;h3 id="22-examples-of-common-aria-roles">2.2 Examples of Common ARIA Roles
&lt;/h3>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-html" data-lang="html">&lt;span class="line">&lt;span class="cl">&lt;span class="c">&amp;lt;!-- Button role --&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">div&lt;/span> &lt;span class="na">role&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;button&amp;#34;&lt;/span> &lt;span class="na">tabindex&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;0&amp;#34;&lt;/span> &lt;span class="na">aria-pressed&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;false&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>Custom button&lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">div&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c">&amp;lt;!-- Navigation region --&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">nav&lt;/span> &lt;span class="na">role&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;navigation&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">ul&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">li&lt;/span>&lt;span class="p">&amp;gt;&amp;lt;&lt;/span>&lt;span class="nt">a&lt;/span> &lt;span class="na">href&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;/&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>Home&lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">a&lt;/span>&lt;span class="p">&amp;gt;&amp;lt;/&lt;/span>&lt;span class="nt">li&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">ul&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">nav&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c">&amp;lt;!-- Alert message --&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">div&lt;/span> &lt;span class="na">role&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;alert&amp;#34;&lt;/span> &lt;span class="na">aria-live&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;assertive&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> Your operation has been saved successfully
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;/&lt;/span>&lt;span class="nt">div&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c">&amp;lt;!-- Progress bar --&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&amp;lt;&lt;/span>&lt;span class="nt">div&lt;/span> &lt;span class="na">role&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;progressbar&amp;#34;&lt;/span> &lt;span class="na">aria-valuenow&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;75&amp;#34;&lt;/span> &lt;span class="na">aria-valuemin&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;0&amp;#34;&lt;/span> &lt;span class="na">aria-valuemax&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s">&amp;#34;100&amp;#34;&lt;/span>&lt;span class="p">&amp;gt;&amp;lt;/&lt;/span>&lt;span class="nt">div&lt;/span>&lt;span class="p">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="iii-aria-in-playwright">III. ARIA in Playwright
&lt;/h2>&lt;h3 id="31-element-location-based-on-aria-roles">3.1 Element Location Based on ARIA Roles
&lt;/h3>&lt;p>Playwright provides a dedicated &lt;code>getByRole()&lt;/code> locator method, which is the best way to locate elements using ARIA Roles. Compared with traditional CSS or XPath selectors, role-based location is more stable and semantically explicit.&lt;/p>
&lt;p>&lt;strong>Basic syntax&lt;/strong>:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-javascript" data-lang="javascript">&lt;span class="line">&lt;span class="cl">&lt;span class="kr">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;button&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;提交&amp;#39;&lt;/span> &lt;span class="p">}).&lt;/span>&lt;span class="nx">click&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>&lt;strong>Common role location examples&lt;/strong>:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-javascript" data-lang="javascript">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Locate the button named &amp;#34;Search&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;button&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;搜索&amp;#39;&lt;/span> &lt;span class="p">}).&lt;/span>&lt;span class="nx">click&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Locate the checkbox and check it
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;checkbox&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;同意条款&amp;#39;&lt;/span> &lt;span class="p">}).&lt;/span>&lt;span class="nx">check&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Locate the text input and fill in content
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;textbox&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;用户名&amp;#39;&lt;/span> &lt;span class="p">}).&lt;/span>&lt;span class="nx">fill&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;testuser&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Locate the dropdown and select an option
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;combobox&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;国家&amp;#39;&lt;/span> &lt;span class="p">}).&lt;/span>&lt;span class="nx">selectOption&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;中国&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="32-option-parameters-of-the-role-locator">3.2 Option Parameters of the Role Locator
&lt;/h3>&lt;p>The &lt;code>getByRole()&lt;/code> method supports a variety of option parameters for more precise element location:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-javascript" data-lang="javascript">&lt;span class="line">&lt;span class="cl">&lt;span class="kr">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;button&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;提交&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="c1">// accessible name
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="nx">pressed&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="kc">false&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="c1">// button state (whether pressed)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="nx">expanded&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="kc">true&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="c1">// whether expanded (for menus, etc.)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="nx">disabled&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="kc">false&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="c1">// whether disabled
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="nx">checked&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="kc">false&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="c1">// whether checked (checkbox/radio button)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="nx">selected&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="kc">false&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="c1">// whether selected (tabs, etc.)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="nx">includeHidden&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="kc">false&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="c1">// whether to include hidden elements
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span> &lt;span class="nx">exact&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="kc">true&lt;/span> &lt;span class="c1">// whether the name matches exactly
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="p">});&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="33-verifying-aria-attributes-and-states">3.3 Verifying ARIA Attributes and States
&lt;/h3>&lt;p>Playwright can not only locate elements but also verify ARIA attributes and states:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-javascript" data-lang="javascript">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Verify whether the button is disabled
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">expect&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;button&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;提交&amp;#39;&lt;/span> &lt;span class="p">})).&lt;/span>&lt;span class="nx">toBeDisabled&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Verify whether the checkbox is checked
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">expect&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;checkbox&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;记住我&amp;#39;&lt;/span> &lt;span class="p">})).&lt;/span>&lt;span class="nx">toBeChecked&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Verify whether the element is visible
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">expect&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;alert&amp;#39;&lt;/span>&lt;span class="p">)).&lt;/span>&lt;span class="nx">toBeVisible&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Verify the element&amp;#39;s ARIA attribute value
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">const&lt;/span> &lt;span class="nx">button&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;button&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;展开&amp;#39;&lt;/span> &lt;span class="p">});&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kr">await&lt;/span> &lt;span class="nx">expect&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">button&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="nx">toHaveAttribute&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;aria-expanded&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;false&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="iv-aria-snapshot-testing-in-playwright">IV. ARIA Snapshot Testing in Playwright
&lt;/h2>&lt;p>Playwright provides a powerful ARIA snapshot feature that can capture and verify the accessibility tree structure of a page.&lt;/p>
&lt;h3 id="41-aria-snapshot-basics">4.1 ARIA Snapshot Basics
&lt;/h3>&lt;p>An ARIA snapshot is a YAML representation of the page&amp;rsquo;s accessibility tree, containing the roles, names, states, and hierarchical relationships of elements:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">- &lt;span class="nt">banner&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">heading &amp;#34;欢迎页面&amp;#34; [level=1]&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>- &lt;span class="nt">main&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">button &amp;#34;提交&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">textbox &amp;#34;用户名&amp;#34; [placeholder=&amp;#34;请输入用户名&amp;#34;]&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="42-snapshot-matching-assertions">4.2 Snapshot Matching Assertions
&lt;/h3>&lt;p>Use &lt;code>toMatchAriaSnapshot()&lt;/code> for snapshot verification:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-javascript" data-lang="javascript">&lt;span class="line">&lt;span class="cl">&lt;span class="kr">await&lt;/span> &lt;span class="nx">expect&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;body&amp;#39;&lt;/span>&lt;span class="p">)).&lt;/span>&lt;span class="nx">toMatchAriaSnapshot&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sb">`
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - heading &amp;#34;欢迎页面&amp;#34; [level=1]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - button &amp;#34;提交&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">`&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="43-partial-matching-and-regular-expressions">4.3 Partial Matching and Regular Expressions
&lt;/h3>&lt;p>Snapshots support flexible partial matching:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;span class="lnt">9
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-javascript" data-lang="javascript">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Match the role only, not the name
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">expect&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;dialog&amp;#39;&lt;/span>&lt;span class="p">)).&lt;/span>&lt;span class="nx">toMatchAriaSnapshot&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sb">`
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - dialog
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">`&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Use a regular expression to match dynamic text
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">expect&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;body&amp;#39;&lt;/span>&lt;span class="p">)).&lt;/span>&lt;span class="nx">toMatchAriaSnapshot&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sb">`
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - heading /订单 \d+/
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">`&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="44-generating-and-updating-snapshots">4.4 Generating and Updating Snapshots
&lt;/h3>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Update snapshots using the --update-snapshots flag&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">npx playwright &lt;span class="nb">test&lt;/span> --update-snapshots
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Or generate it programmatically:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-javascript" data-lang="javascript">&lt;span class="line">&lt;span class="cl">&lt;span class="kr">const&lt;/span> &lt;span class="nx">snapshot&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="kr">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;#main&amp;#39;&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="nx">ariaSnapshot&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nx">console&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">log&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">snapshot&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="v-best-practices-for-aria-testing">V. Best Practices for ARIA Testing
&lt;/h2>&lt;h3 id="51-principles-for-using-roles">5.1 Principles for Using Roles
&lt;/h3>&lt;ol>
&lt;li>&lt;strong>Prefer native HTML elements&lt;/strong>: e.g., use &lt;code>&amp;lt;button&amp;gt;&lt;/code> instead of &lt;code>&amp;lt;div role=&amp;quot;button&amp;quot;&amp;gt;&lt;/code>&lt;/li>
&lt;li>&lt;strong>Avoid redundant roles&lt;/strong>: e.g., &lt;code>&amp;lt;nav role=&amp;quot;navigation&amp;quot;&amp;gt;&lt;/code> is redundant because &lt;code>&amp;lt;nav&amp;gt;&lt;/code> already implies that role&lt;/li>
&lt;li>&lt;strong>Combine roles and attributes correctly&lt;/strong>: e.g., &lt;code>role=&amp;quot;checkbox&amp;quot;&lt;/code> should be used together with &lt;code>aria-checked&lt;/code>&lt;/li>
&lt;/ol>
&lt;h3 id="52-playwright-testing-recommendations">5.2 Playwright Testing Recommendations
&lt;/h3>&lt;ol>
&lt;li>&lt;strong>Prefer ARIA locators&lt;/strong>: more stable and reliable than CSS/XPath&lt;/li>
&lt;li>&lt;strong>Combine with accessible names&lt;/strong>: use the &lt;code>name&lt;/code> option to improve location accuracy&lt;/li>
&lt;li>&lt;strong>Verify dynamic ARIA states&lt;/strong>: such as &lt;code>aria-expanded&lt;/code>, &lt;code>aria-selected&lt;/code>, etc.&lt;/li>
&lt;li>&lt;strong>Check ARIA snapshots regularly&lt;/strong>: ensure the page structure complies with accessibility standards&lt;/li>
&lt;li>&lt;strong>Test keyboard navigation&lt;/strong>: use &lt;code>page.keyboard&lt;/code> to test accessibility&lt;/li>
&lt;/ol>
&lt;h3 id="53-common-issue-troubleshooting">5.3 Common Issue Troubleshooting
&lt;/h3>&lt;ol>
&lt;li>&lt;strong>Element not visible&lt;/strong>: add &lt;code>includeHidden: true&lt;/code> or check the &lt;code>aria-hidden&lt;/code> attribute&lt;/li>
&lt;li>&lt;strong>Name mismatch&lt;/strong>: use &lt;code>exact: false&lt;/code> or a regular expression&lt;/li>
&lt;li>&lt;strong>Dynamic content&lt;/strong>: use &lt;code>await expect().toHaveAttribute()&lt;/code> to wait for state changes&lt;/li>
&lt;li>&lt;strong>Custom controls&lt;/strong>: ensure appropriate ARIA roles and attributes are added&lt;/li>
&lt;/ol>
&lt;h2 id="vi-aria-in-complex-components">VI. ARIA in Complex Components
&lt;/h2>&lt;h3 id="61-navigation-menu-testing">6.1 Navigation Menu Testing
&lt;/h3>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-javascript" data-lang="javascript">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Expand the menu
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;button&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;菜单&amp;#39;&lt;/span> &lt;span class="p">}).&lt;/span>&lt;span class="nx">click&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Verify the menu items
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">expect&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;menu&amp;#39;&lt;/span>&lt;span class="p">)).&lt;/span>&lt;span class="nx">toMatchAriaSnapshot&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sb">`
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - menu:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - menuitem &amp;#34;首页&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - menuitem &amp;#34;产品&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - menuitem &amp;#34;关于我们&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">`&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Select a menu item
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;menuitem&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;产品&amp;#39;&lt;/span> &lt;span class="p">}).&lt;/span>&lt;span class="nx">click&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="62-tabs-testing">6.2 Tabs Testing
&lt;/h3>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-javascript" data-lang="javascript">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Verify the tab structure
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">expect&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;.tabs-container&amp;#39;&lt;/span>&lt;span class="p">)).&lt;/span>&lt;span class="nx">toMatchAriaSnapshot&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sb">`
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - tablist:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - tab &amp;#34;基本信息&amp;#34; [selected=true]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - tab &amp;#34;高级设置&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - tabpanel:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - textbox &amp;#34;用户名&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">`&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Switch tabs
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;tab&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;高级设置&amp;#39;&lt;/span> &lt;span class="p">}).&lt;/span>&lt;span class="nx">click&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kr">await&lt;/span> &lt;span class="nx">expect&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;tab&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;高级设置&amp;#39;&lt;/span> &lt;span class="p">})).&lt;/span>&lt;span class="nx">toHaveAttribute&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;aria-selected&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;true&amp;#39;&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="63-modal-dialog-testing">6.3 Modal Dialog Testing
&lt;/h3>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-javascript" data-lang="javascript">&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Open the dialog
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;button&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;删除&amp;#39;&lt;/span> &lt;span class="p">}).&lt;/span>&lt;span class="nx">click&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Verify the dialog
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">expect&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;dialog&amp;#39;&lt;/span>&lt;span class="p">)).&lt;/span>&lt;span class="nx">toMatchAriaSnapshot&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sb">`
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - dialog &amp;#34;确认删除&amp;#34;:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - heading &amp;#34;确认删除&amp;#34; [level=2]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - button &amp;#34;取消&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - button &amp;#34;确认&amp;#34; [disabled=false]
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">`&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">// Operate the dialog
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="kr">await&lt;/span> &lt;span class="nx">page&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">getByRole&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;button&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span> &lt;span class="nx">name&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="s1">&amp;#39;确认&amp;#39;&lt;/span> &lt;span class="p">}).&lt;/span>&lt;span class="nx">click&lt;/span>&lt;span class="p">();&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h2 id="vii-conclusion">VII. Conclusion
&lt;/h2>&lt;p>As a test automation engineer, mastering W3C ARIA Roles and applying them effectively in Playwright testing brings multiple benefits:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Improved test stability&lt;/strong>: location based on semantic roles is more reliable than location based on implementation details&lt;/li>
&lt;li>&lt;strong>Enhanced accessibility&lt;/strong>: ensure the application complies with WCAG standards and serves a broader user base&lt;/li>
&lt;li>&lt;strong>Simplified test maintenance&lt;/strong>: when UI styles change, role-based tests usually do not need updating&lt;/li>
&lt;li>&lt;strong>Cross-platform testing support&lt;/strong>: ARIA Roles behave consistently across different browsers and devices&lt;/li>
&lt;/ol>
&lt;p>By combining Playwright&amp;rsquo;s ARIA locators, state verification, and snapshot testing features, you can build a robust, maintainable, and accessibility-conscious automated test suite. As web applications grow increasingly complex, the importance of ARIA Roles in test automation will continue to grow, making them one of the core skills that modern web test engineers must master.&lt;/p>
&lt;hr>
&lt;h2 id="v-implementation-recommendations-and-challenges">V. Implementation Recommendations and Challenges
&lt;/h2>&lt;h3 id="51-adoption-roadmap">5.1 Adoption Roadmap
&lt;/h3>&lt;ol>
&lt;li>
&lt;p>&lt;strong>Foundation phase&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Gradually introduce the &lt;code>getByRole&lt;/code> locator into existing tests&lt;/li>
&lt;li>Add ARIA snapshot comparisons&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Advanced phase&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Build a role-driven test case library&lt;/li>
&lt;li>Develop ARIA compliance monitoring&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>AI integration phase&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Train a dedicated role classification model&lt;/li>
&lt;li>Implement automatic test script generation&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;h3 id="52-solutions-to-common-challenges">5.2 Solutions to Common Challenges
&lt;/h3>&lt;p>&lt;strong>Challenge 1: Dynamic Role Assignment&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Solution: use MutationObserver to listen for role changes
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-javascript" data-lang="javascript">&lt;span class="line">&lt;span class="cl">&lt;span class="k">new&lt;/span> &lt;span class="nx">MutationObserver&lt;/span>&lt;span class="p">((&lt;/span>&lt;span class="nx">mutations&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">=&amp;gt;&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">mutations&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">forEach&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">m&lt;/span> &lt;span class="p">=&amp;gt;&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nx">m&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">attributeName&lt;/span> &lt;span class="o">===&lt;/span> &lt;span class="s1">&amp;#39;role&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nx">updateAIElementRegistry&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">m&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">target&lt;/span>&lt;span class="p">);&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">});&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}).&lt;/span>&lt;span class="nx">observe&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nb">document&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">{&lt;/span>&lt;span class="nx">attributes&lt;/span>&lt;span class="o">:&lt;/span> &lt;span class="kc">true&lt;/span>&lt;span class="p">});&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Challenge 2: Role Misuse Detection&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Solution: pattern recognition algorithm
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">detect_role_misuse&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">element&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">valid_roles&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">get_valid_roles_for_tag&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">element&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">tag_name&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">current_role&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">element&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">get_attribute&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;role&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="n">current_role&lt;/span> &lt;span class="ow">not&lt;/span> &lt;span class="ow">in&lt;/span> &lt;span class="n">valid_roles&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">suggest_native_element&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">element&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">tag_name&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">current_role&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Challenge 3: Cross-Framework Consistency&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>Solution: an intermediate abstraction layer
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">[React/Vue/Angular components]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> → [ARIA adaptation layer]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> → [Standardized role tree]
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> → [AI test engine]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;/li>
&lt;/ul></description></item><item><title>AI Testing, the Inevitable Path for Testing Teams</title><link>https://chengxiaqiucao.github.io/en/post/083-ai%E6%B5%8B%E8%AF%95%E8%B7%AF%E7%BA%BF%E5%9B%BE/</link><pubDate>Sat, 26 Apr 2025 00:00:00 +0000</pubDate><guid>https://chengxiaqiucao.github.io/en/post/083-ai%E6%B5%8B%E8%AF%95%E8%B7%AF%E7%BA%BF%E5%9B%BE/</guid><description>&lt;blockquote>
&lt;p>This article is translated and adapted from the latest post on the well-known testing blog &lt;a class="link" href="https://testguild.com/" target="_blank" rel="noopener"
>https://testguild.com/&lt;/a> and discusses a roadmap for systematically implementing and advancing AI testing within testing teams. It offers considerable reference value, so I am sharing it with you all.&lt;/p>&lt;/blockquote>
&lt;h2 id="ai-test-automation-is-no-longer-optional">AI Test Automation Is No Longer Optional
&lt;/h2>&lt;p>In today&amp;rsquo;s software testing field, artificial intelligence (AI) is no longer merely an option but a significant strategic advantage. AI-driven testing tools can automate everything from test case generation to test execution, enabling your team to focus on delivering higher-quality software releases.&lt;/p>
&lt;p>Tal Barmeir, CEO of Blinq.io, once noted: &amp;ldquo;The role of generative AI is to help us truly solve the problem of a massive backlog of testing demand with very limited coverage—a phenomenon we see across every industry.&amp;rdquo;&lt;/p>
&lt;p>AI-driven testing tools can automate the entire process from test case creation to execution and maintenance, helping testing teams:&lt;/p>
&lt;ul>
&lt;li>Reduce test creation time by up to 80%&lt;/li>
&lt;li>Lower test maintenance costs by 40-60%&lt;/li>
&lt;li>Accelerate time to market through faster release cycles&lt;/li>
&lt;li>Improve test coverage across browsers, devices, and environments&lt;/li>
&lt;li>Free up valuable engineering resources for innovation&lt;/li>
&lt;/ul>
&lt;p>This guide offers a structured approach to implementing AI testing, designed to deliver both immediate benefits and long-term transformation.&lt;/p>
&lt;h2 id="phase-1-days-1-15---define-your-ai-testing-strategy">Phase 1 (Days 1-15) - Define Your AI Testing Strategy
&lt;/h2>&lt;p>Before diving into specific tools, you first need to clarify how you want to apply AI:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Assistive AI&lt;/strong>: Enhances human-led testing processes.&lt;/li>
&lt;li>&lt;strong>Autonomous AI&lt;/strong>: Test automation driven entirely by AI, with human oversight.&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>&amp;ldquo;Most organizations start with assistive AI. But they soon realize its value is limited and try to move to fully AI-led. That shift requires different tools, structures, and mindsets.&amp;rdquo;&lt;/p>&lt;/blockquote>
&lt;p>For decision-making leaders of testing teams, the key strategic decisions include:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Scope of automation&lt;/strong>: Is your team automating existing test cases, or allowing AI to take full charge of creating, executing, and maintaining test scripts?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Integration requirements&lt;/strong>: How will AI testing integrate with your existing CI/CD pipelines and development workflows?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Success metrics&lt;/strong>: Which KPIs will be used to measure success (such as test coverage, execution time, defect detection, and so on)?&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Risk assessment&lt;/strong>: Which applications or features are best suited as the initial targets for AI testing implementation?&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Action recommendation&lt;/strong>: Before evaluating tools, be sure to define your AI testing vision, scope, and success criteria.&lt;/p>
&lt;h2 id="phase-2-days-16-30---redefine-qa-roles-and-test-inputs">Phase 2 (Days 16-30) - Redefine QA Roles and Test Inputs
&lt;/h2>&lt;p>AI test automation does not eliminate existing roles; rather, it transforms them.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;strong>Traditional Role&lt;/strong>&lt;/th>
&lt;th>&lt;strong>AI-Augmented Role&lt;/strong>&lt;/th>
&lt;th>&lt;strong>Key Responsibilities&lt;/strong>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Manual Tester&lt;/td>
&lt;td>Prompt Engineer&lt;/td>
&lt;td>Create effective test prompts, review AI-generated tests&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Automation Engineer&lt;/td>
&lt;td>AI Testing Lead&lt;/td>
&lt;td>Oversee the generation, execution, and maintenance of AI tests&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>QA Manager&lt;/td>
&lt;td>AI Testing Strategist&lt;/td>
&lt;td>Define AI testing strategy, measure ROI, optimize processes&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;blockquote>
&lt;p>&amp;ldquo;People often think AI means job losses. That is not the case. What it really does is redeploy testers—manual testers become prompt engineers, and automation engineers become supervisors of AI work.&amp;rdquo;&lt;/p>&lt;/blockquote>
&lt;h3 id="expand-test-input-sources">&lt;strong>Expand Test Input Sources&lt;/strong>
&lt;/h3>&lt;p>AI testing platforms can generate comprehensive test cases from a variety of inputs, including:&lt;/p>
&lt;ul>
&lt;li>Jira tickets and user stories&lt;/li>
&lt;li>Screen recordings of application usage&lt;/li>
&lt;li>Natural language requirements&lt;/li>
&lt;li>API specifications and documentation&lt;/li>
&lt;li>Existing manual test cases&lt;/li>
&lt;/ul>
&lt;p>This flexibility means AI testing does not need to strictly adhere to a BDD framework or a specific test case format, making AI testing accessible to teams at every maturity level.&lt;/p>
&lt;h2 id="phase-3-days-31-45---evaluate-ai-testing-tools">Phase 3 (Days 31-45) - Evaluate AI Testing Tools
&lt;/h2>&lt;p>Choosing the right AI testing tool requires aligning it with your infrastructure, team skills, and long-term vision.&lt;/p>
&lt;h3 id="core-capabilities-of-enterprise-ai-testing-platforms">&lt;strong>Core Capabilities of Enterprise AI Testing Platforms&lt;/strong>
&lt;/h3>&lt;ul>
&lt;li>&lt;strong>Open-source test code generation&lt;/strong>: Generates maintainable code in standard frameworks (such as Playwright, Selenium, and so on).&lt;/li>
&lt;li>&lt;strong>Self-healing capability&lt;/strong>: Automatically adapts to user interface (UI) changes without human intervention.&lt;/li>
&lt;li>&lt;strong>Comprehensive test support&lt;/strong>: Covers functional, visual, performance, and security testing.&lt;/li>
&lt;li>&lt;strong>Enterprise integration&lt;/strong>: Works with your CI/CD pipelines, test management, and defect tracking systems.&lt;/li>
&lt;li>&lt;strong>Cross-platform testing&lt;/strong>: Supports web, mobile, API, and enterprise applications (such as Salesforce, SAP, and so on).&lt;/li>
&lt;li>&lt;strong>Visual testing&lt;/strong>: AI-driven visual comparison and anomaly detection.&lt;/li>
&lt;li>&lt;strong>Flaky test management&lt;/strong>: Automatically identifies and resolves inconsistent tests.&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>&amp;ldquo;Even if you stop using a particular vendor, you still have a code project you can maintain. No black box, no vendor lock-in.&amp;rdquo;&lt;/p>&lt;/blockquote>
&lt;p>&lt;strong>Decision framework&lt;/strong>: Evaluate tools against your specific needs, existing infrastructure, and team capabilities. Give priority to platforms that generate standard, maintainable test code rather than proprietary formats.&lt;/p>
&lt;h2 id="phase-4-days-46-60---train-for-new-ai-augmented-testing-roles">Phase 4 (Days 46-60) - Train for New AI-Augmented Testing Roles
&lt;/h2>&lt;p>Introducing AI into test automation brings new AI capabilities and responsibilities, elevating the role of the QA team.&lt;/p>
&lt;h3 id="key-skills-for-the-ai-testing-era">&lt;strong>Key Skills for the AI Testing Era&lt;/strong>
&lt;/h3>&lt;ul>
&lt;li>&lt;strong>Prompt engineering&lt;/strong>: Creating effective test prompts to generate comprehensive test coverage.&lt;/li>
&lt;li>&lt;strong>AI test review&lt;/strong>: Evaluating and refining AI-generated test scripts.&lt;/li>
&lt;li>&lt;strong>Test maintenance management&lt;/strong>: Overseeing self-healing capabilities and test stability.&lt;/li>
&lt;li>&lt;strong>Test prioritization&lt;/strong>: Determining which tests deliver the highest value in each release.&lt;/li>
&lt;li>&lt;strong>Exploratory testing&lt;/strong>: Concentrating human creativity on edge cases and complex scenarios.&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>&amp;ldquo;The old skills were scripting and debugging. The new skills? Writing prompts, reviewing AI suggestions, and managing code at scale.&amp;rdquo;&lt;/p>&lt;/blockquote>
&lt;h3 id="training-resources-for-the-qa-team">&lt;strong>Training Resources for the QA Team&lt;/strong>:
&lt;/h3>&lt;ul>
&lt;li>Internal workshops on AI testing concepts and prompt engineering.&lt;/li>
&lt;li>Vendor-provided training on specific AI testing platforms.&lt;/li>
&lt;li>Hands-on practice in real application testing scenarios.&lt;/li>
&lt;li>Cross-training between manual and automation testers.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Leadership focus&lt;/strong>: Encourage experimentation and create a learning environment where the team can develop AI testing expertise through real-world application.&lt;/p>
&lt;h2 id="phase-5-days-61-75---pilot-and-expand-ai-testing-coverage">Phase 5 (Days 61-75) - Pilot and Expand AI Testing Coverage
&lt;/h2>&lt;p>Launch a focused pilot project using 10-20 test scenarios to achieve fast, measurable impact and build confidence in AI testing capabilities.&lt;/p>
&lt;h3 id="ideal-pilot-project-characteristics">&lt;strong>Ideal Pilot Project Characteristics&lt;/strong>:
&lt;/h3>&lt;ul>
&lt;li>An application of moderate complexity with a stable UI.&lt;/li>
&lt;li>Existing manual test cases for comparison.&lt;/li>
&lt;li>A regular release cadence to demonstrate CI/CD integration.&lt;/li>
&lt;li>A mix of regression, functional, and visual testing needs.&lt;/li>
&lt;li>Stakeholders who are open to innovation and process change.&lt;/li>
&lt;/ul>
&lt;h3 id="implementation-checklist">&lt;strong>Implementation Checklist&lt;/strong>:
&lt;/h3>&lt;ul>
&lt;li>Select the pilot application and define the test scope.&lt;/li>
&lt;li>Configure the AI testing tool and integrate with CI/CD.&lt;/li>
&lt;li>Create initial test prompts and generate baseline tests.&lt;/li>
&lt;li>Execute tests across multiple environments.&lt;/li>
&lt;li>Measure results against traditional testing methods.&lt;/li>
&lt;li>Document lessons learned and optimization opportunities.&lt;/li>
&lt;/ul>
&lt;p>This phase is ideal for expanding test coverage across browsers, devices, and languages—leveraging the multilingual capabilities of AI models to efficiently test international applications.&lt;/p>
&lt;h2 id="phase-6-days-76-90---measure-kpis-and-optimize">Phase 6 (Days 76-90) - Measure KPIs and Optimize
&lt;/h2>&lt;p>Track key performance indicators (KPIs) to quantify the impact of AI testing implementation and uncover optimization opportunities.&lt;/p>
&lt;h3 id="key-ai-testing-metrics">&lt;strong>Key AI Testing Metrics&lt;/strong>:
&lt;/h3>&lt;ul>
&lt;li>&lt;strong>Release time&lt;/strong>: Reduction in overall test cycle time.&lt;/li>
&lt;li>&lt;strong>Test coverage&lt;/strong>: Increase in functional and platform coverage.&lt;/li>
&lt;li>&lt;strong>Maintenance effort&lt;/strong>: Reduction in test script maintenance time.&lt;/li>
&lt;li>&lt;strong>Defect detection&lt;/strong>: Increase in the defect identification rate.&lt;/li>
&lt;li>&lt;strong>Resource utilization&lt;/strong>: The QA team shifting focus to higher-value activities.&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>&amp;ldquo;Most leaders think AI testing is about cutting costs. But the biggest ROI is actually faster time to market.&amp;rdquo;&lt;/p>&lt;/blockquote>
&lt;h3 id="continuous-improvement-framework">&lt;strong>Continuous Improvement Framework&lt;/strong>:
&lt;/h3>&lt;ul>
&lt;li>Review AI testing performance and accuracy weekly.&lt;/li>
&lt;li>Refine prompts based on test results and missed scenarios.&lt;/li>
&lt;li>Extend AI testing to other applications and test types.&lt;/li>
&lt;li>Document best practices and share them across teams.&lt;/li>
&lt;li>Establish an AI testing center of excellence.&lt;/li>
&lt;/ul>
&lt;p>These insights will support your team in making data-driven decisions about test coverage, release readiness, and quality improvement.&lt;/p>
&lt;h2 id="summary---your-90-day-ai-testing-implementation-roadmap">Summary - Your 90-Day AI Testing Implementation Roadmap
&lt;/h2>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;strong>Phase&lt;/strong>&lt;/th>
&lt;th>&lt;strong>Timeline&lt;/strong>&lt;/th>
&lt;th>&lt;strong>Focus&lt;/strong>&lt;/th>
&lt;th>&lt;strong>Key Deliverables&lt;/strong>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>1&lt;/td>
&lt;td>Days 1-15&lt;/td>
&lt;td>Strategy definition&lt;/td>
&lt;td>AI testing vision, implementation approach, success metrics&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>2&lt;/td>
&lt;td>Days 16-30&lt;/td>
&lt;td>Role transformation&lt;/td>
&lt;td>Updated team structure, skill requirements, input sources&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>3&lt;/td>
&lt;td>Days 31-45&lt;/td>
&lt;td>Tool selection&lt;/td>
&lt;td>AI testing platform evaluation, selection criteria, proof of concept&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>4&lt;/td>
&lt;td>Days 46-60&lt;/td>
&lt;td>Team training&lt;/td>
&lt;td>Skill development plan, training resources, knowledge sharing&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>5&lt;/td>
&lt;td>Days 61-75&lt;/td>
&lt;td>Pilot implementation&lt;/td>
&lt;td>Initial AI test suite, CI/CD integration, baseline metrics&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>6&lt;/td>
&lt;td>Days 76-90&lt;/td>
&lt;td>Measurement and optimization&lt;/td>
&lt;td>Performance analysis, optimization plan, scaling strategy&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="the-future-of-qa---ai-driven-testing-leadership">The Future of QA - AI-Driven Testing Leadership
&lt;/h2>&lt;p>With the right AI testing strategy, your QA organization will not only keep pace with the industry but will lead the transformation toward faster, more reliable software delivery. You are not merely automating tests; you are empowering your team to enhance and streamline the entire testing lifecycle, delivering higher-quality software at unprecedented speed while reducing risk and technical debt. Embrace AI testing now, and you will position your organization at the forefront of quality engineering, creating a sustainable competitive advantage through superior software quality and accelerated innovation.&lt;/p></description></item><item><title>The Definitive Guide to Prompt Engineering - The Art and Science of Empowering Software Testing</title><link>https://chengxiaqiucao.github.io/en/post/080-%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%B7%A5%E7%A8%8B/</link><pubDate>Sun, 20 Apr 2025 00:00:00 +0000</pubDate><guid>https://chengxiaqiucao.github.io/en/post/080-%E6%8F%90%E7%A4%BA%E8%AF%8D%E5%B7%A5%E7%A8%8B/</guid><description>&lt;p>As the wave of artificial intelligence (AI) and large language models (LLMs) sweeps across the globe, the field of software testing is undergoing a profound transformation. Traditional testing methods are merging with cutting-edge AI technologies, and &lt;strong>Prompt Engineering&lt;/strong> is precisely the core skill for steering this transformation. This guide delves into the theory, practice, and advanced techniques of prompt engineering, and offers a series of concrete examples tailored to software testing roles, aiming to help test engineers and teams effectively leverage AI to improve testing efficiency, coverage, and depth.&lt;/p>
&lt;hr>
&lt;h3 id="chapter-1---getting-to-know-prompt-engineering-the-art-of-efficient-dialogue-with-ai">Chapter 1 - Getting to Know Prompt Engineering, the Art of Efficient Dialogue with AI
&lt;/h3>&lt;h4 id="11-what-is-prompt-engineering">1.1 What Is Prompt Engineering?
&lt;/h4>&lt;p>&lt;strong>Prompt engineering&lt;/strong> is a discipline devoted to designing, constructing, and optimizing input text (that is, &amp;ldquo;prompts&amp;rdquo;) so as to guide large language models (LLMs) such as GPT-4 and Claude to generate the high-quality, relevant outputs we expect. If an LLM is a powerful engine packed with vast knowledge, then the prompt is the steering wheel and accelerator that control that engine.&lt;/p>
&lt;p>For software testing, prompt engineering is far more than simply &amp;ldquo;asking AI a question&amp;rdquo;; it is a &lt;strong>strategic form of communication&lt;/strong>. With carefully designed prompts, testers can drive AI to complete a range of complex testing tasks, such as:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Generating test cases&lt;/strong>: Based on requirements documents, user stories, or code snippets, automatically create functional, boundary, exception, and other types of test cases.&lt;/li>
&lt;li>&lt;strong>Creating test data&lt;/strong>: Generate diverse test data that conforms to specific formats and business rules.&lt;/li>
&lt;li>&lt;strong>Writing automation scripts&lt;/strong>: Assist in writing, or directly generate, automation test scripts for frameworks such as Selenium, Cypress, and Playwright.&lt;/li>
&lt;li>&lt;strong>Analyzing test results&lt;/strong>: Summarize, classify, and perform root cause analysis on large volumes of test logs and reports.&lt;/li>
&lt;li>&lt;strong>Simulating user behavior&lt;/strong>: Create interaction scenarios that match specific user personas, for User Acceptance Testing (UAT) or exploratory testing.&lt;/li>
&lt;/ul>
&lt;p>Mastering prompt engineering means test engineers can hand tedious, repetitive work over to AI, freeing them to devote more energy to more creative and strategic testing activities.&lt;/p>
&lt;h4 id="12-core-principles---clarity-specificity-and-context">1.2 Core Principles - Clarity, Specificity, and Context
&lt;/h4>&lt;p>Successful prompt engineering follows one core principle: &lt;strong>Garbage In, Garbage Out (GIGO)&lt;/strong>. The quality of the information you give AI directly determines the quality of its output. Therefore, a good prompt typically has the following characteristics:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Clear &amp;amp; Specific&lt;/strong>: Avoid vague, general language. Tell AI directly what you want.&lt;/li>
&lt;li>&lt;strong>Contextual&lt;/strong>: Provide AI with ample background information, such as descriptions of the feature under test, relevant code, user personas, and business rules.&lt;/li>
&lt;li>&lt;strong>Role Assignment&lt;/strong>: Have AI play a specific role—for example, &amp;ldquo;You are a senior software testing expert&amp;rdquo;—which helps the model respond from a more professional perspective and tone.&lt;/li>
&lt;li>&lt;strong>Format Specification&lt;/strong>: Clearly define the output format you want, such as JSON, CSV, Markdown tables, or bulleted lists.&lt;/li>
&lt;li>&lt;strong>Iterative Refinement&lt;/strong>: Few prompts are perfect on the first try. Be prepared to make multiple attempts and adjustments based on AI&amp;rsquo;s feedback.&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h3 id="chapter-2---a-glossary-of-prompt-engineering-terminology">Chapter 2 - A Glossary of Prompt Engineering Terminology
&lt;/h3>&lt;p>To better understand and apply prompt engineering, it is essential to be familiar with the following key terms.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;/th>
&lt;th>&lt;/th>
&lt;th>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Term&lt;/strong>&lt;/td>
&lt;td>&lt;strong>Chinese Explanation&lt;/strong>&lt;/td>
&lt;td>&lt;strong>Description&lt;/strong>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Prompt&lt;/strong>&lt;/td>
&lt;td>Prompt&lt;/td>
&lt;td>The input text a user provides to an LLM to guide its response.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Zero-shot Prompting&lt;/strong>&lt;/td>
&lt;td>Zero-shot prompting&lt;/td>
&lt;td>Directly asking the LLM to complete a task without providing any examples. Suitable for tasks the model has already mastered.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Few-shot Prompting&lt;/strong>&lt;/td>
&lt;td>Few-shot prompting&lt;/td>
&lt;td>Providing a small number (usually 1-5) of examples in the prompt to show the LLM the expected input-output format and style.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Chain-of-Thought (CoT) Prompting&lt;/strong>&lt;/td>
&lt;td>Chain-of-thought prompting&lt;/td>
&lt;td>Guiding the LLM to reason step by step before giving the final answer, triggered by phrases such as &amp;ldquo;Let&amp;rsquo;s think step by step&amp;rdquo;.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Role Prompting / Persona&lt;/strong>&lt;/td>
&lt;td>Role prompting / persona&lt;/td>
&lt;td>Assigning the LLM a specific role or identity (such as &amp;ldquo;senior security test engineer&amp;rdquo;) to influence the style, tone, and professional depth of its responses.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Context Window&lt;/strong>&lt;/td>
&lt;td>Context window&lt;/td>
&lt;td>The amount of information (measured in tokens) an LLM can remember and process in a single conversation. Information beyond this window is forgotten.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Token&lt;/strong>&lt;/td>
&lt;td>Token&lt;/td>
&lt;td>The basic unit of text an LLM processes, which may be a word, a character, or a word root.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Hallucination&lt;/strong>&lt;/td>
&lt;td>Hallucination&lt;/td>
&lt;td>The phenomenon where an LLM generates information that seems plausible but is actually false or inconsistent with the facts.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Temperature&lt;/strong>&lt;/td>
&lt;td>Temperature parameter&lt;/td>
&lt;td>A parameter controlling output randomness (usually between 0 and 1). A lower temperature makes output more deterministic and consistent, while a higher one makes it more creative and diverse.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Self-Consistency&lt;/strong>&lt;/td>
&lt;td>Self-consistency&lt;/td>
&lt;td>An advanced technique that generates multiple times (using a higher temperature) and &amp;ldquo;votes&amp;rdquo; on the results to select the most consistent answer, improving accuracy on complex reasoning tasks.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>ReAct (Reasoning and Acting)&lt;/strong>&lt;/td>
&lt;td>Reasoning and acting&lt;/td>
&lt;td>An advanced framework that lets an LLM not only reason but also perform certain &amp;ldquo;actions&amp;rdquo; (such as calling external APIs or executing code) and fold the results of those actions into the next step of reasoning.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Delimiter&lt;/strong>&lt;/td>
&lt;td>Delimiter&lt;/td>
&lt;td>Using special characters or tags (such as ```, ###, &amp;lt;tag&amp;gt;) to clearly separate different parts of a prompt (such as instructions, context, and examples).&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;hr>
&lt;h3 id="chapter-3---prompt-engineering-in-software-testing-practice">Chapter 3 - Prompt Engineering in Software Testing Practice
&lt;/h3>&lt;p>This chapter uses concrete cases to show how to apply prompt engineering at each stage of software testing.&lt;/p>
&lt;h4 id="31-case-1---generating-test-cases-from-user-stories-functional-testing">3.1 Case 1 - Generating Test Cases from User Stories (Functional Testing)
&lt;/h4>&lt;p>Suppose we have a &lt;strong>user story&lt;/strong> for an e-commerce platform: &amp;ldquo;As a logged-in user, I want to be able to add products to the shopping cart so that I can check out all at once later.&amp;rdquo;&lt;/p>
&lt;p>&lt;strong>A poor prompt 👎:&lt;/strong>&lt;/p>
&lt;blockquote>
&lt;p>Write test cases for the add-to-cart feature.&lt;/p>&lt;/blockquote>
&lt;p>This prompt is too vague and provides no context; AI may produce very generic, low-value test cases.&lt;/p>
&lt;p>&lt;strong>A good prompt (using Few-shot and role prompting) 👍:&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl"># Instructions
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">You are an experienced e-commerce software testing expert. Based on the following user story and business rules, generate a comprehensive set of functional test cases for the &amp;#34;add product to shopping cart&amp;#34; feature.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"># Role
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- You are highly detail-oriented and able to consider all kinds of boundary cases and exception scenarios.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Your test cases should include: case ID, test title, preconditions, test steps, expected result, and case type (positive/negative).
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- The output format should be a Markdown table.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"># Context - User Story
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&amp;#34;As a logged-in user, I want to be able to add products to the shopping cart so that I can check out all at once later.&amp;#34;
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"># Context - Business Rules
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">1. The user must be logged in to add products.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">2. The cart can hold at most 50 different products.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">3. The maximum purchase quantity for a single product is 99.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">4. Products that are removed from sale or have zero stock cannot be added to the cart.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">5. After a successful add, the cart icon in the upper-right corner of the page should update the product count in real time.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"># Example (Few-shot)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Here is a reference example:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| Case ID | Test Title | Preconditions | Test Steps | Expected Result | Case Type |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| :--- | :--- | :--- | :--- | :--- | :--- |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">| TC-CART-001 | Verify a logged-in user can successfully add one product to the cart | User is logged in; cart is empty | 1. Browse to a product detail page with stock available.&amp;lt;br&amp;gt;2. Click the &amp;#34;Add to Cart&amp;#34; button. | 1. The page shows &amp;#34;Product successfully added to cart&amp;#34;.&amp;lt;br&amp;gt;2. The cart icon count updates to 1. | Positive |
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"># Task
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Now, based on the above information, generate at least 10 detailed test cases for this feature, covering positive, negative, and boundary scenarios.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Possible AI output:&lt;/p>
&lt;p>AI will follow the instructions and, in the specified Markdown table format, generate a series of high-quality test cases, including verifying unlogged-in users, adding products up to the limit, adding out-of-stock products, and validating quantity input boundary values (0, 1, 99, 100).&lt;/p>
&lt;h4 id="32-case-2---generating-test-data-in-a-specific-format-data-driven-testing">3.2 Case 2 - Generating Test Data in a Specific Format (Data-Driven Testing)
&lt;/h4>&lt;p>When performing data-driven testing, we often need large amounts of data that conform to specific formats and rules.&lt;/p>
&lt;p>&lt;strong>Scenario&lt;/strong> - Testing a user registration form that has specific requirements for username, password, and email format.&lt;/p>
&lt;p>&lt;strong>A good prompt (using instructions and format specification) 👍:&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-mysql" data-lang="mysql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Role
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="n">You&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">are&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">test&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">data&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">generator&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1"># Task
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="n">Generate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">20&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">sets&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">of&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">test&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">data&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">user&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">registration&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">feature&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">and&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">output&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">them&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">in&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">CSV&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">format&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1"># Data Requirements
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="n">The&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">data&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">should&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">contain&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">three&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">columns&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="n">username&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="n">password&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="n">email&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1"># Column Definitions and Rules
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="n">username&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Must&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">be&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">6&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="mi">15&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">characters&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">May&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">contain&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">only&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">lowercase&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">letters&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">and&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">digits&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Include&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">both&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">valid&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">and&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">invalid&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">usernames&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">example&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">too&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">short&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">too&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">long&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">or&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">containing&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">special&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">characters&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="n">password&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Must&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">be&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">8&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="mi">20&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">characters&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Must&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">contain&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">at&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">least&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">one&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">uppercase&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">letter&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">one&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">lowercase&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">letter&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">one&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">digit&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">and&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">one&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">special&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">character&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="o">!@&lt;/span>&lt;span class="c1">#$%^&amp;amp;*).
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Include&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">strong&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">passwords&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">that&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">comply&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">with&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">rules&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">and&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">weak&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">passwords&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">that&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">do&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">not&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="mi">3&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="n">email&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Must&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">be&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">in&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">valid&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">email&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">format&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">*&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Include&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">some&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">common&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">email&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">providers&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">such&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">as&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">gmail&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">com&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">outlook&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">com&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">yahoo&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">com&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">as&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">well&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">as&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">some&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">invalid&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="n">format&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">emails&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">example&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">missing&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">@&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">symbol&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">or&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">having&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">an&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">invalid&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">domain&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1"># Output Format
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="n">Please&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">strictly&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">follow&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">CSV&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">format&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">below&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">including&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">header&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="o">```&lt;/span>&lt;span class="n">csv&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">username&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="n">password&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="n">email&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>&lt;strong>Possible AI output:&lt;/strong>
AI will generate a text block in CSV format containing 20 rows of data that mix valid data with deliberately constructed invalid data, ready to be used directly in automated test scripts or manual testing.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-csv" data-lang="csv">&lt;span class="line">&lt;span class="cl">&lt;span class="s">username&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s">password&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s">email&lt;/span>&lt;span class="p">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&lt;/span>&lt;span class="s">validuser1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s">ValidPass1!&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s">test.user1@gmail.com&lt;/span>&lt;span class="p">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&lt;/span>&lt;span class="s">short&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s">WeakPass1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s">test.user2@outlook.com&lt;/span>&lt;span class="p">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&lt;/span>&lt;span class="s">toolongusername123&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s">AnotherGoodP@ss&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s">test.user3@yahoo.com&lt;/span>&lt;span class="p">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&lt;/span>&lt;span class="s">invalid-user&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s">Weak1&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s">invalid-email&lt;/span>&lt;span class="p">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&lt;/span>&lt;span class="s">user.123&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s">StrongerP@ssword123&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="s">test.user4@gmail.com&lt;/span>&lt;span class="p">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">&lt;/span>&lt;span class="s">... (and so on)&lt;/span>&lt;span class="p">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h4 id="33-case-3---assisting-in-writing-automation-test-scripts-test-automation">3.3 Case 3 - Assisting in Writing Automation Test Scripts (Test Automation)
&lt;/h4>&lt;p>For test automation engineers, AI can become a powerful programming assistant.&lt;/p>
&lt;p>&lt;strong>Scenario&lt;/strong> - You need to write an automated test script using Selenium and Python for the &amp;ldquo;add to cart&amp;rdquo; feature mentioned earlier.&lt;/p>
&lt;p>&lt;strong>A good prompt (using chain-of-thought and code generation) 👍:&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl"># Role
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">You are a senior test automation engineer, proficient in Python and Selenium WebDriver.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"># Task
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">For the test scenario &amp;#34;Verify a logged-in user can successfully add one product to the cart&amp;#34;, write a complete, executable Python Selenium automation test script.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"># Instructions and Thought Process (Chain-of-Thought)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Let&amp;#39;s complete this task step by step:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">1. **Set up the environment**: Import the necessary Selenium libraries, initialize the WebDriver (use the Chrome browser), and set an implicit wait.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">2. **Login operation**: First, write a function `login(username, password)` that navigates to the login page, enters the username and password, and then clicks the login button. Use ID selectors to locate elements.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">3. **Navigate to the product page**: After logging in, navigate to a specific product page. Assume the product page URL is &amp;#34;[http://example.com/product/123](http://example.com/product/123)&amp;#34;.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">4. **Perform the add operation**: Locate the &amp;#34;Add to Cart&amp;#34; button (assume its ID is `add-to-cart-button`) and click it.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">5. **Assertion verification**:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> * Add an explicit wait for the success message to appear (assume its CSS selector is `.success-message`).
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> * Get the text of that message and assert that its content is &amp;#34;Product successfully added to cart&amp;#34;.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> * Get the text of the count element next to the cart icon (assume its ID is `cart-item-count`) and assert that its value is &amp;#34;1&amp;#34;.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">6. **Cleanup**: Finally, close the browser with `driver.quit()`.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">7. **Code structure**: Wrap all operations in a main function or test class, and add comments to explain the key steps.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"># Please output the complete Python code.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Possible AI output:&lt;/p>
&lt;p>Based on this detailed, step-by-step instruction, AI will generate a well-structured, fully commented Python Selenium script containing all the necessary operations and assertions. This approach is far more efficient and accurate than a simple request such as &amp;ldquo;write me a Selenium script&amp;rdquo;.&lt;/p>
&lt;hr>
&lt;h3 id="chapter-4---advanced-prompt-engineering-techniques">Chapter 4 - Advanced Prompt Engineering Techniques
&lt;/h3>&lt;p>Once you have mastered the basics, you can apply more advanced techniques to tackle complex testing challenges.&lt;/p>
&lt;h4 id="41-deeper-applications-of-chain-of-thought-cot">4.1 Deeper Applications of Chain-of-Thought (CoT)
&lt;/h4>&lt;p>For tasks requiring complex logical reasoning, such as &lt;strong>Root Cause Analysis&lt;/strong>, deepening the application of CoT is crucial.&lt;/p>
&lt;p>&lt;strong>Scenario&lt;/strong> - An API test fails, returning a 500 error, and you need to analyze the possible causes.&lt;/p>
&lt;p>&lt;strong>Prompt:&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-mysql" data-lang="mysql">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Role
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="n">You&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">are&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">top&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="n">tier&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Site&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Reliability&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">Engineer&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">SRE&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">diagnosing&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">an&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">API&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">failure&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1"># Context
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="n">API&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">endpoint&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`/&lt;/span>&lt;span class="n">api&lt;/span>&lt;span class="o">/&lt;/span>&lt;span class="n">v1&lt;/span>&lt;span class="o">/&lt;/span>&lt;span class="n">users&lt;/span>&lt;span class="o">/&lt;/span>&lt;span class="err">{&lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="err">}&lt;/span>&lt;span class="o">/&lt;/span>&lt;span class="n">profile&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="n">Problem&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">During&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">high&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="n">concurrency&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">load&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">testing&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">this&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">endpoint&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">occasionally&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">returns&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">an&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">HTTP&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">500&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Internal&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Server&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Error&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="n">Log&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">snippet&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">```&lt;/span>&lt;span class="n">log&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">ERROR&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Connection&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">pool&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">exhausted&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Could&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">not&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">get&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">connection&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">from&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">pool&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="p">...&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">Caused&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">by&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">java&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="k">sql&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">SQLTransientConnectionException&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">HikariPool&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Connection&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">is&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">not&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">available&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">request&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">timed&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">out&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">after&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">30000&lt;/span>&lt;span class="n">ms&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1"># Task
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">Please&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">use&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;chain-of-thought&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">method&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">to&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">analyze&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">potential&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">root&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">causes&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">of&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">this&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">problem&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">step&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">by&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">step&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">and&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">each&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">cause&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">propose&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">concrete&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">investigation&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">steps&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">and&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">solution&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">recommendations&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Think&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">like&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">an&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">expert&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">and&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">analyze&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">from&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">multiple&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">layers&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">application&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">layer&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">database&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">layer&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">configuration&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">layer&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="n">Thinking&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">begins&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="n">Log&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">analysis&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">The&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">log&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">explicitly&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">states&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;Connection pool exhausted&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">database&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">connection&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">pool&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">is&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">exhausted&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">This&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">is&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">most&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">direct&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">clue&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="n">Why&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">is&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">connection&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">pool&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">exhausted&lt;/span>&lt;span class="o">?**&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="n">Cause&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">A&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Connections&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">are&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">not&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">released&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">Is&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">there&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">logic&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">branch&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">in&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">application&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">code&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">that&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">does&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">not&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">properly&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">close&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">connection&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="n">connection&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nf">close&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">after&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">querying&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">database&lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="n">Cause&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">B&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">The&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">connection&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">pool&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">is&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">too&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">small&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">Is&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="n">maximumPoolSize&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">configuration&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">of&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="n">HikariCP&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">set&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">too&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">low&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">current&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">concurrent&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">load&lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="n">Cause&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">C&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">The&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">queries&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">themselves&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">are&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">too&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">slow&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Are&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">there&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">slow&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">queries&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">that&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">hold&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">connections&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">long&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">time&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">rapidly&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">exhausting&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">pool&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">under&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">high&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">concurrency&lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="n">Cause&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">D&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">A&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">database&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">performance&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">bottleneck&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Has&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">database&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">server&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">itself&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">hit&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">CPU&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">memory&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">or&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">I&lt;/span>&lt;span class="o">/&lt;/span>&lt;span class="n">O&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">bottleneck&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">causing&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">queries&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">to&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">respond&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">slowly&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">and&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">indirectly&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">exhausting&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">connection&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">pool&lt;/span>&lt;span class="o">?&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="mi">3&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="n">How&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">to&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">investigate&lt;/span>&lt;span class="o">?**&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="k">For&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Cause&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">A&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Review&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">all&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">code&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">paths&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">that&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">handle&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`/&lt;/span>&lt;span class="n">api&lt;/span>&lt;span class="o">/&lt;/span>&lt;span class="n">v1&lt;/span>&lt;span class="o">/&lt;/span>&lt;span class="n">users&lt;/span>&lt;span class="o">/&lt;/span>&lt;span class="err">{&lt;/span>&lt;span class="n">userId&lt;/span>&lt;span class="err">}&lt;/span>&lt;span class="o">/&lt;/span>&lt;span class="n">profile&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">requests&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">especially&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">exception&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="n">handling&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">blocks&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">to&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ensure&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">connections&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">are&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">properly&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">closed&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">in&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="n">finally&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">blocks&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="k">For&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Cause&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">B&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">Check&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">application&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">configuration&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">files&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">such&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">as&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="n">application&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">properties&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">or&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="n">yml&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">for&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">value&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">of&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="n">spring&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">datasource&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">hikari&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="n">maximum&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="n">pool&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="n">size&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Monitor&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">real&lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="kt">time&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">connection&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">pool&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">usage&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="k">For&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Cause&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">C&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Enable&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">database&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">slow&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">query&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">log&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">and&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">analyze&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">whether&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">there&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">are&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">slow&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">query&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">records&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">at&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kt">time&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">problem&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">occurred&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Run&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="k">EXPLAIN&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">ANALYZE&lt;/span>&lt;span class="o">`&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">on&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">SQL&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">statements&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">involved&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">in&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">this&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">API&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="k">For&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Cause&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">D&lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">Check&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">database&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">server&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">monitoring&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">dashboard&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">CPU&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">usage&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">memory&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">disk&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">I&lt;/span>&lt;span class="o">/&lt;/span>&lt;span class="n">O&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">active&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">connections&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="mi">4&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">**&lt;/span>&lt;span class="n">Solution&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">recommendations&lt;/span>&lt;span class="o">?**&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="o">-&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">...&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1"># Output
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">Based&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">on&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">chain&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">of&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">thought&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">above&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">organize&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">it&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">into&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">formal&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">incident&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">analysis&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">report&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>This kind of CoT prompt not only guides AI to a conclusion but, more importantly, forces it to display a structured, logically clear analysis process—something extremely valuable for complex diagnostic tasks.&lt;/p>
&lt;h4 id="42-self-consistency-for-exploratory-testing">4.2 Self-Consistency for Exploratory Testing
&lt;/h4>&lt;p>In &lt;strong>exploratory testing&lt;/strong>, which demands creative and divergent thinking, you can leverage &lt;code>Self-Consistency&lt;/code> to generate a more diverse set of testing ideas.&lt;/p>
&lt;p>&lt;strong>Scenario&lt;/strong> - Designing exploratory testing ideas for a new &amp;ldquo;online document collaboration&amp;rdquo; feature.&lt;/p>
&lt;p>&lt;strong>Prompt:&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-mysql" data-lang="mysql">&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1"># Role
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="n">You&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">are&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">highly&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">creative&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">and&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">destructive&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">software&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">tester&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">skilled&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">at&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">finding&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">bugs&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">that&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">users&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">never&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">expect&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1"># Task
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="k">For&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;real-time online document collaboration&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">feature&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">generate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">5&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">different&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">creative&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">exploratory&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">testing&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">ideas&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">charters&lt;/span>&lt;span class="p">).&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">What&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">I&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">need&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">are&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">diverse&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">unconventional&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ideas&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="c1"># Instructions
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1">&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="mi">1&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">I&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">will&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">run&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">this&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">prompt&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">multiple&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">times&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="mi">2&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Please&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">think&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">about&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">and&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">generate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="mi">5&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">testing&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ideas&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">focusing&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">on&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">concurrent&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">operations&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">network&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">latency&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">data&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">conflicts&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">and&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">unconventional&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">user&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">interactions&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="mi">3&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Please&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">output&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">in&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">form&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">of&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">a&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">bulleted&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">list&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">You&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">can&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">turn&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">up&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">the&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">model&lt;/span>&lt;span class="s1">&amp;#39;s `temperature` parameter, for example to 0.8, and then run this prompt multiple times)
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>&lt;strong>Possible output for Run 1:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Simulate disconnect and reconnect&lt;/strong>: Two users edit simultaneously; one suddenly loses connectivity, makes a large number of changes, and then reconnects—observe how the data merges.&lt;/li>
&lt;li>&lt;strong>Frantic cursor movement&lt;/strong>: Multiple users furiously type, delete, and move cursors on the same line, testing rendering performance and synchronization accuracy.&lt;/li>
&lt;li>&amp;hellip;&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Possible output for Run 2:&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Dynamic permission change&lt;/strong>: While one user is editing, an administrator suddenly downgrades their permission from &amp;ldquo;editable&amp;rdquo; to &amp;ldquo;read-only&amp;rdquo;—observe the behavior of their client.&lt;/li>
&lt;li>&lt;strong>Mixing rich text and plain text&lt;/strong>: One user pastes complex rich text (with formatting and images) while another simultaneously types plain text nearby—check whether the formatting gets scrambled.&lt;/li>
&lt;li>&amp;hellip;&lt;/li>
&lt;/ul>
&lt;p>By generating multiple times and synthesizing all the unique ideas, testers can obtain an exploratory testing checklist far richer and more comprehensive than what a single request would yield.&lt;/p>
&lt;hr>
&lt;h3 id="chapter-5---summary-and-outlook">Chapter 5 - Summary and Outlook
&lt;/h3>&lt;p>Prompt engineering is rapidly becoming one of the core competencies of software test engineers. It is not meant to replace testers&amp;rsquo; thinking, but to augment their capabilities, freeing them from repetitive labor so they can take on tasks that demand greater wisdom and insight.&lt;/p>
&lt;p>&lt;strong>The key to success lies in practice&lt;/strong>. Starting today, try applying the techniques introduced in this article to your daily work. Begin with small tasks—for example, having AI polish a defect report for you, or brainstorming some edge cases for the feature you are currently testing. As your understanding of the model&amp;rsquo;s &amp;ldquo;temperament&amp;rdquo; deepens, you will be able to build increasingly powerful prompts, truly achieving efficient collaboration with AI and lifting the efficiency and quality of software testing to an entirely new level.&lt;/p>
&lt;p>The future of software testing will be an era of deep integration between human wisdom and artificial intelligence—and prompt engineering is precisely the key that opens this door.&lt;/p>
&lt;hr></description></item><item><title>A Prompt-Writing Framework for Test Engineers to Use Large AI Models Effectively</title><link>https://chengxiaqiucao.github.io/en/post/079-%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E6%8F%90%E7%A4%BA%E8%AF%8D/</link><pubDate>Wed, 16 Apr 2025 00:00:00 +0000</pubDate><guid>https://chengxiaqiucao.github.io/en/post/079-%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%E6%8F%90%E7%A4%BA%E8%AF%8D/</guid><description>&lt;h2 id="preface">Preface
&lt;/h2>&lt;p>With the widespread application of large AI models in software testing, prompt engineering has become a key skill for test engineers to improve efficiency. Through precise prompt design, we can quickly generate test cases, optimize test scenarios, generate automation scripts, and even achieve intelligent test coverage.&lt;/p>
&lt;p>So how can we use large models more effectively and have them help us reach the desired results more efficiently? Good prompts let us achieve twice the result with half the effort. The following summarizes, for test engineers, how to write a good prompt framework.&lt;/p>
&lt;h2 id="breaking-down-complex-requirements-and-describing-problems-precisely">Breaking Down Complex Requirements and Describing Problems Precisely
&lt;/h2>&lt;p>The effectiveness of large AI models depends heavily on the clarity of the input prompt, that is, on minimizing ambiguity as much as possible. So when entering a prompt, you should break complex tasks down into concrete requirements as much as possible, for example:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Scenario-based descriptions&lt;/strong>: specify the test objective (e.g., &amp;ldquo;generate boundary-value test cases for the login function&amp;rdquo;) rather than a vague instruction (e.g., &amp;ldquo;help me write test cases&amp;rdquo;).&lt;/li>
&lt;li>&lt;strong>Constraints&lt;/strong>: add format requirements (e.g., &amp;ldquo;output in table form&amp;rdquo;), priorities (e.g., &amp;ldquo;include only high-risk scenarios&amp;rdquo;), or technical limitations (e.g., &amp;ldquo;no third-party APIs involved&amp;rdquo;).&lt;/li>
&lt;li>&lt;strong>Example guidance&lt;/strong>: provide sample data or templates to help the model understand the expected output structure.&lt;/li>
&lt;/ul>
&lt;h2 id="using-a-structured-framework-to-improve-output-stability">Using a Structured Framework to Improve Output Stability
&lt;/h2>&lt;p>By defining a structured prompt framework, you can constrain model behavior and reduce random interference:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Role setting&lt;/strong>: specify a professional role for the model to play (e.g., &amp;ldquo;you are a senior testing expert skilled at designing high-coverage test scenarios&amp;rdquo;).&lt;/li>
&lt;li>&lt;strong>Step-by-step instructions&lt;/strong>: break a complex task into multiple steps (e.g., &amp;ldquo;Step 1: analyze the requirements document; Step 2: identify critical paths; Step 3: generate cases&amp;rdquo;).&lt;/li>
&lt;li>&lt;strong>Chain-of-Thought&lt;/strong>: although many models now offer deep-thinking capabilities, guiding the model&amp;rsquo;s analysis through prompts can simplify the direction of its reasoning. For example, &amp;ldquo;first analyze the user operation flow, then focus on generating test cases for exception scenarios&amp;rdquo;.&lt;/li>
&lt;/ol>
&lt;h2 id="progressive-iterative-optimization-and-continuous-prompt-improvement">Progressive Iterative Optimization and Continuous Prompt Improvement
&lt;/h2>&lt;p>Large models usually retain conversation context; for the result of each round of feedback, you should keep correcting and gradually move toward the best output.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Feedback correction&lt;/strong>: promptly point out errors in the model&amp;rsquo;s output (e.g., &amp;ldquo;case 2 does not cover the timeout scenario, please add it&amp;rdquo;) and ask for regeneration.&lt;/li>
&lt;li>&lt;strong>Parameter tuning&lt;/strong>: control output length (e.g., &amp;ldquo;describe in 50 characters or less&amp;rdquo;) and the Temperature coefficient to balance the model&amp;rsquo;s creativity and accuracy.&lt;/li>
&lt;li>&lt;strong>Cross-comparison&lt;/strong>: there are many open large models today with varying capabilities, and their analysis results can differ considerably. Judge comprehensively and extract the best result.&lt;/li>
&lt;/ul>
&lt;p>Some common correction scenarios:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;strong>Problem&lt;/strong>&lt;/th>
&lt;th>&lt;strong>Cause&lt;/strong>&lt;/th>
&lt;th>&lt;strong>Improvement&lt;/strong>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Output too broad&lt;/td>
&lt;td>Vague requirement description&lt;/td>
&lt;td>Add specific scenarios, format, and priority constraints&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Repeated or redundant results&lt;/td>
&lt;td>Output scope not clearly limited&lt;/td>
&lt;td>Exclude unwanted scenarios (e.g., specify &amp;ldquo;output only uncovered boundary-value scenarios&amp;rdquo;)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Incorrect technical terminology&lt;/td>
&lt;td>Model lacks domain knowledge&lt;/td>
&lt;td>Provide a glossary or specify a role (e.g., &amp;ldquo;financial systems testing expert&amp;rdquo;)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="case-study">Case Study
&lt;/h2>&lt;p>Based on the principles above, taking the shopping flow of the website &lt;a class="link" href="https://www.saucedemo.com" target="_blank" rel="noopener"
>https://www.saucedemo.com&lt;/a> that we want to test as an example, to use a large model to help us generate a series of test cases, the prompt framework can be set up as follows:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;span class="lnt">46
&lt;/span>&lt;span class="lnt">47
&lt;/span>&lt;span class="lnt">48
&lt;/span>&lt;span class="lnt">49
&lt;/span>&lt;span class="lnt">50
&lt;/span>&lt;span class="lnt">51
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">Assume you are an experienced software test engineer responsible for end-to-end functional testing of the core shopping flow of the e-commerce website https://www.saucedemo.com/
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Task: Generate detailed, high-priority positive and negative test cases for the following user scenarios. Focus on the complete flow from product selection to a successful order.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Site under test: https://www.saucedemo.com/
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Test user credentials:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">• Standard User: standard_user / secret_sauce
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">• Problem User: problem_user / secret_sauce (used to observe specific erroneous behavior)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Core shopping flow steps:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">1. User login
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">2. Browse the product list (Inventory Page)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">3. Select at least two different products and add them to the cart
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">4. View the cart (Cart Page)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">5. On the cart page, verify product information (name, quantity, price) and the total price
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">6. Enter the checkout information page (Checkout: Your Information)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">7. Fill in valid checkout information (first name, last name, postal code)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">8. Enter the checkout overview page (Checkout: Overview)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">9. On the overview page, verify product information and the total price (including tax)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">10. Complete the purchase (Checkout: Complete!)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">11. Verify the order success message
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Test case requirements:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">• Positive test cases: cover every step of a successful shopping flow using the standard user, ensuring the functionality works as expected.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">• Negative test cases:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> • Attempt to enter invalid data on the checkout information page (for example, empty or malformed first name, last name, or postal code).
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> • Attempt to check out when the cart is empty.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> • (Optional) Log in with problem_user to observe and record any abnormal behavior in the shopping flow, especially product images, adding to cart, or the checkout step.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Output requirements:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">• Each test case should include: Case ID (TC_SAUCE_SHOP_XXX), Test Description, Preconditions (e.g., logged in with products added), Test Steps (clear and executable), Expected Result, Actual Result (left blank), Status (left blank), and Priority (High/Medium/Low).
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">• Prioritize generating high-priority test cases.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Output format: Output the test cases as a Markdown table containing the following columns: Case ID, Test Description, Preconditions, Test Steps, Expected Result, Priority.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Constraints:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">• Assume a tax rate of 8%.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">• Focus on the correctness of UI element interactions and page navigation.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">• If you are unsure about the ID or Class of certain elements, use a generic description, for example &amp;#34;click the Add to Cart button&amp;#34; or &amp;#34;enter the name field&amp;#34;.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>The prompt above maps fairly well to the relevant prompt framework principles:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Clear role&lt;/strong>: &amp;ldquo;Assume you are an experienced software test engineer&amp;hellip;&amp;rdquo;&lt;/li>
&lt;li>&lt;strong>Clear task&lt;/strong>: &amp;ldquo;Generate detailed, high-priority positive and negative test cases for the following user scenarios. Focus on the complete flow from product selection to a successful order&amp;rdquo;&lt;/li>
&lt;li>&lt;strong>Sufficient contextual information&lt;/strong>: the URL under test, user information, case focus, and tax rate assumptions&lt;/li>
&lt;li>&lt;strong>Specified output format&lt;/strong>: &amp;ldquo;Output the test cases as a Markdown table containing the following columns: &lt;code>Case ID&lt;/code>, &lt;code>Test Description&lt;/code>, &lt;code>Preconditions&lt;/code>, &lt;code>Test Steps&lt;/code>, &lt;code>Expected Result&lt;/code>, &lt;code>Priority&lt;/code>.&amp;rdquo;&lt;/li>
&lt;li>&lt;strong>Clear specific requirements and constraints&lt;/strong>: the specific requirements for cases and output,&lt;/li>
&lt;li>&lt;strong>Guiding the direction of thinking&lt;/strong>: using problem_user to generate exception cases&lt;/li>
&lt;/ul>
&lt;p>Finally, with such a prompt, through Deepseek we obtain the following set of generated test cases:&lt;/p>
&lt;h3 id="high-priority-core-shopping-flow-test-cases">High-Priority Core Shopping Flow Test Cases
&lt;/h3>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Case ID&lt;/th>
&lt;th>Test Description&lt;/th>
&lt;th>Preconditions&lt;/th>
&lt;th>Test Steps&lt;/th>
&lt;th>Expected Result&lt;/th>
&lt;th>Priority&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Positive Test Cases&lt;/strong>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>TC_SAUCE_SHOP_001&lt;/td>
&lt;td>Standard user logs in successfully and enters the product list page&lt;/td>
&lt;td>None&lt;/td>
&lt;td>1. Visit &lt;code>https://www.saucedemo.com/&lt;/code> &lt;br>2. Enter username &lt;code>standard_user&lt;/code> and password &lt;code>secret_sauce&lt;/code> &lt;br>3. Click the login button&lt;/td>
&lt;td>Login succeeds, redirecting to the product list page (Inventory Page)&lt;/td>
&lt;td>High&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>TC_SAUCE_SHOP_002&lt;/td>
&lt;td>Add two different products to the cart and verify the quantity&lt;/td>
&lt;td>User logged in&lt;/td>
&lt;td>1. On the product list page, select two different products and click the &amp;ldquo;Add to Cart&amp;rdquo; button for each &lt;br>2. Check that the cart icon shows a quantity of 2&lt;/td>
&lt;td>The cart icon quantity updates to 2, and both products appear on the cart page&lt;/td>
&lt;td>High&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>TC_SAUCE_SHOP_003&lt;/td>
&lt;td>Verify product information and total price (excluding tax) on the cart page&lt;/td>
&lt;td>User has added two products to the cart&lt;/td>
&lt;td>1. Click the cart icon to enter the cart page &lt;br>2. Check the product name, quantity, and unit price &lt;br>3. Calculate the total price (product 1 price + product 2 price)&lt;/td>
&lt;td>Product information is correct, and the total price shows the sum of the two products&lt;/td>
&lt;td>High&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>TC_SAUCE_SHOP_004&lt;/td>
&lt;td>Complete valid checkout information and verify the tax-inclusive total&lt;/td>
&lt;td>User has entered the checkout information page&lt;/td>
&lt;td>1. On the checkout information page, enter a valid first name, last name, and postal code (e.g., John/Doe/12345) &lt;br>2. Click the &amp;ldquo;Continue&amp;rdquo; button &lt;br>3. On the overview page, verify the total price (total = product total * 1.08)&lt;/td>
&lt;td>Redirected to the checkout overview page, total includes 8% tax and is calculated correctly&lt;/td>
&lt;td>High&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>TC_SAUCE_SHOP_005&lt;/td>
&lt;td>Complete the purchase and verify the order success message&lt;/td>
&lt;td>User has entered the checkout overview page&lt;/td>
&lt;td>1. Click the &amp;ldquo;Finish&amp;rdquo; button&lt;/td>
&lt;td>Displays the &amp;ldquo;THANK YOU FOR YOUR ORDER&amp;rdquo; success message and returns to the product list page&lt;/td>
&lt;td>High&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Negative Test Cases&lt;/strong>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>TC_SAUCE_SHOP_006&lt;/td>
&lt;td>Submit the form with an empty name on the checkout information page&lt;/td>
&lt;td>User has entered the checkout information page&lt;/td>
&lt;td>1. Leave the name field blank and enter a valid postal code (e.g., 12345) &lt;br>2. Click the &amp;ldquo;Continue&amp;rdquo; button&lt;/td>
&lt;td>Shows &amp;ldquo;First Name is required&amp;rdquo; and blocks navigation&lt;/td>
&lt;td>High&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>TC_SAUCE_SHOP_007&lt;/td>
&lt;td>Invalid postal code format on the checkout information page (e.g., non-numeric)&lt;/td>
&lt;td>User has entered the checkout information page&lt;/td>
&lt;td>1. Enter a valid first name and last name, with postal code &amp;ldquo;ABC12&amp;rdquo; &lt;br>2. Click the &amp;ldquo;Continue&amp;rdquo; button&lt;/td>
&lt;td>Shows &amp;ldquo;Postal Code is invalid&amp;rdquo; and blocks navigation&lt;/td>
&lt;td>High&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>TC_SAUCE_SHOP_008&lt;/td>
&lt;td>Attempt to check out with an empty cart&lt;/td>
&lt;td>User logged in with an empty cart&lt;/td>
&lt;td>1. Click the cart icon to enter the cart page &lt;br>2. Click the &amp;ldquo;Checkout&amp;rdquo; button&lt;/td>
&lt;td>Shows &amp;ldquo;Cart is empty&amp;rdquo; or blocks navigation to the checkout page&lt;/td>
&lt;td>High&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Problem User Test Cases&lt;/strong>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;td>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>TC_SAUCE_SHOP_009&lt;/td>
&lt;td>Problem User shows abnormal product images when adding products&lt;/td>
&lt;td>Problem User logged in&lt;/td>
&lt;td>1. Browse the product list page &lt;br>2. Check whether product images load correctly (e.g., misplaced or failing to display)&lt;/td>
&lt;td>Product images display abnormally (e.g., blank or wrong images)&lt;/td>
&lt;td>Medium&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>TC_SAUCE_SHOP_010&lt;/td>
&lt;td>Problem User total price calculation error at checkout&lt;/td>
&lt;td>Problem User has added products to the cart&lt;/td>
&lt;td>1. Complete the checkout flow up to the overview page &lt;br>2. Verify whether the total equals product total * 1.08&lt;/td>
&lt;td>Total price calculation error (e.g., tax not included or deviated value)&lt;/td>
&lt;td>Medium&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h4 id="supplementary-notes">&lt;strong>Supplementary Notes&lt;/strong>
&lt;/h4>&lt;ol>
&lt;li>&lt;strong>Priority assignment&lt;/strong>: core flows (login, adding products, checkout) and key exception scenarios (empty fields, invalid data) are set to high priority.&lt;/li>
&lt;li>&lt;strong>Problem User&lt;/strong>: used to verify specific abnormal behaviors (such as UI rendering errors or logic flaws).&lt;/li>
&lt;li>&lt;strong>Actual Result/Status&lt;/strong>: to be filled in based on actual observations during execution (such as &amp;ldquo;Pass&amp;rdquo;, &amp;ldquo;Fail&amp;rdquo;, or &amp;ldquo;Blocked&amp;rdquo;).&lt;/li>
&lt;li>&lt;strong>Tax calculation&lt;/strong>: assuming the product total is &lt;code>$X&lt;/code>, the tax-inclusive total should be &lt;code>X * 1.08&lt;/code>, rounded to two decimal places (e.g., &lt;code>$21.99 * 1.08 = $23.75&lt;/code>).&lt;/li>
&lt;/ol></description></item><item><title>The Hidden Concerns Behind the MCP Boom</title><link>https://chengxiaqiucao.github.io/en/post/076-mcp%E5%A4%A7%E6%B5%81%E8%A1%8C%E8%83%8C%E5%90%8E%E7%9A%84%E9%9A%90%E5%BF%A7/</link><pubDate>Mon, 14 Apr 2025 15:28:24 +0800</pubDate><guid>https://chengxiaqiucao.github.io/en/post/076-mcp%E5%A4%A7%E6%B5%81%E8%A1%8C%E8%83%8C%E5%90%8E%E7%9A%84%E9%9A%90%E5%BF%A7/</guid><description>&lt;p>Over the past few weeks, the Model Context Protocol (MCP) has rapidly emerged as the de facto standard for connecting third-party data and tools to LLM-based conversational systems. In a short time, the internet has been flooded with all kinds of flashy application cases, and the room for imagination is enormous. Yet behind this protocol there also lurk some subtle security risks and functional limitations.&lt;/p>
&lt;h1 id="background">Background
&lt;/h1>&lt;p>The essence of MCP is to act as a bridge for building an &amp;ldquo;intelligent assistant plugin ecosystem&amp;rdquo;, allowing users to provide local extension capabilities to various large models and AI clients that support the MCP protocol, so that these LLM-based intelligent interfaces can perform non-text operations through MCP&amp;rsquo;s &amp;ldquo;tool calls&amp;rdquo;. The MCP protocol in effect standardizes the way LLMs interface with local data and tools.&lt;/p>
&lt;p>For example, in the previous article, we simply told the large model in &lt;code> Cursor&lt;/code>: &lt;em>&amp;ldquo;Visit the &lt;a class="link" href="https://www.saucedemo.com" target="_blank" rel="noopener"
>www.saucedemo.com&lt;/a> website, log in with problem_user, verify the complete workflow of the site, and record any issues found&amp;rdquo;&lt;/em> , and Cursor then used the &lt;code>playwright-mcp&lt;/code> MCP server to call the &lt;code>playwright&lt;/code> framework to carry out a series of activities such as launching the browser, visiting, browsing, testing, and recording issues—completing testing activities similar to those of a manual test engineer&lt;/p>
&lt;p>So through MCP, its core value is that it breaks through the original role of large AI models as text-based advisory assistants and turns them into actual executors, better able to directly operate local tools and data, providing large models with a universal socket.&lt;/p>
&lt;h1 id="the-potential-hidden-concerns">The Potential Hidden Concerns
&lt;/h1>&lt;p>But while we recognize MCP&amp;rsquo;s enormous potential, we must also see that MCP, as a foundational protocol that has only recently gotten started, is far from perfect, and there are still the following hidden concerns:&lt;/p>
&lt;h2 id="hidden-concern-1---security-of-the-protocol-itself">&lt;strong>Hidden Concern 1 - Security of the Protocol Itself&lt;/strong>
&lt;/h2>&lt;h3 id="authentication-mechanisms">&lt;strong>Authentication Mechanisms&lt;/strong>
&lt;/h3>&lt;p>The initial version of MCP did not define an authentication specification, leaving each MCP server to do as it pleased—from cumbersome verification to sensitive data being left completely exposed, a veritable chaos. Although authentication schemes were introduced later, their implementation complexity has sparked new controversy.&lt;/p>
&lt;h3 id="the-risk-of-local-malicious-code-execution">&lt;strong>The Risk of Local Malicious Code Execution&lt;/strong>
&lt;/h3>&lt;p>The protocol supports running MCP servers via standard input/output, which, while lowering the barrier to use, also provides a breeding ground for the spread of malicious code. If a non-technical user runs third-party malicious MCP code and causes a local device security failure, this has become a new attack vector.&lt;/p>
&lt;h3 id="mcp">&lt;strong>MCP&amp;rsquo;s Trust in User Input&lt;/strong>
&lt;/h3>&lt;p>Many MCP servers directly execute user input instructions. When user intent is translated by the LLM and takes effect on the system, traditional security models face a severe challenge: the boundary between user input instructions and attacks on the system is no longer clear.&lt;/p>
&lt;h2 id="hidden-concern-2---limitations-in-interaction-design">&lt;strong>Hidden Concern 2 - Limitations in Interaction Design&lt;/strong>
&lt;/h2>&lt;p>The MCP protocol is oriented more toward LLM interaction, but for users, the interaction is hardly easy to use or friendly.&lt;/p>
&lt;h3 id="the-lack-of-risk-grading-for-different-levels-of-operations">&lt;strong>The Lack of Risk Grading for Different Levels of Operations&lt;/strong>
&lt;/h3>&lt;p>Many assistant tools provide a global operation-confirmation mechanism, but the &amp;ldquo;auto-confirm&amp;rdquo; habit formed around many harmless tools often leads to serious misoperations, such as the deletion of important local files or sending emails by mistake.&lt;/p>
&lt;h3 id="cost-control-capability">&lt;strong>Cost Control Capability&lt;/strong>
&lt;/h3>&lt;p>Unlike traditional protocols, in LLM scenarios different volumes of returned tokens incur varying costs, and the cost of serving users depends heavily on the token efficiency of MCP tools, yet the current protocol has no limit on return length to strengthen cost control.&lt;/p>
&lt;h3 id="sacrificing-the-advantages-of-structured-data">&lt;strong>Sacrificing the Advantages of Structured Data&lt;/strong>
&lt;/h3>&lt;p>To accommodate LLM preferences, MCP tends to adopt human-readable formats such as plain text / images / audio clips for transmission, sacrificing the advantages of structured data. For services such as maps or Didi-style ride-hailing, which need to ensure location accuracy, trip-detail feedback, and real-time status updates, the current protocol is hardly up to the task. Solving such problems for now still requires some workaround designs at the tool layer.&lt;/p>
&lt;hr>
&lt;h2 id="hidden-concern-3---llm-security">&lt;strong>Hidden Concern 3 - LLM Security&lt;/strong>
&lt;/h2>&lt;p>The discussion around the security of large models themselves is still unresolved, and introducing MCP to connect more data and tools makes this problem even more prominent.&lt;/p>
&lt;h3 id="mcp-makes-prompt-injection-more-powerful">&lt;strong>MCP Makes Prompt Injection More Powerful&lt;/strong>
&lt;/h3>&lt;p>LLMs usually have two layers of instructions: &lt;strong>system-level prompts&lt;/strong> (which control the assistant&amp;rsquo;s behavior and policies) and &lt;strong>user-level prompts&lt;/strong> (provided by the user). Usually, when &lt;strong>prompt injection&lt;/strong> was mentioned in the past, it referred to malicious user input. A fairly significant vulnerability of the MCP model is that it allows tools provided by third parties to be trusted as part of the assistant&amp;rsquo;s system-level prompt, thereby granting them greater privileges to override the agent&amp;rsquo;s behavior.&lt;/p>
&lt;h3 id="sensitive-data-leakage">&lt;strong>Sensitive Data Leakage&lt;/strong>
&lt;/h3>&lt;p>Beyond malicious hijacking via malicious tools, MCP can also cause users to leak sensitive data unintentionally. Even if a user strictly confirms every operation, data may still be exfiltrated in a &amp;ldquo;reasonable&amp;rdquo; way. For example, with your instruction: &amp;ldquo;Explain my personal medical records to me&amp;rdquo;, the assistant may launch a medical-retrieval multi-tenant MCP tool and leak your private personal information to the service provider.&lt;/p>
&lt;p>MCP servers can also easily hijack or alter user intent through disguised prompts and their actual tool implementations.&lt;/p>
&lt;h2 id="hidden-concern-4---breaking-traditional-enterprise-data-access-controls">Hidden Concern 4 - &lt;strong>Breaking Traditional Enterprise Data Access Controls&lt;/strong>
&lt;/h2>&lt;p>Unlike the direct leakage of sensitive data, after an enterprise connects large amounts of internal data to an LLM via MCP, ordinary employees may be able to access or infer data they are not authorized to access.&lt;/p>
&lt;p>For example, if all of an enterprise&amp;rsquo;s internal documents are connected to an LLM, an employee, through the assistant:&lt;/p>
&lt;p>&lt;em>&amp;ldquo;Based on all the documents I have permission to access and the company&amp;rsquo;s appointment and removal notices, infer major events that have not yet been announced, such as layoffs&amp;rdquo;&lt;/em>&lt;/p>
&lt;p>Or someone at the manager level:&lt;/p>
&lt;p>&lt;em>&amp;ldquo;I saw an anonymous negative comment about XXX on the internal wiki, the content is XXXX; please analyze the speaking records of members in the XX team and infer who most likely wrote this comment&amp;rdquo;&lt;/em>&lt;/p>
&lt;h2 id="hidden-concern-5---the-inherent-capability-limits-of-llms">&lt;strong>Hidden Concern 5 - The Inherent Capability Limits of LLMs&lt;/strong>
&lt;/h2>&lt;p>For large-scale MCP integration, the load capacity of the LLM itself may well be unable to cope. Google&amp;rsquo;s &lt;strong>A2A protocol (Agent to Agent)&lt;/strong> may be a solution, but that is another matter.&lt;/p>
&lt;h3 id="mcp-1">&lt;strong>MCP&amp;rsquo;s Effectiveness Depends on the LLM Integrated into the Assistant&lt;/strong>
&lt;/h3>&lt;p>One fact is that &lt;strong>it is not the case that the more tools and the more data, the more accurate the results&lt;/strong>; on the contrary, the more similar data and tools there are, the worse the precision of the final output becomes. As the number of MCP servers grows and more tools are integrated, the performance of AI assistants will also decline significantly, and the cost of requests and analysis will increase.&lt;/p>
&lt;h3 id="the-gap-between-tool-implementation-and-user-expectations">&lt;strong>The Gap Between Tool Implementation and User Expectations&lt;/strong>
&lt;/h3>&lt;p>In implementation, many MCP servers are essentially functions or methods written to call tools that already exist locally, so their capabilities are mainly constrained by those functions and methods. If users have little understanding of the specific function implementations and simply interact with the LLM following ordinary human communication patterns, they are likely to struggle to get satisfactory results.&lt;/p>
&lt;p>&lt;em>&amp;ldquo;Please find for me all recent blog articles related to AI testing&amp;rdquo;&lt;/em>; this instruction actually requires the local MCP server to have the ability to full-text search local text content, but if the integrated MCP server only includes file-finding functionality, naturally no corresponding results can be obtained.&lt;/p>
&lt;h1 id="conclusion-and-outlook">Conclusion and Outlook
&lt;/h1>&lt;p>The birth of MCP answers the data-integration needs of the AI era, and its everyday application value is beyond doubt. But we also need a sober awareness: the MCP protocol is still in its growth phase, and while we embrace its applications, we must also recognize the risks within it; combining LLMs with data amplifies existing risks and gives rise to new types of threats.&lt;/p>
&lt;hr>
&lt;p>Most of the views in this article are drawn from Shrivu&amp;rsquo;s blog (Read the original article)&lt;/p></description></item><item><title>Google Launches the A2A Protocol</title><link>https://chengxiaqiucao.github.io/en/post/075-google%E6%8E%A8%E5%87%BAa2a%E5%8D%8F%E8%AE%AE/</link><pubDate>Fri, 11 Apr 2025 11:36:52 +0800</pubDate><guid>https://chengxiaqiucao.github.io/en/post/075-google%E6%8E%A8%E5%87%BAa2a%E5%8D%8F%E8%AE%AE/</guid><description>&lt;img src="https://chengxiaqiucao.github.io/post/075-google%E6%8E%A8%E5%87%BAa2a%E5%8D%8F%E8%AE%AE/Pasted-20250411.webp" alt="Featured image of post Google Launches the A2A Protocol" />&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/075-google%E6%8E%A8%E5%87%BAa2a%E5%8D%8F%E8%AE%AE/Pasted-20250411_hu_5e28383edd3073c.webp"
width="1024"
height="352"
srcset="https://chengxiaqiucao.github.io/post/075-google%E6%8E%A8%E5%87%BAa2a%E5%8D%8F%E8%AE%AE/Pasted-20250411_hu_ba1edaf83d481e4f.webp 480w, https://chengxiaqiucao.github.io/post/075-google%E6%8E%A8%E5%87%BAa2a%E5%8D%8F%E8%AE%AE/Pasted-20250411_hu_5e28383edd3073c.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="290"
data-flex-basis="697px"
>
&lt;/p>
&lt;blockquote>
&lt;p>On April 9, Google made a major release of the &lt;strong>A2A (Agent to Agent)&lt;/strong> protocol, adding more fuel to the opening-up and standardization of AI Agent capabilities. So what exactly does this &lt;strong>A2A protocol&lt;/strong> do? What is its relationship with the previously red-hot &lt;strong>MCP Server&lt;/strong>? Will it give rise to a standards war? In this article, let&amp;rsquo;s get to know this freshly baked A2A protocol and its application scenarios.&lt;/p>&lt;/blockquote>
&lt;h2 id="a2a-and-mcp">A2A and MCP
&lt;/h2>&lt;p>&lt;strong>A2A&lt;/strong>, namely the Agent to Agent protocol, is an open-source foundational AI protocol just launched by Google, aimed at enabling communication and interoperability between AI Agents. By providing agents with a standardized way to collaborate — that is, regardless of their underlying framework or vendor — different AI Agents can securely exchange information and collaborate, and can work across a variety of enterprise platforms and applications.&lt;/p>
&lt;p>This protocol provides a common communication standard between Agent and Agent.&lt;/p>
&lt;p>It and the recently red-hot &lt;strong>MCP (Model Context Protocol)&lt;/strong> (introduced in the previous article 【】) are actually not in a competitive relationship. Google&amp;rsquo;s official release statement also emphasized that this protocol is in fact a complement to the MCP protocol.&lt;/p>
&lt;p>&lt;strong>MCP&lt;/strong> is an open protocol launched late last year by the AI company Anthropic (the parent company of Claude), aimed at standardizing the interaction interface between large language models (LLMs) and external data sources and tools.&lt;/p>
&lt;p>As mainstream large models such as OpenAI announce support for MCP integration, MCP currently has great potential to become a foundational specification in the AI application field; the recent proliferation of all kinds of MCP Servers springing up like mushrooms after rain also proves that this protocol has gained wide recognition.&lt;/p>
&lt;p>As the saying goes, &lt;strong>third-rate companies make products, second-rate companies make brands, first-rate companies make standards&lt;/strong>; Google has keenly captured a very important piece of the puzzle in the AI Agent application standards beyond MCP.&lt;/p>
&lt;p>That is, MCP defines the connection between LLMs and Agents, and can use Agents to extend LLM capabilities. In the future there will surely also be Agent stores similar to the App Store, integrating all kinds of different Agents.&lt;/p>
&lt;p>But for subsequent large-scale AI applications, many Agents will be integrated to collaborate together, and the interaction between these Agents is precisely the missing piece of the puzzle at present. This is the role A2A plays — very similar to the inter-service communication protocol in a microservices system.&lt;/p>
&lt;h2 id="a2as-design-principles">A2A&amp;rsquo;s Design Principles
&lt;/h2>&lt;p>The official side has given the design principles of the A2A protocol:&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Embrace agentic capabilities&lt;/strong> — A2A is committed to enabling agents to collaborate in natural, unstructured modes, even when they do not share memory, tools, and context. We are enabling truly multi-agent scenarios, rather than confining agents to being a single &amp;ldquo;tool&amp;rdquo;.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Built on existing standards&lt;/strong> — the protocol is built on top of existing popular standards, including HTTP, SSE, and JSON-RPC, which means it is easier to integrate with the existing IT stacks that enterprises use every day.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Secure by default&lt;/strong> — A2A is designed to support enterprise-grade authentication and authorization, matching OpenAPI&amp;rsquo;s authentication schemes at launch.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Support for long-running tasks&lt;/strong> — A2A was designed with flexibility in mind and supports a variety of scenarios, enabling it to excel at a wide range of tasks, from quick tasks to deep research that may take hours or even days (if humans are involved). Along the way, A2A can provide users with real-time feedback, notifications, and status updates.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Modality agnostic&lt;/strong> — the world of agents is not limited to text, which is why we designed A2A to support a variety of modalities, including audio and video streaming.&lt;/p>
&lt;/li>
&lt;/ul>
&lt;h2 id="main-features">Main Features
&lt;/h2>&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/075-google%E6%8E%A8%E5%87%BAa2a%E5%8D%8F%E8%AE%AE/Pasted-20250412_hu_4219795f3fed0417.webp"
width="1024"
height="815"
srcset="https://chengxiaqiucao.github.io/post/075-google%E6%8E%A8%E5%87%BAa2a%E5%8D%8F%E8%AE%AE/Pasted-20250412_hu_aec75ac54f36259a.webp 480w, https://chengxiaqiucao.github.io/post/075-google%E6%8E%A8%E5%87%BAa2a%E5%8D%8F%E8%AE%AE/Pasted-20250412_hu_4219795f3fed0417.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="125"
data-flex-basis="301px"
>
&lt;/p>
&lt;ul>
&lt;li>
&lt;p>&lt;strong>Capability discovery&lt;/strong> — agents can advertise their capabilities using a JSON-format &amp;ldquo;Agent Card&amp;rdquo;, allowing client agents to identify the best agent able to perform a task and use A2A to communicate with remote agents.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Task management&lt;/strong> — communication between client and remote agents is oriented toward task completion, with the agent responsible for executing the end user&amp;rsquo;s request. This &amp;ldquo;task&amp;rdquo; object is defined by the protocol and has a lifecycle. It can be completed immediately, or, for long-running tasks, each agent can communicate to stay in sync with one another about the task&amp;rsquo;s latest completion status. The output of a task is called an &amp;ldquo;artifact&amp;rdquo;.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Collaboration&lt;/strong> — agents can send messages to one another to convey context, replies, artifacts, or user instructions.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>User experience negotiation&lt;/strong> — each message contains &amp;ldquo;parts&amp;rdquo;, that is, fully formed content fragments such as a generated image. Each part has a specified content type, allowing the client and remote agents to negotiate the correct format needed, and explicitly including negotiation of user UI capabilities (such as iframe, video, Web forms, and so on).&lt;/p>
&lt;/li>
&lt;/ul>
&lt;p>The relationship between A2A, MCP, and LLMs:&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/075-google%E6%8E%A8%E5%87%BAa2a%E5%8D%8F%E8%AE%AE/Pasted-20250411-1_hu_359ec77ba0900eec.webp"
width="1024"
height="710"
srcset="https://chengxiaqiucao.github.io/post/075-google%E6%8E%A8%E5%87%BAa2a%E5%8D%8F%E8%AE%AE/Pasted-20250411-1_hu_e4cd7fea2eafa3d5.webp 480w, https://chengxiaqiucao.github.io/post/075-google%E6%8E%A8%E5%87%BAa2a%E5%8D%8F%E8%AE%AE/Pasted-20250411-1_hu_359ec77ba0900eec.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="144"
data-flex-basis="346px"
>
&lt;/p>
&lt;h2 id="protocol-specification">Protocol Specification
&lt;/h2>&lt;p>The protocol is currently open source on GitHub, mainly a format specification file in json schema form (for an introduction to json schema, see 【】); the concrete definitions can be found in the source document.&lt;/p>
&lt;p>Here is an explanation of the main parts it contains and their roles:&lt;/p>
&lt;h3 id="1-agentauthentication">&lt;strong>1. AgentAuthentication&lt;/strong>
&lt;/h3>&lt;p>This part defines the supported authentication methods, such as OAuth or API keys.&lt;/p>
&lt;h3 id="2-agentcapabilities">&lt;strong>2. AgentCapabilities&lt;/strong>
&lt;/h3>&lt;p>Used to identify the scope of an Agent&amp;rsquo;s capabilities, such as whether it supports real-time communication.&lt;/p>
&lt;h3 id="3-agentcard">&lt;strong>3. AgentCard&lt;/strong>
&lt;/h3>&lt;p>Provides an Agent&amp;rsquo;s core information, such as its functions and skills, to facilitate discovery.&lt;/p>
&lt;h3 id="4-agentprovider">&lt;strong>4. AgentProvider&lt;/strong>
&lt;/h3>&lt;p>Identifies the organization or company information of the provider.&lt;/p>
&lt;h3 id="5-agentskill">&lt;strong>5. AgentSkill&lt;/strong>
&lt;/h3>&lt;p>Describes an Agent&amp;rsquo;s skills, such as the tasks or functions it can perform.&lt;/p>
&lt;h3 id="6-error-definitions">&lt;strong>6. Error Definitions&lt;/strong>
&lt;/h3>&lt;p>Contains some predefined Errors — &lt;strong>PushNotificationNotSupportedError&lt;/strong>, &lt;strong>InvalidParamsError&lt;/strong>, and &lt;strong>JSONParseError&lt;/strong> indicate error types such as notifications not supported, invalid parameters, and JSON parsing, respectively.&lt;/p>
&lt;h3 id="7-filecontent--filepart">&lt;strong>7. FileContent &amp;amp; FilePart&lt;/strong>
&lt;/h3>&lt;p>Used to pass file-related data, such as upload or download operations.&lt;/p>
&lt;h2 id="case-study">Case Study
&lt;/h2>&lt;p>&lt;code>a2aprotocol.net&lt;/code> provides a case-scenario description of A2A and MCP collaboration.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/075-google%E6%8E%A8%E5%87%BAa2a%E5%8D%8F%E8%AE%AE/Pasted-20250412-1_hu_1fdf0b8e3220556e.webp"
width="1024"
height="1609"
srcset="https://chengxiaqiucao.github.io/post/075-google%E6%8E%A8%E5%87%BAa2a%E5%8D%8F%E8%AE%AE/Pasted-20250412-1_hu_a088d5dd5ca60cc.webp 480w, https://chengxiaqiucao.github.io/post/075-google%E6%8E%A8%E5%87%BAa2a%E5%8D%8F%E8%AE%AE/Pasted-20250412-1_hu_1fdf0b8e3220556e.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="63"
data-flex-basis="152px"
>
&lt;/p>
&lt;p>For applications in the testing field, as in the article 【】, some readers mentioned richer scenarios: integrating test-case parsing, Playwright execution, and issue collection and reporting. This can be accomplished by different Agents, respectively responsible for test-case generation, Playwright execution, and submissions to tools such as ZenTao and Jira. Here, besides the workflow between Agents, the transfer of items like test cases and Bugs between different Agents can be implemented using the A2A protocol.&lt;/p>
&lt;p>Relevant practices still await the enrichment of the related Agents; this account will continue to follow up going forward!&lt;/p></description></item><item><title>Microsoft Has Released Playwright MCP</title><link>https://chengxiaqiucao.github.io/en/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/</link><pubDate>Wed, 02 Apr 2025 16:38:33 +0800</pubDate><guid>https://chengxiaqiucao.github.io/en/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/</guid><description>&lt;img src="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402.webp" alt="Featured image of post Microsoft Has Released Playwright MCP" />&lt;h1 id="preface">Preface
&lt;/h1>&lt;p>&lt;code>MCP protocol&lt;/code> is an open protocol for AI capabilities launched in November 2024 by the AI company Anthropic (the parent company of Claude), aimed at standardizing the interaction interface between large language models (LLMs) and external data sources and tools. Its core design goals:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Decoupling and standardization&lt;/strong> — shifting the integration of LLMs with external systems from custom development to universal connections based on a unified protocol, similar to the USB-C interface in hardware.&lt;/li>
&lt;li>&lt;strong>Decentralization&lt;/strong> — by allowing developers to build their own MCP Servers, distributing AI capabilities and avoiding a single vendor&amp;rsquo;s monopoly on knowledge and services.&lt;/li>
&lt;li>&lt;strong>Security and control&lt;/strong> — ensuring data privacy and operational safety through permission verification and localized deployment.&lt;/li>
&lt;/ul>
&lt;p>And &lt;code>MCP Server&lt;/code> is the key component of MCP, providing the following three functions:&lt;/p>
&lt;ul>
&lt;li>Resources — file-like data that can be read by clients, such as API responses or file contents.&lt;/li>
&lt;li>Tools — functions that can be called by the LLM (requiring user approval).&lt;/li>
&lt;li>Prompts — pre-written templates that help users accomplish specific tasks.&lt;/li>
&lt;/ul>
&lt;p>Through these capabilities, MCP Server can provide AI applications with richer context and the ability to operate on private data or specific applications, thereby enhancing the usefulness of LLMs.&lt;/p>
&lt;p>In the previous article 【】, we gained a basic understanding of MCP Server, provided a basic example of querying the local desktop, and used the AI editor &lt;code>Cursor&lt;/code> to invoke this MCP server.&lt;/p>
&lt;h1 id="microsoft-officially-releases-playwright-mcp">Microsoft Officially Releases Playwright-mcp
&lt;/h1>&lt;p>Among the many current applications of MCP Server, orchestrating browser operations is an extremely high-frequency scenario. Based on Playwright, this rising new browser tool, third parties have already taken the lead in releasing an MCP Server.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402_hu_6115ffe2cb7bd57.webp"
width="1024"
height="549"
srcset="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402_hu_9b19dc088504c794.webp 480w, https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402_hu_6115ffe2cb7bd57.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="186"
data-flex-basis="447px"
>
&lt;/p>
&lt;p>And now, Microsoft has finally officially released Playwright-mcp, which can be used seamlessly with VS Code Copilot.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-1_hu_3ad7d5515eed5d41.webp"
width="1024"
height="575"
srcset="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-1_hu_b490105d1cb5d18b.webp 480w, https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-1_hu_3ad7d5515eed5d41.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="178"
data-flex-basis="427px"
>
&lt;/p>
&lt;h1 id="playwright-mcp-deployment">Playwright-mcp Deployment
&lt;/h1>&lt;p>Because Playwright-mcp has just been released, its integration in VS Code is currently mainly in the preview edition, VS Code Insiders. So we can first download VS Code Insiders from the official VS Code website.
&lt;img src="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-2_hu_74ed7668c659b2fd.webp"
width="1024"
height="528"
srcset="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-2_hu_fed69eea3aa9ff72.webp 480w, https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-2_hu_74ed7668c659b2fd.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="193"
data-flex-basis="465px"
>
&lt;/p>
&lt;p>After installing VS Code Insiders, on the GitHub project homepage, simply click the corresponding button to install it.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-3_hu_6f97d608f30c9908.webp"
width="1024"
height="694"
srcset="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-3_hu_eeae79262f666e81.webp 480w, https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-3_hu_6f97d608f30c9908.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="147"
data-flex-basis="354px"
>
&lt;/p>
&lt;p>After opening VS Code, select install server; this will automatically configure the MCP server&amp;rsquo;s configuration file. Click start to run the MCP server, and with that the deployment is actually complete.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-4_hu_d155d43882fcee93.webp"
width="1024"
height="606"
srcset="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-4_hu_8f82ef31fe28c5a8.webp 480w, https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-4_hu_d155d43882fcee93.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="169"
data-flex-basis="405px"
>
&lt;/p>
&lt;p>Click the tools button shown in the Copilot dialog box to see the currently integrated tools, which mainly correspond to Playwright&amp;rsquo;s 15 main operation behaviors.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-5_hu_58391e16e77adad.webp"
width="1024"
height="766"
srcset="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-5_hu_d20a8dc5f22dfa88.webp 480w, https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-5_hu_58391e16e77adad.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="133"
data-flex-basis="320px"
>
&lt;/p>
&lt;h1 id="complete-browser-operations-and-verification-with-playwright-mcp-without-writing-code">Complete Browser Operations and Verification with Playwright-mcp Without Writing Code
&lt;/h1>&lt;p>Let&amp;rsquo;s take a look at the results below.&lt;/p>
&lt;p>Open Copilot and enter the instruction:&lt;/p>
&lt;blockquote>
&lt;p>Navigate to &lt;a class="link" href="vscode-file://vscode-app/c:/Users/Administrator/AppData/Local/Programs/Microsoft%20VS%20Code%20Insiders/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html" >https://www.saucedemo.com&lt;/a>, log in with the account standard_user and the password secret_sauce, confirm the login succeeds, and verify the product page displays correctly&lt;/p>&lt;/blockquote>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-6_hu_fd4cbb8513a9b1db.webp"
width="1024"
height="598"
srcset="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-6_hu_e65ecd9262e5b849.webp 480w, https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-6_hu_fd4cbb8513a9b1db.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="171"
data-flex-basis="410px"
>
&lt;/p>
&lt;p>Continue the execution and obtain the result — the test case ran successfully.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-7_hu_f889b9b7740fec63.webp"
width="1024"
height="556"
srcset="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-7_hu_aa4cb13af9b277bb.webp 480w, https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250402-7_hu_f889b9b7740fec63.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="184"
data-flex-basis="441px"
>
&lt;/p>
&lt;p>As you can see, here we did not write any code, yet used Playwright&amp;rsquo;s MCP to complete the execution of the login test case.&lt;/p>
&lt;p>Of course, in real work, the integration of the MCP server is more about giving us greater convenience in calling the browser to carry out task execution!&lt;/p>
&lt;p>Based on MCP Server, I believe there are still more and richer practices that can help us!&lt;/p>
&lt;hr>
&lt;p>In the previous article, we introduced the basic effect of integrating Microsoft&amp;rsquo;s official Playwright MCP through VS Code Insiders and executing tests.&lt;/p>
&lt;p>A reader asked whether it can be used in &lt;code>Cursor&lt;/code>? I also tried it here, and the answer is that it can be integrated successfully, but there are a few small pitfalls. Here I will share the configuration process with everyone, as well as the powerful capabilities after integrating MCP in Cursor. Having AI help us complete most basic functional testing is no longer far off.&lt;/p>
&lt;h2 id="enable-playwright-mcp-in-cursor">Enable Playwright-mcp in Cursor
&lt;/h2>&lt;h3 id="prerequisite-installation">Prerequisite Installation
&lt;/h3>&lt;p>First, of course, you need to install the MCP server and its corresponding dependencies; here both MCP and Playwright are based on Node.js. So install them first with the following commands.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-batch" data-lang="batch">&lt;span class="line">&lt;span class="cl">npm install -g @playwright/mcp@latest
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">npm install -g @playwright@latest
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">npx playwright install --with-deps
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="cursor-configuration">Cursor Configuration
&lt;/h3>&lt;p>After installation is complete, go to Cursor&amp;rsquo;s settings page, and in its MCP section, add the MCP server configuration. Referring to the introduction on the official Playwright website,
add the MCP server configuration:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;mcpServers&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;playwright&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;command&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;npx&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;args&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;@playwright/mcp@latest&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>But at this point, the MCP server in Cursor actually cannot run normally and will display &lt;code>Clint closed&lt;/code>.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/-20250404_hu_d7b32ce22abdd7db.webp"
width="1024"
height="399"
srcset="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/-20250404_hu_3ec933e8293b3541.webp 480w, https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/-20250404_hu_d7b32ce22abdd7db.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="256"
data-flex-basis="616px"
>
&lt;/p>
&lt;h3 id="on-windows-two-pitfalls-to-avoid">On Windows, Two Pitfalls to Avoid
&lt;/h3>&lt;p>&lt;strong>Pitfall 1 — the npx package loading path should be added to the search path&lt;/strong>&lt;/p>
&lt;p>That is, put the globally installed related packages into Node.js&amp;rsquo;s search path. The way to do this is to add the npm package directory to the PATH in the Windows system environment variables, and place it before Node.js.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250404_hu_efb68dc07543ffd5.webp"
width="1024"
height="1131"
srcset="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250404_hu_618db60a18911ac.webp 480w, https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250404_hu_efb68dc07543ffd5.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="90"
data-flex-basis="217px"
>
&lt;/p>
&lt;p>&lt;strong>Pitfall 2 — modify the MCP command-line invocation command&lt;/strong>&lt;/p>
&lt;p>Calling npx in Cursor is actually done through the command line, but on Windows, when npx is called directly from the command line, Cursor itself cannot obtain the invocation status, so here we need to use the &lt;code>cmd /c&lt;/code> command to invoke it and obtain the command handle.&lt;/p>
&lt;p>That is, modify the above configuration file to:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;mcpServers&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;playwright&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;command&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;cmd /c npx&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;args&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;@playwright/mcp@latest&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>After modifying the above configuration, reload Cursor. A command-line window will then start up — this is actually Playwright-mcp; do not close it — and then you can see that the MCP in Cursor has also started up normally.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250403_hu_57d69d819e55bef6.webp"
width="1024"
height="747"
srcset="https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250403_hu_80daf4c39384c787.webp 480w, https://chengxiaqiucao.github.io/post/072-%E5%BE%AE%E8%BD%AF%E5%B7%B2%E5%8F%91%E5%B8%83playwright-mcp/Pasted-20250403_hu_57d69d819e55bef6.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="137"
data-flex-basis="329px"
>
&lt;/p>
&lt;h2 id="let-playwright-mcp-execute-tests-on-our-behalf">Let Playwright-mcp Execute Tests on Our Behalf
&lt;/h2>&lt;p>We enter a basic task instruction in Cursor:&lt;/p>
&lt;blockquote>
&lt;p>Visit the &lt;a class="link" href="https://www.saucedemo.com" target="_blank" rel="noopener"
>www.saucedemo.com&lt;/a> website, log in using problem_user, verify the site&amp;rsquo;s complete workflow, and record the issues found&lt;/p>&lt;/blockquote>
&lt;p>Below is the complete execution process.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt"> 10
&lt;/span>&lt;span class="lnt"> 11
&lt;/span>&lt;span class="lnt"> 12
&lt;/span>&lt;span class="lnt"> 13
&lt;/span>&lt;span class="lnt"> 14
&lt;/span>&lt;span class="lnt"> 15
&lt;/span>&lt;span class="lnt"> 16
&lt;/span>&lt;span class="lnt"> 17
&lt;/span>&lt;span class="lnt"> 18
&lt;/span>&lt;span class="lnt"> 19
&lt;/span>&lt;span class="lnt"> 20
&lt;/span>&lt;span class="lnt"> 21
&lt;/span>&lt;span class="lnt"> 22
&lt;/span>&lt;span class="lnt"> 23
&lt;/span>&lt;span class="lnt"> 24
&lt;/span>&lt;span class="lnt"> 25
&lt;/span>&lt;span class="lnt"> 26
&lt;/span>&lt;span class="lnt"> 27
&lt;/span>&lt;span class="lnt"> 28
&lt;/span>&lt;span class="lnt"> 29
&lt;/span>&lt;span class="lnt"> 30
&lt;/span>&lt;span class="lnt"> 31
&lt;/span>&lt;span class="lnt"> 32
&lt;/span>&lt;span class="lnt"> 33
&lt;/span>&lt;span class="lnt"> 34
&lt;/span>&lt;span class="lnt"> 35
&lt;/span>&lt;span class="lnt"> 36
&lt;/span>&lt;span class="lnt"> 37
&lt;/span>&lt;span class="lnt"> 38
&lt;/span>&lt;span class="lnt"> 39
&lt;/span>&lt;span class="lnt"> 40
&lt;/span>&lt;span class="lnt"> 41
&lt;/span>&lt;span class="lnt"> 42
&lt;/span>&lt;span class="lnt"> 43
&lt;/span>&lt;span class="lnt"> 44
&lt;/span>&lt;span class="lnt"> 45
&lt;/span>&lt;span class="lnt"> 46
&lt;/span>&lt;span class="lnt"> 47
&lt;/span>&lt;span class="lnt"> 48
&lt;/span>&lt;span class="lnt"> 49
&lt;/span>&lt;span class="lnt"> 50
&lt;/span>&lt;span class="lnt"> 51
&lt;/span>&lt;span class="lnt"> 52
&lt;/span>&lt;span class="lnt"> 53
&lt;/span>&lt;span class="lnt"> 54
&lt;/span>&lt;span class="lnt"> 55
&lt;/span>&lt;span class="lnt"> 56
&lt;/span>&lt;span class="lnt"> 57
&lt;/span>&lt;span class="lnt"> 58
&lt;/span>&lt;span class="lnt"> 59
&lt;/span>&lt;span class="lnt"> 60
&lt;/span>&lt;span class="lnt"> 61
&lt;/span>&lt;span class="lnt"> 62
&lt;/span>&lt;span class="lnt"> 63
&lt;/span>&lt;span class="lnt"> 64
&lt;/span>&lt;span class="lnt"> 65
&lt;/span>&lt;span class="lnt"> 66
&lt;/span>&lt;span class="lnt"> 67
&lt;/span>&lt;span class="lnt"> 68
&lt;/span>&lt;span class="lnt"> 69
&lt;/span>&lt;span class="lnt"> 70
&lt;/span>&lt;span class="lnt"> 71
&lt;/span>&lt;span class="lnt"> 72
&lt;/span>&lt;span class="lnt"> 73
&lt;/span>&lt;span class="lnt"> 74
&lt;/span>&lt;span class="lnt"> 75
&lt;/span>&lt;span class="lnt"> 76
&lt;/span>&lt;span class="lnt"> 77
&lt;/span>&lt;span class="lnt"> 78
&lt;/span>&lt;span class="lnt"> 79
&lt;/span>&lt;span class="lnt"> 80
&lt;/span>&lt;span class="lnt"> 81
&lt;/span>&lt;span class="lnt"> 82
&lt;/span>&lt;span class="lnt"> 83
&lt;/span>&lt;span class="lnt"> 84
&lt;/span>&lt;span class="lnt"> 85
&lt;/span>&lt;span class="lnt"> 86
&lt;/span>&lt;span class="lnt"> 87
&lt;/span>&lt;span class="lnt"> 88
&lt;/span>&lt;span class="lnt"> 89
&lt;/span>&lt;span class="lnt"> 90
&lt;/span>&lt;span class="lnt"> 91
&lt;/span>&lt;span class="lnt"> 92
&lt;/span>&lt;span class="lnt"> 93
&lt;/span>&lt;span class="lnt"> 94
&lt;/span>&lt;span class="lnt"> 95
&lt;/span>&lt;span class="lnt"> 96
&lt;/span>&lt;span class="lnt"> 97
&lt;/span>&lt;span class="lnt"> 98
&lt;/span>&lt;span class="lnt"> 99
&lt;/span>&lt;span class="lnt">100
&lt;/span>&lt;span class="lnt">101
&lt;/span>&lt;span class="lnt">102
&lt;/span>&lt;span class="lnt">103
&lt;/span>&lt;span class="lnt">104
&lt;/span>&lt;span class="lnt">105
&lt;/span>&lt;span class="lnt">106
&lt;/span>&lt;span class="lnt">107
&lt;/span>&lt;span class="lnt">108
&lt;/span>&lt;span class="lnt">109
&lt;/span>&lt;span class="lnt">110
&lt;/span>&lt;span class="lnt">111
&lt;/span>&lt;span class="lnt">112
&lt;/span>&lt;span class="lnt">113
&lt;/span>&lt;span class="lnt">114
&lt;/span>&lt;span class="lnt">115
&lt;/span>&lt;span class="lnt">116
&lt;/span>&lt;span class="lnt">117
&lt;/span>&lt;span class="lnt">118
&lt;/span>&lt;span class="lnt">119
&lt;/span>&lt;span class="lnt">120
&lt;/span>&lt;span class="lnt">121
&lt;/span>&lt;span class="lnt">122
&lt;/span>&lt;span class="lnt">123
&lt;/span>&lt;span class="lnt">124
&lt;/span>&lt;span class="lnt">125
&lt;/span>&lt;span class="lnt">126
&lt;/span>&lt;span class="lnt">127
&lt;/span>&lt;span class="lnt">128
&lt;/span>&lt;span class="lnt">129
&lt;/span>&lt;span class="lnt">130
&lt;/span>&lt;span class="lnt">131
&lt;/span>&lt;span class="lnt">132
&lt;/span>&lt;span class="lnt">133
&lt;/span>&lt;span class="lnt">134
&lt;/span>&lt;span class="lnt">135
&lt;/span>&lt;span class="lnt">136
&lt;/span>&lt;span class="lnt">137
&lt;/span>&lt;span class="lnt">138
&lt;/span>&lt;span class="lnt">139
&lt;/span>&lt;span class="lnt">140
&lt;/span>&lt;span class="lnt">141
&lt;/span>&lt;span class="lnt">142
&lt;/span>&lt;span class="lnt">143
&lt;/span>&lt;span class="lnt">144
&lt;/span>&lt;span class="lnt">145
&lt;/span>&lt;span class="lnt">146
&lt;/span>&lt;span class="lnt">147
&lt;/span>&lt;span class="lnt">148
&lt;/span>&lt;span class="lnt">149
&lt;/span>&lt;span class="lnt">150
&lt;/span>&lt;span class="lnt">151
&lt;/span>&lt;span class="lnt">152
&lt;/span>&lt;span class="lnt">153
&lt;/span>&lt;span class="lnt">154
&lt;/span>&lt;span class="lnt">155
&lt;/span>&lt;span class="lnt">156
&lt;/span>&lt;span class="lnt">157
&lt;/span>&lt;span class="lnt">158
&lt;/span>&lt;span class="lnt">159
&lt;/span>&lt;span class="lnt">160
&lt;/span>&lt;span class="lnt">161
&lt;/span>&lt;span class="lnt">162
&lt;/span>&lt;span class="lnt">163
&lt;/span>&lt;span class="lnt">164
&lt;/span>&lt;span class="lnt">165
&lt;/span>&lt;span class="lnt">166
&lt;/span>&lt;span class="lnt">167
&lt;/span>&lt;span class="lnt">168
&lt;/span>&lt;span class="lnt">169
&lt;/span>&lt;span class="lnt">170
&lt;/span>&lt;span class="lnt">171
&lt;/span>&lt;span class="lnt">172
&lt;/span>&lt;span class="lnt">173
&lt;/span>&lt;span class="lnt">174
&lt;/span>&lt;span class="lnt">175
&lt;/span>&lt;span class="lnt">176
&lt;/span>&lt;span class="lnt">177
&lt;/span>&lt;span class="lnt">178
&lt;/span>&lt;span class="lnt">179
&lt;/span>&lt;span class="lnt">180
&lt;/span>&lt;span class="lnt">181
&lt;/span>&lt;span class="lnt">182
&lt;/span>&lt;span class="lnt">183
&lt;/span>&lt;span class="lnt">184
&lt;/span>&lt;span class="lnt">185
&lt;/span>&lt;span class="lnt">186
&lt;/span>&lt;span class="lnt">187
&lt;/span>&lt;span class="lnt">188
&lt;/span>&lt;span class="lnt">189
&lt;/span>&lt;span class="lnt">190
&lt;/span>&lt;span class="lnt">191
&lt;/span>&lt;span class="lnt">192
&lt;/span>&lt;span class="lnt">193
&lt;/span>&lt;span class="lnt">194
&lt;/span>&lt;span class="lnt">195
&lt;/span>&lt;span class="lnt">196
&lt;/span>&lt;span class="lnt">197
&lt;/span>&lt;span class="lnt">198
&lt;/span>&lt;span class="lnt">199
&lt;/span>&lt;span class="lnt">200
&lt;/span>&lt;span class="lnt">201
&lt;/span>&lt;span class="lnt">202
&lt;/span>&lt;span class="lnt">203
&lt;/span>&lt;span class="lnt">204
&lt;/span>&lt;span class="lnt">205
&lt;/span>&lt;span class="lnt">206
&lt;/span>&lt;span class="lnt">207
&lt;/span>&lt;span class="lnt">208
&lt;/span>&lt;span class="lnt">209
&lt;/span>&lt;span class="lnt">210
&lt;/span>&lt;span class="lnt">211
&lt;/span>&lt;span class="lnt">212
&lt;/span>&lt;span class="lnt">213
&lt;/span>&lt;span class="lnt">214
&lt;/span>&lt;span class="lnt">215
&lt;/span>&lt;span class="lnt">216
&lt;/span>&lt;span class="lnt">217
&lt;/span>&lt;span class="lnt">218
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-text" data-lang="text">&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">I will help you visit the Sauce Demo website and use the problem_user account to carry out a complete test-flow verification. Let&amp;#39;s get started.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">First, let me visit the website:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_navigate
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Let me log in with the problem_user account:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_type
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Now enter the password:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_type
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Click the login button:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_click
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Let&amp;#39;s begin testing and recording issues. First I notice the following problem:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">1. Product image issue:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">All products display the same image (a picture of a dog), which is obviously a bug, because each product should display its own unique product image.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Let me try adding a product to the cart:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_click
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Let me click the cart icon to view the cart:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_click
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Let&amp;#39;s return to the product list and try using the sorting function:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_click
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Let me try using the sorting function:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_click
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_select_option
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Based on the test process, I found the following problems:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">1. Image display issue:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- All product images display as the same dog picture, rather than their respective product images
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- This affects the user&amp;#39;s visual recognition of products
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">1. Cart function issue:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Clicking a product image or title does not correctly navigate to the product detail page, but instead jumps directly to a fixed product page
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- This affects the user&amp;#39;s experience of browsing and selecting products
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">1. Sorting function issue:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- After selecting different sorting options (such as price from low to high), the product list order does not change
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- The sorting function is completely broken
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">1. Navigation issue:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Clicking a product always jumps to the same product page, rather than the specific product clicked
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- This seriously affects the user&amp;#39;s shopping experience
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">1. Button state issue:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- The &amp;#34;Add to cart&amp;#34; and &amp;#34;Remove&amp;#34; button states for some products are displayed inconsistently
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- This may cause users to be confused about the state of products in the cart
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">These problems seriously affect the website&amp;#39;s basic functions and user experience. The problem_user account indeed demonstrates multiple issues that need fixing, covering aspects such as UI display, functional operations, and user experience.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Would you like me to continue testing other functions, such as the checkout flow?
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Please continue testing
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">OK, I will continue testing the checkout flow. First let&amp;#39;s add some products to the cart and then proceed to checkout:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_click
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Now let&amp;#39;s click the cart icon to enter the cart page:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_click
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">I found that clicking the cart icon revealed another problem - it took us to the product detail page instead of the cart page. Let&amp;#39;s try clicking the cart icon in the upper right corner of the page:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_navigate
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Let&amp;#39;s continue the checkout flow and click the Checkout button:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_click
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Let&amp;#39;s fill in the personal information:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_type
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_type
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_type
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Click Continue to proceed:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_click
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">I found a new problem: although we entered the last name, the system displays a &amp;#34;Last Name is required&amp;#34; error. This indicates there is a problem with the input field. Let&amp;#39;s try entering the last name again:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_type
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Based on the test process, I found the following new problems:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">1. Cart navigation issue:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Clicking the cart icon on the product list page incorrectly navigates to the product detail page
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- You must manually enter the cart URL to access the cart page
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">1. Checkout form issue:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- The last name (Last Name) input field has a serious problem
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Even after entering the last name, the system still shows a &amp;#34;Last Name is required&amp;#34; error
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- This problem prevents the user from completing the checkout flow
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">1. Cart product display issue:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- The number of products shown in the cart does not match the number of products actually added
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Some products that were not added also appear in the cart
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Together with the previously found problems, these seriously affect the entire shopping flow:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Users cannot browse products normally (image problem)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Cannot correctly add products to the cart (cart function problem)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Cannot use the sorting function (sorting broken)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Cannot access the cart normally (navigation problem)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Cannot complete the checkout flow (form validation problem)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">These problems make it almost impossible for the problem_user account to complete a normal shopping flow. Every major function has problems to varying degrees; this may have been deliberately set up for testing purposes.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Would you like me to continue testing other functions, such as the menu bar functions?
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Test complete — please log out and summarize the issues found
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">OK, let&amp;#39;s first click the menu button and then log out:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_click
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Called MCP toolbrowser_click
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">Now I will summarize all the issues found testing with the problem_user account:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">### 1. Product display issues
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- All product images display as the same dog picture, rather than their respective product images
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- This seriously affects the user&amp;#39;s visual recognition of products and the shopping experience
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">### 2. Navigation issues
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Clicking a product image or title always jumps to a fixed product page, rather than the specific product clicked
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Clicking the cart icon incorrectly navigates to the product detail page instead of the cart page
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- You must manually enter the cart URL to correctly access the cart page
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">### 3. Product sorting function issues
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- After selecting different sorting options (such as price from low to high), the product list order does not change at all
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- The sorting function is completely broken and cannot help users browse products the way they want
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">### 4. Cart function issues
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- The products shown in the cart do not match the products actually added
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Some products that were not added also appear in the cart
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- The &amp;#34;Add to cart&amp;#34; and &amp;#34;Remove&amp;#34; button states are displayed inconsistently, causing user confusion
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">### 5. Checkout flow issues
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- The last name (Last Name) input field has a serious problem
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Even after entering the last name, the system still shows a &amp;#34;Last Name is required&amp;#34; error
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- This validation problem completely prevents the user from finishing the checkout flow
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">### 6. User experience impact
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- The combined effect of the above problems leads to:
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Users cannot correctly browse and select products
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Cannot manage cart contents
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Cannot complete the shopping flow
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- The overall shopping experience is seriously damaged
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">### 7. Functional usability assessment
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Almost all basic functions have problems
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- Users cannot complete a normal shopping flow
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">- This account may be dedicated to testing purposes, demonstrating various possible problem scenarios
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">These problems cover the core functions of an e-commerce website, including product display, navigation, cart management, and the checkout flow. Every link has problems to varying degrees, making the entire shopping experience extremely difficult and frustrating. The existence of these problems may be for testing purposes, helping developers and testers understand various possible error scenarios.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>As you can see, with Cursor + Playwright-mcp, AI can already, from the basic instructions we give it, proactively help us cover the main functional test scenarios and discover and record issues. Given time, it could largely replace fairly basic functional testing tasks, while testers can focus more on high-value, in-depth problem exploration. Of course, on the other hand, basic functional testers really do need a considerable sense of crisis — upgrading their skills and expanding their boundaries brooks no delay.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/qrcode_for_gh_e12c318badb4_258%20%281%29.jpg"
loading="lazy"
>
&lt;/p>
&lt;p>Welcome to follow Qiucao&amp;rsquo;s course on systematic, advanced improvement of testing skills; reply with &lt;code>Outline&lt;/code> in the official account to see the detailed course catalog.&lt;/p></description></item><item><title>The Next Stop for AI - MCP Server</title><link>https://chengxiaqiucao.github.io/en/post/073-ai%E4%B8%8B%E4%B8%80%E7%AB%99-mcpserver/</link><pubDate>Tue, 01 Apr 2025 00:00:00 +0000</pubDate><guid>https://chengxiaqiucao.github.io/en/post/073-ai%E4%B8%8B%E4%B8%80%E7%AB%99-mcpserver/</guid><description>&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/073-ai%E4%B8%8B%E4%B8%80%E7%AB%99-mcpserver/Pasted-20250402_hu_7489755b7817049a.webp"
width="1024"
height="573"
srcset="https://chengxiaqiucao.github.io/post/073-ai%E4%B8%8B%E4%B8%80%E7%AB%99-mcpserver/Pasted-20250402_hu_9da7da69332f4757.webp 480w, https://chengxiaqiucao.github.io/post/073-ai%E4%B8%8B%E4%B8%80%E7%AB%99-mcpserver/Pasted-20250402_hu_7489755b7817049a.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="178"
data-flex-basis="429px"
>
&lt;/p>
&lt;h2 id="introduction">Introduction
&lt;/h2>&lt;p>In 2025, as AI technology evolves at breakneck speed, the limitations of large models are becoming increasingly apparent; they possess powerful reasoning capabilities, yet struggle to directly access private data or invoke external tools. This pain point has given rise to a revolutionary technology — &lt;strong>MCP (Model Context Protocol)&lt;/strong> — and &lt;strong>MCP Server&lt;/strong>, its core component, is fast becoming the next big thing in the AI industry. This article takes a deep dive into the technical essence and industry value of MCP Server, and explores its application prospects through real-world cases.&lt;/p>
&lt;hr>
&lt;h2 id="part-one---what-is-mcp-the-past-and-present-of-mcp">Part One - What Is MCP? The Past and Present of MCP
&lt;/h2>&lt;h3 id="1-the-definition-and-design-goals-of-mcp">1. The Definition and Design Goals of MCP
&lt;/h3>&lt;p>MCP is an open protocol introduced by the AI company Anthropic (the parent company of Claude) in November 2024, designed to standardize the interaction interface between large language models (LLMs) and external data sources and tools. Its core design goals:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Decoupling and Standardization&lt;/strong>: Transforming the integration of LLMs with external systems from custom development into universal connections based on a unified protocol, similar to the USB-C interface in hardware.&lt;/li>
&lt;li>&lt;strong>Decentralization&lt;/strong>: By allowing developers to build their own MCP Servers, AI capabilities are distributed, preventing a single vendor from monopolizing knowledge and services.&lt;/li>
&lt;li>&lt;strong>Security and Control&lt;/strong>: Ensuring data privacy and operational safety through permission verification and local deployment.&lt;/li>
&lt;/ul>
&lt;h3 id="2-the-technical-evolution-from-langchain-to-mcp">2. The Technical Evolution from Langchain to MCP
&lt;/h3>&lt;p>Before MCP, developers relied on middleware frameworks such as Langchain to connect LLMs with tools, but these solutions had two major bottlenecks:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Fragmentation&lt;/strong>: API standards vary across vendors, making integration costly;&lt;/li>
&lt;li>&lt;strong>Closedness&lt;/strong>: The plugin ecosystems of vendors such as OpenAI are confined to their own platforms, making reuse across models difficult.&lt;/li>
&lt;li>&lt;/li>
&lt;/ol>
&lt;p>Through abstraction at the protocol layer, MCP encapsulates capabilities such as tool invocation and data access into standardized interfaces, so that any LLM supporting the MCP protocol can seamlessly connect to third-party services.&lt;/p>
&lt;h3 id="3-the-current-state-of-the-mcp-ecosystem">3. The Current State of the MCP Ecosystem
&lt;/h3>&lt;p>At this stage, the MCP ecosystem has begun to take shape:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Support from Leading Companies&lt;/strong>: Besides Claude from the company that initiated it, OpenAI, a leader in the AI industry, as well as domestic players such as Baidu and Tencent, have all announced support for MCP&lt;/li>
&lt;li>&lt;strong>A Large Developer Base&lt;/strong>: Thanks to a low barrier to entry, the various publicly available MCP Servers have grown explosively; within just a few weeks, thousands of public Servers have appeared, covering areas such as databases, design tools, and payment systems.&lt;/li>
&lt;li>&lt;strong>Emerging Business Value&lt;/strong>: Institutions such as a16z have drawn up MCP market maps, predicting it may give rise to a &amp;ldquo;Stripe of the Agentic AI space&amp;rdquo; caliber company.&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="part-two---what-does-mcp-server-do-why-might-it-be-the-ai-industrys-next-big-thing">Part Two - What Does MCP Server Do? Why Might It Be the AI Industry&amp;rsquo;s Next Big Thing?
&lt;/h2>&lt;h3 id="1-the-core-functions-of-mcp-server">1. The Core Functions of MCP Server
&lt;/h3>&lt;p>An MCP Server is a concrete implementation of the MCP protocol, playing the following key roles:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Tool Proxy&lt;/strong>: Converting external APIs (such as GitHub and PostgreSQL) into standardized tool descriptions that LLMs can understand, for example abstracting &amp;ldquo;create a GitHub Issue&amp;rdquo; into a function call.&lt;/li>
&lt;li>&lt;strong>Data Gateway&lt;/strong>: Securely accessing local or cloud data, for example letting an LLM read desktop files through a file-system MCP Server.&lt;/li>
&lt;li>&lt;strong>Workflow Orchestration&lt;/strong>: Supporting chained calls across multiple tools, for example querying a database first and then generating a report.&lt;/li>
&lt;/ul>
&lt;h3 id="2-three-major-drivers-behind-the-craze">2. Three Major Drivers Behind the Craze
&lt;/h3>&lt;h4 id="1-technology-trend---from-fat-models-to-thin-models--ecosystem">(1) Technology Trend - From &amp;ldquo;Fat Models&amp;rdquo; to &amp;ldquo;Thin Models + Ecosystem&amp;rdquo;
&lt;/h4>&lt;p>Traditional &amp;ldquo;fat models&amp;rdquo; try to internalize all knowledge within their parameters, resulting in high training costs and poor timeliness. Under the MCP architecture, LLMs focus on language understanding, while knowledge extension and tool invocation are handled by the MCP Server network, forming a new paradigm of &amp;ldquo;thin models + distributed capabilities&amp;rdquo;.&lt;/p>
&lt;h4 id="2-economic-model---the-ai-ification-of-the-creator-economy">(2) Economic Model - The AI-ification of the Creator Economy
&lt;/h4>&lt;p>MCP allows individual developers to earn revenue shares by building MCP Servers (such as a bird knowledge base), forming a decentralized knowledge economy network. For example, OpenMCP.Network, built on Ethereum, can automatically settle call volumes through smart contracts.&lt;/p>
&lt;h4 id="3-industry-demand---the-rigid-need-for-private-enterprise-ai-deployment">(3) Industry Demand - The Rigid Need for Private Enterprise AI Deployment
&lt;/h4>&lt;p>Enterprises can use MCP Servers to securely expose internal systems (such as CRM and ERP) to LLMs without uploading sensitive data to the cloud. Companies such as NineData have launched database MCP Server solutions that support localized data management.&lt;/p>
&lt;hr>
&lt;h2 id="part-three---as-software-testing-professionals-how-do-we-apply-mcp-server">Part Three - As Software Testing Professionals, How Do We Apply MCP Server?
&lt;/h2>&lt;h3 id="1-mcp-ifying-testing-scenarios">1. MCP-ifying Testing Scenarios
&lt;/h3>&lt;h4 id="1-simulating-external-dependencies">(1) Simulating External Dependencies
&lt;/h4>&lt;p>By building Mock MCP Servers to replace dependencies such as real payment and third-party APIs, test environment isolation is achieved. For example, simulating the Alipay interface returning an abnormal response to verify the system&amp;rsquo;s fault tolerance.&lt;/p>
&lt;h4 id="2-data-driven-testing">(2) Data-Driven Testing
&lt;/h4>&lt;p>Store test cases in a database or file, and have the MCP Server read and execute them dynamically. For example:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@mcp.tool&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">load_test_cases&lt;/span>&lt;span class="p">():&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Load JSON-format test cases from the specified directory&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">json&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">load&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nb">open&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;test_cases.json&amp;#34;&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>The test framework can automatically obtain the cases and generate test reports.&lt;/p>
&lt;h4 id="3-ai-assisted-testing">(3) AI-Assisted Testing
&lt;/h4>&lt;p>Use LLMs to invoke testing tools through MCP Servers, for example:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Automatic Test Script Generation&lt;/strong>: Generating Selenium code from requirement descriptions;&lt;/li>
&lt;li>&lt;strong>Intelligent Log Analysis&lt;/strong>: Locating the root causes of defects with an ELK Stack MCP Server.&lt;/li>
&lt;/ul>
&lt;h3 id="2-skill-upgrade-suggestions-for-testing-professionals">2. Skill Upgrade Suggestions for Testing Professionals
&lt;/h3>&lt;ul>
&lt;li>&lt;strong>Master MCP Server Development&lt;/strong>: Learn the Python/TypeScript MCP SDKs to build customized testing tools.&lt;/li>
&lt;li>&lt;strong>Get Familiar with the Mainstream MCP Ecosystem&lt;/strong>: Follow the Awesome MCP Servers list on GitHub to learn about testing-related services (such as PostgreSQL and JIRA integrations).&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="part-four---a-simple-mcp-server-implementation-case---a-desktop-file-query-service">Part Four - A Simple MCP Server Implementation Case - A Desktop File Query Service
&lt;/h2>&lt;h3 id="1-environment-setup">1. Environment Setup
&lt;/h3>&lt;ul>
&lt;li>Install the Python MCP SDK: &lt;code>pip install mcp&lt;/code>&lt;/li>
&lt;li>Create a project directory: &lt;code>mkdir mcp-demo &amp;amp;&amp;amp; cd mcp-demo&lt;/code>&lt;/li>
&lt;/ul>
&lt;h3 id="2-code-implementation">2. Code Implementation
&lt;/h3>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">mcp.server.fastmcp&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">FastMCP&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">import&lt;/span> &lt;span class="nn">os&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">mcp&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">FastMCP&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@mcp.tool&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">list_desktop_files&lt;/span>&lt;span class="p">():&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Get the list of files on the current user&amp;#39;s desktop&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">os&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">listdir&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">os&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">path&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">expanduser&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;~/Desktop&amp;#34;&lt;/span>&lt;span class="p">))&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">if&lt;/span> &lt;span class="vm">__name__&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="s2">&amp;#34;__main__&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">mcp&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">run&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">transport&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s1">&amp;#39;stdio&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>This code defines an MCP Server that provides the &lt;code>list_desktop_files&lt;/code> tool, allowing an LLM to query the user&amp;rsquo;s desktop files.&lt;/p>
&lt;h3 id="3-client-configuration-and-testing">3. Client Configuration and Testing
&lt;/h3>&lt;p>Add the configuration to &lt;code>mcp.json&lt;/code> in the Cursor editor:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;mcpServers&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;desktop&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;command&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;python server.py&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>After starting the service, we can directly ask, &amp;ldquo;What files are on my desktop?&amp;rdquo; Cursor will invoke the service through the MCP protocol, return a list of files currently on my desktop, and classify them by type.&lt;/p>
&lt;hr>
&lt;h2 id="conclusion">Conclusion
&lt;/h2>&lt;p>MCP Server is reshaping the way AI interacts with the physical world. For developers, it is a sharp tool for lowering integration costs; for enterprises, it is the key to unlocking the value of data; for testing professionals, it is a new engine for the evolution of automation. Although the ecosystem is still in its early days, its standardized, decentralized design philosophy has already pointed the way to the next stop for the AI industry. As Anthropic put it, &amp;ldquo;MCP is not the destination, but the starting point of the Agentic AI era.&amp;rdquo;&lt;/p></description></item><item><title>Software Testing in the AI Era - Assistant or Adversary?</title><link>https://chengxiaqiucao.github.io/en/post/070-ai%E6%97%B6%E4%BB%A3%E7%9A%84%E6%B5%8B%E8%AF%95/</link><pubDate>Tue, 25 Mar 2025 21:38:36 +0800</pubDate><guid>https://chengxiaqiucao.github.io/en/post/070-ai%E6%97%B6%E4%BB%A3%E7%9A%84%E6%B5%8B%E8%AF%95/</guid><description>&lt;p>In the present era, the AI wave is sweeping in, and &amp;ldquo;the future is already here&amp;rdquo; is no longer an empty slogan. AI-related topics and discussions have become the sure-fire &amp;ldquo;traffic magnet&amp;rdquo; of the tech world; from autonomous driving to intelligent customer service, every industry seems eager to ride this wave of AI hype.&lt;/p>
&lt;p>But as testing professionals, when we face the rapid development of AI, what we care about most is probably this: &lt;strong>What can AI actually do in software testing? Can it really help us improve output and efficiency? Or, as it evolves, will AI completely replace testing roles?&lt;/strong>&lt;/p>
&lt;p>In this article, let us explore this topic.&lt;/p>
&lt;h2 id="the-role-of-ai-in-the-different-stages-of-software-testing">The Role of AI in the Different Stages of Software Testing
&lt;/h2>&lt;p>AI testing, when it comes down to it, is about having AI take on part of, assist with, or enhance the original testing work. In other words, AI itself does not change the underlying laws of the software testing lifecycle within software development.&lt;/p>
&lt;p>Therefore, we can look at what role AI can play from the perspective of the different stages of the software testing lifecycle and the scope of testing responsibilities.&lt;/p>
&lt;h3 id="requirements-analysis-stage">Requirements Analysis Stage
&lt;/h3>&lt;p>At this stage, we can use AI&amp;rsquo;s natural language processing technology to sort out the original requirements documents and produce analysis results including business flowcharts, operation flowcharts, and data flow diagrams.&lt;/p>
&lt;p>At the same time, we can combine more relevant local data — such as historical bug data, test logs, and project data — to identify testing priorities, build risk models, and detect risks. Based on these analysis results, we can then help formulate a more reasonable test plan.&lt;/p>
&lt;h3 id="test-case-design-stage">Test Case Design Stage
&lt;/h3>&lt;p>During the software design and development phase, testers usually complete test design in parallel. At this stage, we can leverage AI to help us generate test cases based on the requirements documents and the results of the requirements analysis phase. With AI, we can produce more and fuller positive and negative cases as well as a variety of boundary conditions to expand coverage.&lt;/p>
&lt;h3 id="test-preparation-stage">Test Preparation Stage
&lt;/h3>&lt;p>At this stage, the main work is setting up and deploying the test environment. We can use AI capabilities combined with a CI platform to achieve intelligent management of test servers and database environments, as well as the dynamic allocation of resources.&lt;/p>
&lt;h3 id="test-execution-stage">Test Execution Stage
&lt;/h3>&lt;p>During the execution stage, we can dynamically adjust the test order based on factors such as various risk assessments, dependencies, and business impact, prioritizing coverage of higher-risk modules so as to expose defects as early as possible.&lt;/p>
&lt;p>In addition, AI can enhance capabilities such as log analysis and image comparison, improving our test execution efficiency and defect detection ability.&lt;/p>
&lt;h3 id="test-reporting-stage">Test Reporting Stage
&lt;/h3>&lt;p>In the closing part of testing, using AI to perform comprehensive analysis of various process data can help us produce multi-dimensional test reports, providing project decision-makers with a structured analysis of testing status.&lt;/p>
&lt;h2 id="how-ai-empowers-software-testing-at-this-stage">How AI Empowers Software Testing at This Stage
&lt;/h2>&lt;p>The current development of AI can already provide more support in many typical testing scenarios. The following outlines some typical scenarios that can be empowered by AI:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Intelligent Data Generation&lt;/strong> - Create diverse datasets covering common scenarios and edge cases&lt;/li>
&lt;li>&lt;strong>Test Automation&lt;/strong> - Automatically adapt to UI changes to keep automation scripts stable&lt;/li>
&lt;li>&lt;strong>Precise Regression Testing&lt;/strong> - Intelligently select related test cases based on code changes&lt;/li>
&lt;li>&lt;strong>Process Cloning&lt;/strong> - Learn testing workflows and then automatically execute similar processes&lt;/li>
&lt;li>&lt;strong>Dynamic Waiting Mechanism&lt;/strong> - Intelligently judge page load status before performing actions&lt;/li>
&lt;li>&lt;strong>Intelligent Log Analysis&lt;/strong> - Analyze and identify potential problem patterns in error logs&lt;/li>
&lt;li>&lt;strong>Load / Performance Testing&lt;/strong> - Simulate real user behavior and diagnose performance bottlenecks&lt;/li>
&lt;li>&lt;strong>Continuous Test Monitoring&lt;/strong> - Monitor application status in real time and alert on anomalies&lt;/li>
&lt;li>&lt;strong>Exploratory Testing Support&lt;/strong> - Provide intelligent suggestions during exploratory testing&lt;/li>
&lt;li>&lt;strong>Predictive Analysis&lt;/strong> - Predict release risks based on historical data&lt;/li>
&lt;/ul>
&lt;h2 id="the-advantages-of-introducing-ai">The Advantages of Introducing AI
&lt;/h2>&lt;p>AI can keep learning, training, and improving continuously, so after introducing AI, we can build advantages across many of the following aspects:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Cost Optimization&lt;/strong> - Reduce labor costs, optimize resource allocation, and speed up time to market&lt;/li>
&lt;li>&lt;strong>Stable and Reliable&lt;/strong> - Ensure standardized test execution and result consistency&lt;/li>
&lt;li>&lt;strong>Early Defect Screening&lt;/strong> - Expose problems early and shorten the fix cycle&lt;/li>
&lt;li>&lt;strong>Fast Feedback&lt;/strong> - Run tests in parallel across multiple environments to shorten the feedback loop&lt;/li>
&lt;li>&lt;strong>High-Quality Cases&lt;/strong> - Automatically generate diverse cases such as unit tests, regression tests, and API tests&lt;/li>
&lt;/ul>
&lt;h2 id="significant-challenges-still-remain-in-applying-ai">Significant Challenges Still Remain in Applying AI
&lt;/h2>&lt;h3 id="artificial-intelligence-or">&lt;strong>Artificial Intelligence or &amp;ldquo;Artificial Stupidity&amp;rdquo;?&lt;/strong>
&lt;/h3>&lt;p>If AI&amp;rsquo;s training data is biased, the results can be so absurd that they make you question reality. If the training outcome of AI is not ideal, then applying AI may not only fail to improve efficiency, but also waste a large amount of extra resources correcting its execution results.&lt;/p>
&lt;h3 id="data-dependency-syndrome">&lt;strong>Data Dependency Syndrome&lt;/strong>
&lt;/h3>&lt;p>AI&amp;rsquo;s high demands for quality training data and various parameter adjustments often impose significant constraints on real-world deployment in specific industries.&lt;/p>
&lt;h3 id="maintenance-costs-are-higher-than-you-think">&lt;strong>Maintenance Costs Are Higher Than You Think&lt;/strong>
&lt;/h3>&lt;p>Beyond the investment in data resources, training models on local datasets also requires a great deal of time and money, including equipment resources, which are a considerable expense. In addition, the current shortage of AI talent makes the labor cost of AI applications much higher.&lt;/p>
&lt;h3 id="experience-and-intuition-are-things-ai-can-never-learn">&lt;strong>Experience and Intuition Are Things AI Can Never Learn&lt;/strong>
&lt;/h3>&lt;p>Veteran testers with rich experience can sniff out hidden defects in a product from all kinds of subtle clues; this &amp;ldquo;mystical,&amp;rdquo; sixth-sense-like ability is bound to be difficult for AI to replicate.&lt;/p>
&lt;h2 id="assistant-or-adversary">Assistant or Adversary?
&lt;/h2>&lt;p>&amp;ldquo;With AI developing like this, are test engineers going to lose their jobs?&amp;rdquo; &lt;strong>There is really no need to panic!&lt;/strong>&lt;/p>
&lt;p>AI is still essentially a tool. Just as test automation replaced some manual checks, it only changes parts of the way we work rather than eliminating the role altogether. Future testers will be more like an &amp;ldquo;AI Trainer + Strategy Commander&amp;rdquo; — what we actually need to do boils down to the following:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Teach AI to understand business logic&lt;/strong> (for example, what a &amp;ldquo;correct order status transition&amp;rdquo; is);&lt;/li>
&lt;li>&lt;strong>Design smarter testing strategies&lt;/strong> (for example, how to balance automation and exploratory testing);&lt;/li>
&lt;li>&lt;strong>Interpret AI&amp;rsquo;s results and make decisions&lt;/strong> (for example, whether a given anomaly is a bug or a false positive).&lt;/li>
&lt;/ul>
&lt;p>AI is like a robotic vacuum: it can help you clean the floor, but when it comes to stubborn stains (complex business scenarios) or changes in furniture layout (requirement changes), you still have to step in yourself.&lt;/p>
&lt;h2 id="conclusion---ai-is-not-the-end-but-a-new-starting-point">Conclusion - AI Is Not the End, but a New Starting Point
&lt;/h2>&lt;p>The application of AI in software testing is still in its infancy. We can see its enormous potential, but it is not yet time to place full trust in it and abandon the original models. As testers, rather than worrying about &amp;ldquo;whether we will be replaced,&amp;rdquo; it is better to actively embrace change: learn some basic machine learning, get to know mainstream AI testing tools, and even take part in training your own models.&lt;/p>
&lt;p>After all, &lt;strong>in the future world of software testing, the most sought-after people will certainly not be &amp;ldquo;those who are best at clicking a mouse,&amp;rdquo; but &amp;ldquo;those who are best at working with AI&amp;rdquo;&lt;/strong>. What do you think?&lt;/p>
&lt;hr>
&lt;p>Some earlier articles also discussed the development of AI. For further reading:&lt;/p>
&lt;p>&lt;a class="link" href="https://mp.weixin.qq.com/s/JkBcOzZpVEVJBtvZjE4vEQ?token=645759914&amp;amp;lang=zh_CN" target="_blank" rel="noopener"
>In the AI Era, Do Programmers Still Have a Future?&lt;/a>&lt;/p>
&lt;p>&lt;a class="link" href="https://mp.weixin.qq.com/s/k9Dj9eRBhehPtbMiIHnn9g" target="_blank" rel="noopener"
>The Testing Profession and Its Future Prospects&lt;/a>&lt;/p></description></item><item><title>DeepSeek Prompt Frameworks Help Teams Improve the Status Quo and Boost Efficiency</title><link>https://chengxiaqiucao.github.io/en/post/069-%E4%BC%98%E5%8C%96ai%E6%8F%90%E7%A4%BA%E6%A1%86%E6%9E%B6%E5%AE%9E%E7%8E%B0%E5%9B%A2%E9%98%9F%E6%8F%90%E5%8D%87/</link><pubDate>Wed, 19 Mar 2025 22:44:42 +0800</pubDate><guid>https://chengxiaqiucao.github.io/en/post/069-%E4%BC%98%E5%8C%96ai%E6%8F%90%E7%A4%BA%E6%A1%86%E6%9E%B6%E5%AE%9E%E7%8E%B0%E5%9B%A2%E9%98%9F%E6%8F%90%E5%8D%87/</guid><description>&lt;img src="https://chengxiaqiucao.github.io/post/069-%E4%BC%98%E5%8C%96ai%E6%8F%90%E7%A4%BA%E6%A1%86%E6%9E%B6%E5%AE%9E%E7%8E%B0%E5%9B%A2%E9%98%9F%E6%8F%90%E5%8D%87/%E6%8F%90%E7%A4%BA%E8%AF%8D%E6%A1%86%E6%9E%B6.webp" alt="Featured image of post DeepSeek Prompt Frameworks Help Teams Improve the Status Quo and Boost Efficiency" />&lt;p>With the rapid development of AI technology, from ChatGPT to the explosion of DeepSeek, AI can now genuinely play a role in assisting our daily work.&lt;/p>
&lt;p>Beyond specific areas such as assisted programming and copywriting, we can also make full use of AI&amp;rsquo;s powerful logical capabilities and vast foundational data to help us propose practical and feasible improvement plans for some of the difficulties we encounter at work.&lt;/p>
&lt;p>But for AI to give us actionable solutions, the design of the prompt framework and the contextual information provided to AI are extremely critical. A well-designed prompt framework can help us quickly obtain highly valuable references.&lt;/p>
&lt;h2 id="a-case-of-the-predicament-we-face">A Case of the Predicament We Face
&lt;/h2>&lt;p>Here we use a fairly common case of an agile team&amp;rsquo;s quality predicament to illustrate:&lt;/p>
&lt;blockquote>
&lt;p>As a test engineer responsible for quality assurance in an agile team running the Scrum framework, the team also includes an SM, a PO, two Android developers (among whom Xiao Li is responsible for the overall system design of the App), one back-end developer, and one part-time visual designer. The team&amp;rsquo;s product is a companion Android App for an IoT smart bracelet product. However, due to issues such as coordination with the hardware team, frequently changing requirements, untimely visual design, delayed test submissions, and a backlog of bugs, product quality is not optimistic. The App has now gone through multiple iterations, and the planned launch date is drawing ever closer. How can we propose an improvement plan for the current quality predicament?&lt;/p>&lt;/blockquote>
&lt;h3 id="designing-the-prompt-framework">Designing the Prompt Framework
&lt;/h3>&lt;p>For AI to help us produce a feasible improvement plan, we first need to design the prompt framework reasonably, so that the final plan better fits the team&amp;rsquo;s current situation and is actionable.&lt;/p>
&lt;p>The key points of the prompt framework design are then:&lt;/p>
&lt;ul>
&lt;li>A given role, so that AI determines from what perspective to propose the improvement plan&lt;/li>
&lt;li>The current status quo, that is, sufficient background information and context&lt;/li>
&lt;li>What AI should analyze in detail, or what its task should be&lt;/li>
&lt;li>The specific output expected from AI, including format requirements and the elements to be included&lt;/li>
&lt;li>Some relevant constraints, which have an important impact on whether the plan is feasible&lt;/li>
&lt;/ul>
&lt;p>Now, for the predicament above, I want AI to help me provide an overall quality improvement plan for the team that can be discussed at the retrospective meeting. Based on the above thinking, by inputting the prompt framework into DeepSeek, we get the following output:&lt;/p>
&lt;h3 id="quality-improvement-plan-for-the-iteration-retrospective">Quality Improvement Plan (For the Iteration Retrospective)
&lt;/h3>&lt;hr>
&lt;h4 id="1-overall-quality-goals">&lt;strong>1. Overall Quality Goals&lt;/strong>
&lt;/h4>&lt;p>&lt;strong>&amp;ldquo;Within 2 iterations, raise automated test coverage to 40%, shorten defect-fix response time by 50%, compress regression testing time by 30%, and establish a quality defense line linking requirement changes with testing&amp;rdquo;&lt;/strong>&lt;/p>
&lt;hr>
&lt;h4 id="2-specific-improvement-initiatives">&lt;strong>2. Specific Improvement Initiatives&lt;/strong>
&lt;/h4>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Initiative&lt;/th>
&lt;th>Owner&lt;/th>
&lt;th>Execution Plan&lt;/th>
&lt;th>Evaluation Method&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Requirement Freeze Mechanism&lt;/strong>&lt;br>- Lock core functional requirements 3 days before each iteration&lt;br>- Hardware integration requirements are jointly reviewed by the PO and the hardware team to form interface documents&lt;/td>
&lt;td>PO, hardware team lead&lt;/td>
&lt;td>Sign the requirements baseline document at the iteration planning meeting&lt;br>Share hardware interface documents via Confluence&lt;/td>
&lt;td>Reduce requirement changes by 50%&lt;br>Interface document version change records are traceable&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Automated Test Case Tiering Strategy&lt;/strong>&lt;br>- L0 (core business flows): mandatory full automation&lt;br>- L1 (high-frequency usage scenarios): prioritized for automation&lt;br>- L2 (edge scenarios): manual verification&lt;/td>
&lt;td>Test Engineer&lt;br>(Lead)&lt;br>Android Developer&lt;br>(Support)&lt;/td>
&lt;td>Use Allure to label case tiers&lt;br>Daily builds prioritize running L0 cases&lt;/td>
&lt;td>100% pass rate of L0 cases as the test-submission exit criterion&lt;br>Reduce automation execution time by 40%&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Developer Self-Testing Responsibility&lt;/strong>&lt;br>- Code submitted by developers must include unit tests (coverage ≥60%)&lt;br>- API tests are maintained by back-end engineers in Swagger&lt;/td>
&lt;td>Android Developer&lt;br>Back-end Engineer&lt;/td>
&lt;td>Include unit tests as a code review checklist item&lt;br>Link Postman API cases with the code repository&lt;/td>
&lt;td>Raise the smoke-test pass rate of submitted builds to 80%&lt;br>Reduce the API defect rate by 30%&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Hardware Compatibility Mock Service&lt;/strong>&lt;br>- Develop a simulator based on the hardware protocol&lt;br>- Decouple automated testing from real devices&lt;/td>
&lt;td>Test Engineer&lt;br>(Lead)&lt;br>Hardware team provides protocol documents&lt;/td>
&lt;td>Develop a Bluetooth protocol simulator using Python&lt;br>Automatically start the Mock service during Jenkins builds&lt;/td>
&lt;td>Reduce test blockages caused by hardware dependencies to zero&lt;br>Raise automation stability to 95%&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Defect Severity Management&lt;/strong>&lt;br>- P0 defects: respond within 2 hours&lt;br>- P1 defects: must be fixed in the current iteration&lt;br>- Residual defects require the PO to sign off on the risk&lt;/td>
&lt;td>Test Engineer&lt;br>(Classification)&lt;br>Developer&lt;br>(Fix)&lt;/td>
&lt;td>Configure automated defect workflow rules in Jira&lt;br>Sync the progress of the top 3 defects at the daily stand-up&lt;/td>
&lt;td>Shorten the average defect-fix cycle to 8 hours&lt;br>Reduce the number of backlogged defects by 60%&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;hr>
&lt;h4 id="3-risks-and-responses">&lt;strong>3. Risks and Responses&lt;/strong>
&lt;/h4>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Risk&lt;/th>
&lt;th>Response&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Developers resist unit testing&lt;/td>
&lt;td>- Xiao Li (the system designer) demonstrates writing unit tests&lt;br>- Incorporate test coverage into the DoD completion criteria&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>The hardware protocol changes frequently&lt;/td>
&lt;td>- Require the hardware team to notify of protocol changes 3 days in advance&lt;br>- Design a version compatibility mechanism for the Mock service&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>UE design delays affect UI testing&lt;/td>
&lt;td>- Agree with the UE designer: deliver UI element ID specifications together with the visual drafts&lt;br>- Use a screenshot comparison tool with a 10% pixel-difference tolerance&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;hr>
&lt;h4 id="4-external-support-requirements">&lt;strong>4. External Support Requirements&lt;/strong>
&lt;/h4>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Type&lt;/th>
&lt;th>Specific Requirements&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Tools&lt;/td>
&lt;td>- Apply for a BrowserStack mobile cloud testing platform license&lt;br>- Purchase an Xray test case management plugin license&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>People&lt;/td>
&lt;td>- The hardware team designates a protocol liaison&lt;br>- A DevOps engineer optimizes the CI/CD pipeline&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Training&lt;/td>
&lt;td>- Invite a unit testing expert to run a TDD workshop&lt;br>- Internal training on advanced Appium usage&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;hr>
&lt;h4 id="5-effect-evaluation-milestones">&lt;strong>5. Effect Evaluation Milestones&lt;/strong>
&lt;/h4>&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Milestone&lt;/th>
&lt;th>Verification Criteria&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Mid-iteration 5&lt;/td>
&lt;td>- L0 automated cases cover all core business flows&lt;br>- Unit test coverage ≥40%&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>End of iteration 5&lt;/td>
&lt;td>- Automation coverage ≥25%&lt;br>- Regression testing time ≤8 hours per run&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>End of iteration 6&lt;/td>
&lt;td>- Automation coverage ≥40%&lt;br>- Zero fatal defects in the production environment&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;hr>
&lt;p>&lt;strong>Notes on Key Execution Points:&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Daily Quality Dashboard&lt;/strong>: Hang the automation execution rate / defect trend chart in the team war room&lt;/li>
&lt;li>&lt;strong>Quality Gate Mechanism&lt;/strong>: Code merge requests must pass L0 cases plus SonarQube checks&lt;/li>
&lt;li>&lt;strong>Shift-Left Testing Practice&lt;/strong>: Test engineers produce a test-point matrix as soon as they participate in requirement reviews&lt;/li>
&lt;/ol>
&lt;p>This plan requires the whole team to sign a quality commitment letter. It is recommended that, at the iteration retrospective, the team use the &amp;ldquo;5 Whys analysis&amp;rdquo; to reach a consensus on improvement regarding the current quality issues.&lt;/p>
&lt;p>As we can see, we have obtained an improvement plan that is highly targeted and quite feasible. Based on the team&amp;rsquo;s current situation, we can actually put it into implementation after some fine-tuning.&lt;/p>
&lt;p>So making good use of AI prompt frameworks can not only help us get assistance on specific tasks, but also provide tremendous support for overall improvement initiatives of this kind.&lt;/p>
&lt;p>Reply with &amp;ldquo;prompt framework&amp;rdquo; to get the complete prompt example shown above. Regarding more practical applications of AI at work, everyone is also welcome to leave comments or join the group to discuss!&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/qrcode_for_gh_e12c318badb4_258%20%281%29.jpg"
loading="lazy"
>
&lt;/p></description></item><item><title>Integrating the DeepSeek API into Code to Run Tests</title><link>https://chengxiaqiucao.github.io/en/post/068-%E4%BB%A3%E7%A0%81%E4%B8%AD%E9%9B%86%E6%88%90deepseekapi%E6%89%A7%E8%A1%8C%E6%B5%8B%E8%AF%95/</link><pubDate>Wed, 19 Mar 2025 14:05:03 +0800</pubDate><guid>https://chengxiaqiucao.github.io/en/post/068-%E4%BB%A3%E7%A0%81%E4%B8%AD%E9%9B%86%E6%88%90deepseekapi%E6%89%A7%E8%A1%8C%E6%B5%8B%E8%AF%95/</guid><description>&lt;p>In a previous article&lt;/p>
&lt;p>&lt;a class="link" href="https://chengxiaqiucao.github.io/post/52-%E7%94%A8deepseek&amp;#43;vscode%E8%87%AA%E5%8A%A8%E5%AE%8C%E6%88%90%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC/" target="_blank" rel="noopener"
>Automatically Generating Test Scripts with DeepSeek + VS Code&lt;/a>&lt;/p>
&lt;p>we introduced an AI plugin for VS Code that helps us automatically generate test cases.&lt;/p>
&lt;p>Now the official DeepSeek API has reopened as well, offering more possibilities for deeply leveraging large models such as DeepSeek to build applications that fit real-world work.&lt;/p>
&lt;p>Below, taking the integration of DeepSeek&amp;rsquo;s official API as an example, we will walk through a practice of calling a large model from code to automatically generate test cases and execute them.&lt;/p>
&lt;p>First, head to the API open platform from the official DeepSeek website&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/068-%E4%BB%A3%E7%A0%81%E4%B8%AD%E9%9B%86%E6%88%90deepseekapi%E6%89%A7%E8%A1%8C%E6%B5%8B%E8%AF%95/Pasted-20250319_hu_a02cc43452797fe9.webp"
width="1024"
height="531"
srcset="https://chengxiaqiucao.github.io/post/068-%E4%BB%A3%E7%A0%81%E4%B8%AD%E9%9B%86%E6%88%90deepseekapi%E6%89%A7%E8%A1%8C%E6%B5%8B%E8%AF%95/Pasted-20250319_hu_abf187e9b5055a0c.webp 480w, https://chengxiaqiucao.github.io/post/068-%E4%BB%A3%E7%A0%81%E4%B8%AD%E9%9B%86%E6%88%90deepseekapi%E6%89%A7%E8%A1%8C%E6%B5%8B%E8%AF%95/Pasted-20250319_hu_a02cc43452797fe9.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="192"
data-flex-basis="463px"
>
&lt;/p>
&lt;p>Once there, apply for an API key. DeepSeek&amp;rsquo;s pricing is still fairly low at the moment, and there are sizable discounts during certain hours.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/068-%E4%BB%A3%E7%A0%81%E4%B8%AD%E9%9B%86%E6%88%90deepseekapi%E6%89%A7%E8%A1%8C%E6%B5%8B%E8%AF%95/Pasted-20250319-1_hu_b77711537548fa64.webp"
width="1024"
height="723"
srcset="https://chengxiaqiucao.github.io/post/068-%E4%BB%A3%E7%A0%81%E4%B8%AD%E9%9B%86%E6%88%90deepseekapi%E6%89%A7%E8%A1%8C%E6%B5%8B%E8%AF%95/Pasted-20250319-1_hu_580e4efa1b933510.webp 480w, https://chengxiaqiucao.github.io/post/068-%E4%BB%A3%E7%A0%81%E4%B8%AD%E9%9B%86%E6%88%90deepseekapi%E6%89%A7%E8%A1%8C%E6%B5%8B%E8%AF%95/Pasted-20250319-1_hu_b77711537548fa64.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="141"
data-flex-basis="340px"
>
&lt;/p>
&lt;p>With this API key, we can start calling it from our code.&lt;/p>
&lt;p>The DeepSeek API is currently compatible with the OpenAI API interface.&lt;/p>
&lt;p>With the code below, combined with Python&amp;rsquo;s standard library inspect, we can have DeepSeek generate test cases directly against our code under test.&lt;/p>
&lt;p>Of course, we can also feed the corresponding requirements text to DeepSeek; the principle is similar.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="kn">import&lt;/span> &lt;span class="nn">inspect&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">openai&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">OpenAI&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Import the DeepSeek API&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">client&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">OpenAI&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">api_key&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;&amp;lt;your_deepseek_api_key&amp;gt;&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">base_url&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;https://api.deepseek.com&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Function under test, calculates BMI&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">calculate_bmi&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">weight&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">height&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="n">height&lt;/span> &lt;span class="o">&amp;lt;=&lt;/span> &lt;span class="mi">0&lt;/span> &lt;span class="ow">or&lt;/span> &lt;span class="n">weight&lt;/span> &lt;span class="o">&amp;lt;=&lt;/span> &lt;span class="mi">0&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">raise&lt;/span> &lt;span class="ne">ValueError&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;身高、体重必须大于0&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">bmi&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">weight&lt;/span> &lt;span class="o">/&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="n">height&lt;/span> &lt;span class="o">**&lt;/span> &lt;span class="mi">2&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="n">bmi&lt;/span> &lt;span class="o">&amp;lt;&lt;/span> &lt;span class="mf">18.5&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="s2">&amp;#34;竹竿！&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">elif&lt;/span> &lt;span class="mf">18.5&lt;/span> &lt;span class="o">&amp;lt;=&lt;/span> &lt;span class="n">bmi&lt;/span> &lt;span class="o">&amp;lt;&lt;/span> &lt;span class="mf">24.9&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="s2">&amp;#34;正常人&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">elif&lt;/span> &lt;span class="mi">25&lt;/span> &lt;span class="o">&amp;lt;=&lt;/span> &lt;span class="n">bmi&lt;/span> &lt;span class="o">&amp;lt;&lt;/span> &lt;span class="mf">29.9&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="s2">&amp;#34;壮士！&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">else&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="s2">&amp;#34;肥宅！&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Get the function&amp;#39;s source code via inspect&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">function_code&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">inspect&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">getsource&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">calculate_bmi&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Define the prompt based on the retrieved code&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">the_prompt&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">请针对以下代码生成基于pytest框架的测试用例：&lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">function_code&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s2">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">尽可能使用参数化测试，包含各种异常场景
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># Call the DeepSeek API using the V3 model and get the response&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">response&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">client&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">chat&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">completions&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">create&lt;/span>&lt;span class="p">(&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">model&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;deepseek-chat&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">messages&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>&lt;span class="s2">&amp;#34;role&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;system&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;content&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;You are a python testing assistant&amp;#34;&lt;/span>&lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">{&lt;/span>&lt;span class="s2">&amp;#34;role&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;user&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;content&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">the_prompt&lt;/span>&lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">],&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">max_tokens&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mi">1024&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">temperature&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mf">0.7&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">stream&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="kc">False&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">response&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">choices&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="mi">0&lt;/span>&lt;span class="p">]&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">message&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">content&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>With the code above, we can obtain the result returned by DeepSeek V3:&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;span class="lnt">33
&lt;/span>&lt;span class="lnt">34
&lt;/span>&lt;span class="lnt">35
&lt;/span>&lt;span class="lnt">36
&lt;/span>&lt;span class="lnt">37
&lt;/span>&lt;span class="lnt">38
&lt;/span>&lt;span class="lnt">39
&lt;/span>&lt;span class="lnt">40
&lt;/span>&lt;span class="lnt">41
&lt;/span>&lt;span class="lnt">42
&lt;/span>&lt;span class="lnt">43
&lt;/span>&lt;span class="lnt">44
&lt;/span>&lt;span class="lnt">45
&lt;/span>&lt;span class="lnt">46
&lt;/span>&lt;span class="lnt">47
&lt;/span>&lt;span class="lnt">48
&lt;/span>&lt;span class="lnt">49
&lt;/span>&lt;span class="lnt">50
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-markdown" data-lang="markdown">&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">To test the &lt;span class="sb">`calculate_bmi`&lt;/span> function, we can use the &lt;span class="sb">`pytest`&lt;/span> framework together with &lt;span class="sb">`pytest.mark.parametrize`&lt;/span> to implement parameterized testing. Below is a complete test case covering both normal and exceptional scenarios.
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> ``&lt;span class="sb">`python
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">import pytest
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"># Import the function under test
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">from your_module import calculate_bmi
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"># Test cases for normal scenarios
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">@pytest.mark.parametrize(&amp;#34;weight, height, expected&amp;#34;, [
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> (60, 1.75, &amp;#34;正常人&amp;#34;), # Normal BMI
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> (50, 1.75, &amp;#34;竹竿！&amp;#34;), # Low BMI
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> (80, 1.75, &amp;#34;壮士！&amp;#34;), # High BMI
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> (100, 1.75, &amp;#34;肥宅！&amp;#34;), # Very high BMI
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">])
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">def test_calculate_bmi_normal(weight, height, expected):
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> assert calculate_bmi(weight, height) == expected
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"># Test cases for exceptional scenarios
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">@pytest.mark.parametrize(&amp;#34;weight, height, expected_exception&amp;#34;, [
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> (0, 1.75, ValueError), # Weight is 0
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> (60, 0, ValueError), # Height is 0
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> (-10, 1.75, ValueError), # Weight is negative
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> (60, -1.75, ValueError), # Height is negative
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">])
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">def test_calculate_bmi_exceptions(weight, height, expected_exception):
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> with pytest.raises(expected_exception):
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> calculate_bmi(weight, height)
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">`&lt;/span> `&lt;span class="sb">`
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">### Explanation:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">1. **Normal scenario tests**:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - Use `&lt;/span>pytest.mark.parametrize&lt;span class="sb">` to test different combinations of weight and height, verifying that the BMI category returned by the function is correct.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - The test cases cover normal BMI, low BMI, high BMI, and very high BMI.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">2. **Exceptional scenario tests**:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - Verify that the function raises a `&lt;/span>ValueError&lt;span class="sb">` when given invalid inputs (such as weight or height being 0 or negative).
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb"> - Use `&lt;/span>pytest.raises&lt;span class="sb">` to catch the expected exception.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">### Running the tests:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">Make sure you have `&lt;/span>pytest&lt;span class="sb">` installed, then run the following command in the terminal to execute the tests:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">`&lt;/span>`&lt;span class="sb">`bash
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">pytest test_bmi.py
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">`&lt;/span> `&lt;span class="sb">`
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">### Notes:
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- `&lt;/span>your_module&lt;span class="sb">` is the name of the module containing the `&lt;/span>calculate_bmi&lt;span class="sb">` function; replace it with the actual one.
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="sb">- Test files are usually named `&lt;/span>test_*.py&lt;span class="sb">` or `&lt;/span>*_test.py&lt;span class="sb">` so that `&lt;/span>pytest` can discover and run them automatically.
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>To make more direct use of the generated result, we can extract the code from the markdown-formatted output here, write it into a test file, and then simply invoke and execute it.&lt;/p>
&lt;p>The specific code is below; it uses a regular expression (for a detailed introduction to regular expressions, see the earlier article &lt;a class="link" href="https://chengxiaqiucao.github.io/post/58-%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E7%94%A8%E6%B3%95%E8%AF%A6%E8%A7%A3/" target="_blank" rel="noopener"
>Mastering Regular Expressions - Leaving the Newbie Village Behind!&lt;/a>) to extract the code portion.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># User configuration &lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">run_tests&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="kc">True&lt;/span> &lt;span class="c1"># Whether to run the tests &lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># If tests should be run, write the test cases to a file and execute them &lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">if&lt;/span> &lt;span class="n">run_tests&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># Create the test file &lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">test_file_name&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="s2">&amp;#34;test_calculate_bmi.py&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">with&lt;/span> &lt;span class="nb">open&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">test_file_name&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;w&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="n">encoding&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;utf-8&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="k">as&lt;/span> &lt;span class="n">test_file&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">test_file&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">write&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;import pytest&lt;/span>&lt;span class="se">\n\n&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">test_file&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">write&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sa">f&lt;/span>&lt;span class="s2">&amp;#34;from ai_test import calculate_bmi&lt;/span>&lt;span class="se">\n\n&lt;/span>&lt;span class="s2">&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">pattern&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="sa">r&lt;/span>&lt;span class="s1">&amp;#39;```python([\s\S]*?)```\n&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">test_code&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">re&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">findall&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">pattern&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">test_cases&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">re&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">DOTALL&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">test_file&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">write&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">test_code&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="mi">0&lt;/span>&lt;span class="p">])&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># Run the tests with pytest &lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">result&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">subprocess&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">run&lt;/span>&lt;span class="p">([&lt;/span>&lt;span class="s2">&amp;#34;pytest&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">test_file_name&lt;/span>&lt;span class="p">],&lt;/span> &lt;span class="n">capture_output&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="kc">True&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">text&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="kc">True&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># Print the test results &lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;测试结果:&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">result&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">stdout&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;错误信息:&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nb">print&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">result&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">stderr&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># Optional - delete the test file &lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="c1"># os.remove(test_file_name)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>In this way, we have completed an experiment in which DeepSeek automatically generates test cases, executes them immediately, and outputs the results.&lt;/p>
&lt;p>Of course, this example is fairly simple and only a preliminary experiment in fully automated unit testing with AI; practical applications still require deeper exploration!&lt;/p></description></item><item><title>Generating Test Scripts Automatically with DeepSeek and VS Code</title><link>https://chengxiaqiucao.github.io/en/post/052-%E7%94%A8deepseek+vscode%E8%87%AA%E5%8A%A8%E5%AE%8C%E6%88%90%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC/</link><pubDate>Fri, 31 Jan 2025 21:29:12 +0800</pubDate><guid>https://chengxiaqiucao.github.io/en/post/052-%E7%94%A8deepseek+vscode%E8%87%AA%E5%8A%A8%E5%AE%8C%E6%88%90%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC/</guid><description>&lt;p>DeepSeek has been all the rage in recent days, so I gave it a try myself, and it is indeed very powerful. The AI ToolKit extension for VS Code has also integrated the DeepSeek R1 model by now, so here I would like to share my hands-on experience of using DeepSeek inside VS Code to help us complete automated test scripts.&lt;/p>
&lt;h2 id="installing-ai-toolkit-and-enabling-deepseek">Installing AI ToolKit and Enabling DeepSeek
&lt;/h2>&lt;p>Microsoft officially provides an AI-assistance extension, namely &lt;strong>AI ToolKit for Visual Studio Code&lt;/strong>. This extension can leverage a variety of open-source or commercial large language models, and it has now integrated the DeepSeek R1 model, allowing us to conveniently use DeepSeek within VS Code to assist with our code development.&lt;/p>
&lt;p>First, find &lt;strong>AI ToolKit&lt;/strong> in the extension marketplace and complete the installation.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/052-%E7%94%A8deepseek&amp;#43;vscode%E8%87%AA%E5%8A%A8%E5%AE%8C%E6%88%90%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC/Pasted-20250131-1_hu_80a4080bdce14516.webp"
width="1024"
height="762"
srcset="https://chengxiaqiucao.github.io/post/052-%E7%94%A8deepseek&amp;#43;vscode%E8%87%AA%E5%8A%A8%E5%AE%8C%E6%88%90%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC/Pasted-20250131-1_hu_83c7c90fc0a4da7a.webp 480w, https://chengxiaqiucao.github.io/post/052-%E7%94%A8deepseek&amp;#43;vscode%E8%87%AA%E5%8A%A8%E5%AE%8C%E6%88%90%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC/Pasted-20250131-1_hu_80a4080bdce14516.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="134"
data-flex-basis="322px"
>
&lt;/p>
&lt;p>Once the extension is installed, on its page select the Models page in the Catalog, and use the DeepSeek-R1 model by applying the filters &lt;code>hosted by Github&lt;/code> and &lt;code>publisher Deepseek&lt;/code>.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/052-%E7%94%A8deepseek&amp;#43;vscode%E8%87%AA%E5%8A%A8%E5%AE%8C%E6%88%90%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC/Pasted-20250131_hu_e3e7ad0fbb15686b.webp"
width="1024"
height="759"
srcset="https://chengxiaqiucao.github.io/post/052-%E7%94%A8deepseek&amp;#43;vscode%E8%87%AA%E5%8A%A8%E5%AE%8C%E6%88%90%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC/Pasted-20250131_hu_7c65f4ac553f5fc7.webp 480w, https://chengxiaqiucao.github.io/post/052-%E7%94%A8deepseek&amp;#43;vscode%E8%87%AA%E5%8A%A8%E5%AE%8C%E6%88%90%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC/Pasted-20250131_hu_e3e7ad0fbb15686b.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="134"
data-flex-basis="323px"
>
&lt;/p>
&lt;h2 id="ai-assisted-script-generation">AI-Assisted Script Generation
&lt;/h2>&lt;p>With the DeepSeek model available, we can create a new playground and let DeepSeek generate automation scripts for us. Below are the test scripts targeting saucedemo that I had DeepSeek generate.&lt;/p>
&lt;p>&lt;img src="https://chengxiaqiucao.github.io/post/052-%E7%94%A8deepseek&amp;#43;vscode%E8%87%AA%E5%8A%A8%E5%AE%8C%E6%88%90%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC/Pasted-20250131-2_hu_220f0860bd1a50dd.webp"
width="1024"
height="563"
srcset="https://chengxiaqiucao.github.io/post/052-%E7%94%A8deepseek&amp;#43;vscode%E8%87%AA%E5%8A%A8%E5%AE%8C%E6%88%90%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC/Pasted-20250131-2_hu_552bbdfbd6046617.webp 480w, https://chengxiaqiucao.github.io/post/052-%E7%94%A8deepseek&amp;#43;vscode%E8%87%AA%E5%8A%A8%E5%AE%8C%E6%88%90%E6%B5%8B%E8%AF%95%E8%84%9A%E6%9C%AC/Pasted-20250131-2_hu_220f0860bd1a50dd.webp 1024w"
loading="lazy"
class="gallery-image"
data-flex-grow="182"
data-flex-basis="436px"
>
&lt;/p>
&lt;h3 id="thinking-process">Thinking Process
&lt;/h3>&lt;p>Hmm, I now need to help design an automated testing project based on pytest and Playwright, targeting the login and checkout flows of saucedemo.com, using the POM pattern, with user data stored in user.yml, and also covering exceptional scenarios. Alright, I&amp;rsquo;ll take it step by step.&lt;/p>
&lt;p>First, I should determine the project structure. With the POM pattern, there are usually page objects, test cases, configuration files, data files, and so on. The directory structure might look like this:&lt;/p>
&lt;ul>
&lt;li>tests/
&lt;ul>
&lt;li>pages/
&lt;ul>
&lt;li>login_page.py&lt;/li>
&lt;li>inventory_page.py&lt;/li>
&lt;li>cart_page.py&lt;/li>
&lt;li>checkout_page.py&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>test_login.py&lt;/li>
&lt;li>test_checkout.py&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>conftest.py&lt;/li>
&lt;li>user.yml&lt;/li>
&lt;li>pytest.ini&lt;/li>
&lt;/ul>
&lt;p>Then, the user data is stored in user.yml, which should contain different user types, such as a standard user, a locked user, a wrong password, a missing user, and so on. The test cases then need to read this data.&lt;/p>
&lt;p>Next comes the implementation of the Page Object Model. Each page—such as the login page, inventory page, cart page, and checkout page—has its own class that encapsulates elements and operations. For example, LoginPage has methods for the username and password inputs, the login button, and error messages.&lt;/p>
&lt;p>The test cases should use pytest&amp;rsquo;s parametrization to cover different user scenarios, such as a successful login, an invalid password, a locked user, and so on. At the same time, the checkout flow needs tests for the normal path, and possibly cases where the information is filled in incompletely.&lt;/p>
&lt;p>Then consider setting up Playwright fixtures in conftest.py, such as the browser, page, and the fixtures for each page object. For example, before each test, navigate to the login page, and after login to the inventory page, so that preconditions can be handled.&lt;/p>
&lt;p>As for exceptional scenarios, they include various error messages during login, and form validation during checkout, such as the first name being required. These test cases need to be written, and it must be verified that the error prompts are correct.&lt;/p>
&lt;p>How should the user data be loaded? Possibly the pyYAML library can be used to read the user.yml file, which holds the data for different users. During testing, use @pytest.mark.parametrize to feed in different user data.&lt;/p>
&lt;p>For example, the user data is divided into keys such as valid_users, invalid_password, and locked_user. When testing login, parametrize these cases to trigger different test cases.&lt;/p>
&lt;p>When testing the checkout flow, you may need to log in first, then add a product to the cart, go to the cart, enter the checkout page, fill in the information, and complete the checkout. In this case, the normal test cases need valid data, while exceptional cases—such as leaving certain fields blank—need to verify the error prompts.&lt;/p>
&lt;p>We also need to handle element selectors and Playwright&amp;rsquo;s locating methods, such as using CSS selectors or text-based locating. For example, the login page may locate the username and password inputs by id.&lt;/p>
&lt;p>In addition, does the state need to be cleaned up after a test? For example, the products in the cart, or whether a logout is needed, or keeping each test case independent—fixtures may be used to ensure each one&amp;rsquo;s own state.&lt;/p>
&lt;p>It may also be necessary to handle asynchronous operations, but Playwright handles waiting automatically, so no extra handling is needed for page navigation or element clicks.&lt;/p>
&lt;p>Now, the concrete steps:&lt;/p>
&lt;ol>
&lt;li>Create the project structure and install dependencies: pytest, playwright, pyyaml.&lt;/li>
&lt;li>Write user.yml containing different types of user data.&lt;/li>
&lt;li>Implement the Page classes for each page, including element locating and operation methods.&lt;/li>
&lt;li>Define fixtures in conftest.py, such as initializing the page and creating instances of each page object.&lt;/li>
&lt;li>Write test cases, parametrize the user data, and cover both normal and exceptional flows.&lt;/li>
&lt;li>Handle waits and assertions in the tests to ensure elements exist or text is correct.&lt;/li>
&lt;/ol>
&lt;p>We need to check whether the test cases cover the following scenarios:&lt;/p>
&lt;p>Login:&lt;/p>
&lt;ul>
&lt;li>Successful login with the correct username and password.&lt;/li>
&lt;li>An incorrect password triggers an error message.&lt;/li>
&lt;li>A locked user cannot log in.&lt;/li>
&lt;li>An empty username or password triggers an error.&lt;/li>
&lt;/ul>
&lt;p>Checkout:&lt;/p>
&lt;ul>
&lt;li>Filling in all the information normally completes the order.&lt;/li>
&lt;li>A missing required field (e.g., an empty first name) triggers an error.&lt;/li>
&lt;li>The cancel-order flow.&lt;/li>
&lt;/ul>
&lt;p>Now, what should the structure of user.yml look like?&lt;/p>
&lt;p>Possibly like this:&lt;/p>
&lt;p>users: valid_user: username: standard_user password: secret_sauce invalid_password_user: username: standard_user password: wrongpass locked_user: username: locked_out_user password: secret_sauce missing_username: username: &amp;quot;&amp;quot; password: secret_sauce missing_password: username: standard_user password: &amp;quot;&amp;quot;&lt;/p>
&lt;p>When testing login, parametrize these cases. For example, for valid_user, login should succeed and redirect to /inventory.html. For invalid_password, it displays Epic sadface: Username and password do not match. For a locked user, it shows Epic sadface: Sorry, this user has been locked out. A missing username or password shows the corresponding error message.&lt;/p>
&lt;p>For the checkout flow, the feasible steps are:&lt;/p>
&lt;p>After logging in, add a product to the cart, click the cart icon, enter the cart page, click the checkout button, fill in the information, continue, and finish.&lt;/p>
&lt;p>So the test cases need to parametrize whether the information filled in is correct. For example:&lt;/p>
&lt;p>Information for the normal case:&lt;/p>
&lt;p>first_name: John last_name: Doe zip: 12345&lt;/p>
&lt;p>For an exceptional case, such as leaving the first name blank, whether an error is shown.&lt;/p>
&lt;p>When writing these tests, you need to use the page object methods to complete each step, such as adding a product, going to the cart, filling in the information, the continue button, and so on.&lt;/p>
&lt;p>Potential problem areas:&lt;/p>
&lt;p>Whether elements are located correctly, especially whether dynamically generated content or asynchronously loaded parts need waiting. However, Playwright has an automatic waiting mechanism, so as long as elements are selected correctly, there should be no problem.&lt;/p>
&lt;p>The places that need assertions include: whether the page URL after login is correct, whether the confirmation message after the order is completed exists, and whether the error prompt displays the correct text.&lt;/p>
&lt;p>For example, after a successful login it should redirect to /inventory.html; after checkout is completed it should display &amp;ldquo;Thank you for your order&amp;rdquo;.&lt;/p>
&lt;p>Also, the cart may need to be cleaned up, but since each test may run independently, or each test starts a new session, this can be handled in a fixture—for example, logging in and resetting the state before each test?&lt;/p>
&lt;p>Or use a beforeEach-like fixture so that each test case starts in a certain state—for example, the page after login.&lt;/p>
&lt;p>In addition, testing the shopping flow requires adding products to the cart, so the inventory page class needs a method for adding a product.&lt;/p>
&lt;p>Page class example:&lt;/p>
&lt;p>InventoryPage can have a method for adding a certain product, such as clicking the &amp;ldquo;Add to cart&amp;rdquo; button—for example, locating the corresponding button by the product name. However, this may be rather complex; perhaps a generic method on the page would be better.&lt;/p>
&lt;p>Alternatively, InventoryPage has a method add_item_to_cart(item_name) used to click the add button for the corresponding product. This requires using Playwright&amp;rsquo;s locating methods, for example:&lt;/p>
&lt;p>def add_item_to_cart(self, item_name): self.page.locator(f&amp;quot;text={item_name}&amp;quot;).locator(&amp;ldquo;xpath=..&amp;rdquo;).locator(&amp;ldquo;button&amp;rdquo;).click()&lt;/p>
&lt;p>However, this may need to be determined based on the actual DOM structure. The inspector may be needed to examine the element structure.&lt;/p>
&lt;p>For example, the structure of each product item might look like:&lt;/p>
&lt;div class="inventory_item"> &lt;div class="inventory_item_name">Sauce Labs Backpack&lt;/div> &lt;button class="btn btn_primary">Add to cart&lt;/button> &lt;/div>
&lt;p>So, find the corresponding name element, then find the button within its parent element.&lt;/p>
&lt;p>Or, a simpler approach is that each product&amp;rsquo;s &amp;ldquo;Add to cart&amp;rdquo; button has a different id, such as add-to-cart-sauce-labs-backpack, or another attribute. It depends on the actual structure of the site.&lt;/p>
&lt;p>The page after login may have multiple products, and the add button corresponding to each product may need to be located via its text, or through other attributes.&lt;/p>
&lt;p>Now, we need to actually examine the structure of saucedemo.com. Playwright&amp;rsquo;s code generation feature may be used to obtain the correct selectors.&lt;/p>
&lt;p>Suppose, for example, that the id of each product&amp;rsquo;s &amp;ldquo;Add to cart&amp;rdquo; button is dynamically generated or similar—for instance, for &amp;ldquo;Sauce Labs Backpack&amp;rdquo; the corresponding button&amp;rsquo;s id might be add-to-cart-sauce-labs-backpack—then we can locate it directly by this id.&lt;/p>
&lt;p>In that case, InventoryPage can have a method:&lt;/p>
&lt;p>def add_product_to_cart(self, product_name): product_id = product_name.lower().replace(&amp;rsquo; &amp;lsquo;, &amp;lsquo;-&amp;rsquo;) self.page.click(f&amp;quot;#add-to-cart-{product_id}&amp;quot;)&lt;/p>
&lt;p>Of course, this requires checking whether the actual site structure is correct.&lt;/p>
&lt;p>Suppose the correct product example here is Sauce Labs Backpack and its id is indeed like this; then the method works.&lt;/p>
&lt;p>Also, whether the count on the cart icon is correct—after a product is added, the cart icon shows a count of 1. When entering the cart page, whether the corresponding product is present.&lt;/p>
&lt;p>Note that after each operation, a page change may require a new Page object instance. For example, after clicking the cart in InventoryPage, it navigates to CartPage, so that operation should return an instance of CartPage so that operations can continue.&lt;/p>
&lt;p>Then handling the return values of methods may become an issue. For example:&lt;/p>
&lt;p>The method in InventoryPage:&lt;/p>
&lt;p>def go_to_cart(self): self.page.click(&amp;quot;.shopping_cart_link&amp;quot;) return CartPage(self.page)&lt;/p>
&lt;p>Like this, each navigation action returns a new Page object.&lt;/p>
&lt;p>This requires handling the return of the corresponding page object in the methods of each page.&lt;/p>
&lt;p>Then comes the assembly of the test flow:&lt;/p>
&lt;p>When testing checkout, there may be many steps, so a large test case needs to be written and carried out step by step:&lt;/p>
&lt;p>For example:&lt;/p>
&lt;p>def test_checkout_process(login_page, inventory_page, checkout_data): # Log in login_page.login(&amp;ldquo;standard_user&amp;rdquo;, &amp;ldquo;secret_sauce&amp;rdquo;) # Add a product inventory_page.add_product_to_cart(&amp;ldquo;Sauce Labs Backpack&amp;rdquo;) inventory_page.go_to_cart() # Enter the cart page and click checkout cart_page.click_checkout() # Fill in the checkout information checkout_page.fill_shipping_info(checkout_data) checkout_page.continue_to_overview() # Confirm the order checkout_page.finish_checkout() # Assert whether it succeeded assert checkout_page.get_order_confirmation() == &amp;ldquo;Thank you for your order!&amp;rdquo;&lt;/p>
&lt;p>Of course, this may involve navigation across many pages, and each pair of pages needs to be connected with the corresponding methods.&lt;/p>
&lt;p>As for exceptional scenarios, for example, when filling in the information, if the first name is not entered and continue is clicked, an error prompt appears.&lt;/p>
&lt;p>In this case, the test case may parametrize different data, for example:&lt;/p>
&lt;p>@pytest.mark.parametrize(&amp;ldquo;first_name, last_name, zip_code, error_message&amp;rdquo;, [ (&amp;quot;&amp;quot;, &amp;ldquo;Doe&amp;rdquo;, &amp;ldquo;12345&amp;rdquo;, &amp;ldquo;Error: First Name is required&amp;rdquo;), (&amp;ldquo;John&amp;rdquo;, &amp;ldquo;&amp;rdquo;, &amp;ldquo;12345&amp;rdquo;, &amp;ldquo;Error: Last Name is required&amp;rdquo;), (&amp;ldquo;John&amp;rdquo;, &amp;ldquo;Doe&amp;rdquo;, &amp;ldquo;&amp;rdquo;, &amp;ldquo;Error: Postal Code is required&amp;rdquo;), ]) def test_checkout_missing_fields(&amp;hellip;, first_name, last_name, zip_code, error_message): # Omit the corresponding field when filling in the information checkout_page.fill_shipping_info(first_name, last_name, zip_code) checkout_page.continue_to_overview() assert checkout_page.get_error_message() == error_message&lt;/p>
&lt;p>It may also be necessary to consider whether the error-message element is located correctly, and whether an error prevents moving to the next step.&lt;/p>
&lt;p>Now, the question may be how to organize this data and the page methods.&lt;/p>
&lt;p>In addition, regarding loading the user data, the test cases need to load it from a YAML file. One possible approach is to write a fixture in conftest.py that reads the YAML data and then parametrizes the test cases.&lt;/p>
&lt;p>But pytest&amp;rsquo;s parametrization may need to be handled in a specific way, possibly converting the YAML data into test parameters, or using an external data source to parametrize the tests.&lt;/p>
&lt;p>For example, read all the user data from user.yml in conftest.py and create a parametrized fixture for the login tests.&lt;/p>
&lt;p>Or, the data in the YAML file can be read directly in the test cases and parametrized.&lt;/p>
&lt;p>For example:&lt;/p>
&lt;p>import yaml&lt;/p>
&lt;p>def load_users(): with open(&amp;lsquo;user.yml&amp;rsquo;) as f: data = yaml.safe_load(f) return data[&amp;lsquo;users&amp;rsquo;]&lt;/p>
&lt;p>Then in the test case use:&lt;/p>
&lt;p>@pytest.mark.parametrize(&amp;ldquo;user&amp;rdquo;, [ (&amp;ldquo;valid_user&amp;rdquo;), (&amp;ldquo;invalid_password_user&amp;rdquo;), (&amp;ldquo;locked_user&amp;rdquo;), # &amp;hellip; other cases ], indirect=True) def test_login(login_page, user): login_page.login(user[&amp;lsquo;username&amp;rsquo;], user[&amp;lsquo;password&amp;rsquo;]) # assertions, etc.&lt;/p>
&lt;p>However, how to convert the data into parameters may require more careful handling, such as extracting each user data item into parameters for each test instance.&lt;/p>
&lt;p>A possibly better approach is to write the different user situations as separate test data items. For example, list the keys of the different user-type data, then load the corresponding parameters from the data based on these keys.&lt;/p>
&lt;p>Or, when parametrizing, import all the user data as parameters.&lt;/p>
&lt;p>For example:&lt;/p>
&lt;p>import yaml import pytest&lt;/p>
&lt;p>with open(&amp;lsquo;user.yml&amp;rsquo;) as f: user_data = yaml.safe_load(f)[&amp;lsquo;users&amp;rsquo;]&lt;/p>
&lt;p>login_test_data = [ (user_data[&amp;lsquo;valid_user&amp;rsquo;], True, None), # normal user, login succeeds, no error (user_data[&amp;lsquo;invalid_password_user&amp;rsquo;], False, &amp;lsquo;Epic sadface: Username and password do not match&amp;rsquo;), (user_data[&amp;rsquo;locked_user&amp;rsquo;], False, &amp;lsquo;Epic sadface: Sorry, this user has been locked out.&amp;rsquo;), # &amp;hellip; other cases ]&lt;/p>
&lt;p>@pytest.mark.parametrize(&amp;ldquo;user, success, error_msg&amp;rdquo;, login_test_data) def test_login_user(login_page, user, success, error_msg): login_page.navigate() login_page.login(user[&amp;lsquo;username&amp;rsquo;], user[&amp;lsquo;password&amp;rsquo;]) if success: assert login_page.current_url == &amp;lsquo;&lt;a class="link" href="https://www.saucedemo.com/inventory.html%27" target="_blank" rel="noopener"
>https://www.saucedemo.com/inventory.html'&lt;/a> else: assert login_page.get_error_message() == error_msg&lt;/p>
&lt;p>In this case, each user data item in user.yml needs to have an error key, or the mapping of error messages needs to be handled during the preparation of the parametrization.&lt;/p>
&lt;p>However, this way of passing parameters may be more flexible, allowing the expected result to be specified at the same time.&lt;/p>
&lt;p>For the YAML structure, more detailed data items may be needed, with each user data item containing the expected error message.&lt;/p>
&lt;p>For example, part of user.yml:&lt;/p>
&lt;p>valid_user: username: standard_user password: secret_sauce expected: success: true error: null&lt;/p>
&lt;p>invalid_password_user: username: standard_user password: wrong expected: success: false error: &amp;ldquo;Epic sadface: Username and password do not match&amp;rdquo;&lt;/p>
&lt;p>locked_user: username: locked_out_user password: secret_sauce expected: success: false error: &amp;ldquo;Epic sadface: Sorry, this user has been locked out.&amp;rdquo;&lt;/p>
&lt;p>This makes the parametrization more structured. But when writing the YAML, the expected result of each case needs to be considered.&lt;/p>
&lt;p>In this way, the parameters of the test cases may be the structure read directly from the YAML, and then the test case parameters are generated by parsing the different user groups.&lt;/p>
&lt;p>However, this may be somewhat complex. Another approach is to define each test case as an item in the YAML, containing the input data and the expected result.&lt;/p>
&lt;p>In short, this part may require more design.&lt;/p>
&lt;p>Then, regarding the Playwright fixture setup, in conftest.py you can use the fixtures provided by pytest-playwright—for example, the page fixture from the pytest-playwright plugin. However, this may require installing the pytest-playwright library and running the playwright installation step.&lt;/p>
&lt;p>The dependencies to install include:&lt;/p>
&lt;p>pytest-playwright playwright pyyaml&lt;/p>
&lt;p>Run playwright install to install the browsers.&lt;/p>
&lt;p>Then, in conftest.py, define how to initialize each page object and inject them into the test cases as fixtures.&lt;/p>
&lt;p>For example:&lt;/p>
&lt;p>import pytest from playwright.sync_api import Page from pages.login_page import LoginPage from pages.inventory_page import InventoryPage&lt;/p>
&lt;h5 id="importing-other-pages">Importing Other Pages
&lt;/h5>&lt;p>@pytest.fixture def login_page(page: Page): return LoginPage(page)&lt;/p>
&lt;p>@pytest.fixture def inventory_page(page: Page): return InventoryPage(page)&lt;/p>
&lt;p>And so on. In this way, if a test case needs to use a particular page object, it can simply declare the required fixture in its parameters.&lt;/p>
&lt;p>For example, a test case function may receive login_page and inventory_page as parameters.&lt;/p>
&lt;p>Next, examples of each Page class.&lt;/p>
&lt;p>The LoginPage class looks like this:&lt;/p>
&lt;p>class LoginPage: def &lt;strong>init&lt;/strong>(self, page): self.page = page self.username_input = page.locator(&amp;quot;#user-name&amp;quot;) self.password_input = page.locator(&amp;quot;#password&amp;quot;) self.login_button = page.locator(&amp;quot;#login-button&amp;quot;) self.error_message = page.locator(&amp;quot;.error-message-container&amp;quot;)&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">def navigate(self):
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> self.page.goto(&amp;#34;https://www.saucedemo.com&amp;#34;)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">def login(self, username, password):
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> self.username_input.fill(username)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> self.password_input.fill(password)
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> self.login_button.click()
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">def get_error_message(self):
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> return self.error_message.inner_text()
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>But in reality the selectors need to be adjusted according to the actual HTML structure of saucedemo.com. For example, the error-message element might be a div.error-message-container with a data-test=&amp;ldquo;error&amp;rdquo; attribute, whose text may be inside a child element.&lt;/p>
&lt;p>For instance, on the actual site, the HTML of the error message might be:&lt;/p>
&lt;div class="error-message-container" data-test="error"> &lt;h3>Epic sadface: Username and password do not match any user in this service&lt;/h3> &lt;button class="error-button" data-test="close-error-message">&lt;/button> &lt;/div>
&lt;p>Then, the error_message locator needs to target the text of the h3 element. Or, target the entire container and use inner_text() to get the text.&lt;/p>
&lt;p>Or, the correct selector might be:&lt;/p>
&lt;p>error_message = page.locator(&amp;rsquo;[data-test=&amp;ldquo;error&amp;rdquo;]&amp;rsquo;)&lt;/p>
&lt;p>But Playwright supports multiple ways of selecting, such as using the data-testid attribute, so when writing the code you need to verify the correct way of locating elements.&lt;/p>
&lt;p>So a possibly better way is to use the data-test attribute to select elements—for example, the data-test attributes on the login page:&lt;/p>
&lt;p>Username input: data-test=&amp;ldquo;username&amp;rdquo;&lt;/p>
&lt;p>Password input: data-test=&amp;ldquo;password&amp;rdquo;&lt;/p>
&lt;p>Login button: data-test=&amp;ldquo;login-button&amp;rdquo;&lt;/p>
&lt;p>Error-message element: data-test=&amp;ldquo;error&amp;rdquo;, so its element can be located as:&lt;/p>
&lt;p>self.error_message = page.locator(&amp;rsquo;[data-test=&amp;ldquo;error&amp;rdquo;]&amp;rsquo;)&lt;/p>
&lt;p>Then its text content can be obtained with error_message.inner_text(), which contains the key part of the error message.&lt;/p>
&lt;p>As for the other pages, such as the inventory page and the cart page:&lt;/p>
&lt;p>InventoryPage may have a method for adding a product to the cart, a method for navigating to the cart, and perhaps a display of the cart count. For example:&lt;/p>
&lt;p>class InventoryPage: def &lt;strong>init&lt;/strong>(self, page: Page): self.page = page&lt;/p>
&lt;p>def add_product_to_cart(self, product_name):
# Here we assume how the add button corresponding to the product name is located; suppose the data-test attribute has a corresponding add-to-cart button, e.g. data-test=&amp;ldquo;add-to-cart-sauce-labs-backpack&amp;rdquo;
product_id = product_name.lower().replace(&amp;rsquo; &amp;lsquo;, &amp;lsquo;-&amp;rsquo;)
self.page.locator(f&amp;rsquo;[data-test=&amp;ldquo;add-to-cart-{product_id}&amp;rdquo;]&amp;rsquo;).click()&lt;/p>
&lt;p>def get_cart_count(self):
return self.page.locator(&amp;rsquo;.shopping_cart_badge&amp;rsquo;).inner_text()&lt;/p>
&lt;p>def go_to_cart(self):
self.page.locator(&amp;rsquo;.shopping_cart_link&amp;rsquo;).click()
return CartPage(self.page)&lt;/p>
&lt;p>The CartPage class may have a checkout button:&lt;/p>
&lt;p>class CartPage: def &lt;strong>init&lt;/strong>(self, page: Page): self.page = page&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-fallback" data-lang="fallback">&lt;span class="line">&lt;span class="cl">def checkout(self):
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> self.page.locator(&amp;#39;[data-test=&amp;#34;checkout&amp;#34;]&amp;#39;).click()
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> return CheckoutPage(self.page)
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>The CheckoutPage class:&lt;/p>
&lt;p>class CheckoutPage: def &lt;strong>init&lt;/strong>(self, page: Page): self.page = page self.first_name_input = page.locator(&amp;rsquo;[data-test=&amp;ldquo;firstName&amp;rdquo;]&amp;rsquo;) self.last_name_input = page.locator(&amp;rsquo;[data-test=&amp;ldquo;lastName&amp;rdquo;]&amp;rsquo;) self.postal_code_input = page.locator(&amp;rsquo;[data-test=&amp;ldquo;postalCode&amp;rdquo;]&amp;rsquo;) self.continue_button = page.locator(&amp;rsquo;[data-test=&amp;ldquo;continue&amp;rdquo;]&amp;rsquo;) self.error_message = page.locator(&amp;rsquo;[data-test=&amp;ldquo;error&amp;rdquo;]&amp;rsquo;)&lt;/p>
&lt;p>def fill_shipping_info(self, first_name, last_name, postal_code):
self.first_name_input.fill(first_name)
self.last_name_input.fill(last_name)
self.postal_code_input.fill(postal_code)&lt;/p>
&lt;p>def continue_to_overview(self):
self.continue_button.click()&lt;/p>
&lt;p>def get_error_message(self):
return self.error_message.inner_text().strip()&lt;/p>
&lt;p>Then, on the page after the information is filled in, there may be a finish button, in the CheckoutOverviewPage class:&lt;/p>
&lt;p>class CheckoutOverviewPage: def &lt;strong>init&lt;/strong>(self, page: Page): self.page = page self.finish_button = page.locator(&amp;rsquo;[data-test=&amp;ldquo;finish&amp;rdquo;]&amp;rsquo;) self.confirmation_message = page.locator(&amp;rsquo;.complete-header&amp;rsquo;)&lt;/p>
&lt;p>def finish_checkout(self):
self.finish_button.click()&lt;/p>
&lt;p>def get_confirmation_message(self):
return self.confirmation_message.inner_text()&lt;/p>
&lt;p>Of course, these need to be adjusted according to the actual page structure, such as whether the confirmation-message element is correct.&lt;/p>
&lt;p>In this way, the overall test flow can be chained together through the methods of each page.&lt;/p>
&lt;p>Now the steps for writing the test cases:&lt;/p>
&lt;p>Testing the login flow:&lt;/p>
&lt;p>Parametrize different user data and determine whether login succeeds, or whether the correct error prompt appears.&lt;/p>
&lt;p>For example:&lt;/p>
&lt;p>In test_login.py:&lt;/p>
&lt;p>import pytest from playwright.sync_api import Page&lt;/p>
&lt;p>@pytest.mark.parametrize(&amp;ldquo;user_key, expected_success, expected_error&amp;rdquo;, [ (&amp;ldquo;valid_user&amp;rdquo;, True, None), (&amp;ldquo;invalid_password_user&amp;rdquo;, False, &amp;ldquo;Epic sadface: Username and password do not match&amp;rdquo;), (&amp;ldquo;locked_user&amp;rdquo;, False, &amp;ldquo;Epic sadface: Sorry, this user has been locked out.&amp;rdquo;), (&amp;ldquo;missing_username&amp;rdquo;, False, &amp;ldquo;Epic sadface: Username is required&amp;rdquo;), (&amp;ldquo;missing_password&amp;rdquo;, False, &amp;ldquo;Epic sadface: Password is required&amp;rdquo;), ]) def test_login(login_page, user_key, expected_success, expected_error): # Load user data from YAML; assume there is a fixture that can load all the test user data users = load_users() user = users[user_key] login_page.navigate() login_page.login(user[&amp;lsquo;username&amp;rsquo;], user[&amp;lsquo;password&amp;rsquo;])&lt;/p>
&lt;p>if expected_success:
assert login_page.page.url == &amp;ldquo;&lt;a class="link" href="https://www.saucedemo.com/inventory.html%22" target="_blank" rel="noopener"
>https://www.saucedemo.com/inventory.html"&lt;/a>
else:
assert login_page.get_error_message() == expected_error&lt;/p>
&lt;p>The load_users function needs to be written, or a fixture used to pass data to the test cases.&lt;/p>
&lt;p>Here load_users might be a fixture in conftest.py:&lt;/p>
&lt;p>import pytest import yaml&lt;/p>
&lt;p>@pytest.fixture def users(): with open(&amp;lsquo;user.yml&amp;rsquo;) as f: data = yaml.safe_load(f) return data[&amp;lsquo;users&amp;rsquo;]&lt;/p>
&lt;p>Then the test case can receive users as a fixture:&lt;/p>
&lt;p>def test_login(login_page, users, user_key, expected_success, &amp;hellip;): user = users[user_key] &amp;hellip;&lt;/p>
&lt;p>But this kind of parametrization may need to be combined with the use of indirect parameters, or the user data may need to be obtained dynamically during parametrization.&lt;/p>
&lt;p>Or, map the parametrized data to the user keys and obtain the correct user data through a dictionary.&lt;/p>
&lt;p>This may require a deeper handling of pytest&amp;rsquo;s parametrization, such as using indirect parametrization, passing the user key as a parameter, and then obtaining the corresponding user&amp;rsquo;s data inside the test function.&lt;/p>
&lt;p>Or, this way of passing parameters may not be very straightforward, and the parametrization structure may need to be redesigned.&lt;/p>
&lt;p>Perhaps the best way is to directly specify the keys of the user data in the parametrization list, and then use that key in the test case to index the corresponding data in the users fixture.&lt;/p>
&lt;p>For example:&lt;/p>
&lt;p>@pytest.mark.parametrize(&amp;ldquo;user_key, expected_success, expected_error&amp;rdquo;, [ (&amp;ldquo;valid_user&amp;rdquo;, True, None), (&amp;ldquo;invalid_password_user&amp;rdquo;, False, &amp;ldquo;Epic sadface: Username and password do not match&amp;rdquo;), (&amp;ldquo;locked_user&amp;rdquo;, False, &amp;ldquo;Epic sadface: Sorry, this user has been locked out.&amp;rdquo;), (&amp;ldquo;missing_username&amp;rdquo;, False, &amp;ldquo;Epic sadface: Username is required&amp;rdquo;), (&amp;ldquo;missing_password&amp;rdquo;, False, &amp;ldquo;Epic sadface: Password is required&amp;rdquo;), ]) def test_login(login_page, users, user_key, expected_success, expected_error): user = users[user_key] login_page.navigate() login_page.login(user[&amp;lsquo;username&amp;rsquo;], user[&amp;lsquo;password&amp;rsquo;]) if expected_success: assert login_page.page.url == &amp;ldquo;&lt;a class="link" href="https://www.saucedemo.com/inventory.html%22" target="_blank" rel="noopener"
>https://www.saucedemo.com/inventory.html"&lt;/a> else: assert login_page.get_error_message() == expected_error&lt;/p>
&lt;p>It needs to be ensured that the corresponding keys exist in user.yml and that the data for each user is correct.&lt;/p>
&lt;p>For the normal test of the checkout flow:&lt;/p>
&lt;p>In test_checkout.py:&lt;/p>
&lt;p>def test_successful_checkout(login_page, inventory_page, users): valid_user = users[&amp;lsquo;valid_user&amp;rsquo;] login_page.login(valid_user[&amp;lsquo;username&amp;rsquo;], valid_user[&amp;lsquo;password&amp;rsquo;]) inventory_page.add_product_to_cart(&amp;ldquo;Sauce Labs Backpack&amp;rdquo;) cart_page = inventory_page.go_to_cart() checkout_page = cart_page.checkout() checkout_page.fill_shipping_info(&amp;ldquo;John&amp;rdquo;, &amp;ldquo;Doe&amp;rdquo;, &amp;ldquo;12345&amp;rdquo;) checkout_page.continue_to_overview() overview_page = CheckoutOverviewPage(checkout_page.page) overview_page.finish_checkout() assert overview_page.get_confirmation_message() == &amp;ldquo;Thank you for your order!&amp;rdquo;&lt;/p>
&lt;p>This requires defining the corresponding elements and methods of the CheckoutOverviewPage class.&lt;/p>
&lt;p>For exceptional tests:&lt;/p>
&lt;p>For example, omitting a required field when filling in the information:&lt;/p>
&lt;p>@pytest.mark.parametrize(&amp;ldquo;first_name, last_name, zip_code, expected_error&amp;rdquo;, [ (&amp;rdquo;&amp;rdquo;, &amp;ldquo;Doe&amp;rdquo;, &amp;ldquo;12345&amp;rdquo;, &amp;ldquo;Error: First Name is required&amp;rdquo;), (&amp;ldquo;John&amp;rdquo;, &amp;ldquo;&amp;rdquo;, &amp;ldquo;12345&amp;rdquo;, &amp;ldquo;Error: Last Name is required&amp;rdquo;), (&amp;ldquo;John&amp;rdquo;, &amp;ldquo;Doe&amp;rdquo;, &amp;ldquo;&amp;rdquo;, &amp;ldquo;Error: Postal Code is required&amp;rdquo;), ]) def test_checkout_error_messages(login_page, inventory_page, users, first_name, last_name, zip_code, expected_error): valid_user = users[&amp;lsquo;valid_user&amp;rsquo;] login_page.login(valid_user[&amp;lsquo;username&amp;rsquo;], valid_user[&amp;lsquo;password&amp;rsquo;]) inventory_page.add_product_to_cart(&amp;ldquo;Sauce Labs Backpack&amp;rdquo;) cart_page = inventory_page.go_to_cart() checkout_page = cart_page.checkout() checkout_page.fill_shipping_info(first_name, last_name, zip_code) checkout_page.continue_to_overview() assert checkout_page.get_error_message() == expected_error&lt;/p>
&lt;p>Here, it needs to be confirmed whether the actual error prompt is text like this. For example, on the reqreal site, when the first name is left blank and you continue, whether the error prompt is really &amp;ldquo;Error: First Name is required&amp;rdquo;. The actual page needs to be examined—perhaps whether the error message is contained in a data-test=&amp;ldquo;error&amp;rdquo; element, or whether it is some other structure.&lt;/p>
&lt;p>In summary, the whole project needs:&lt;/p>
&lt;ul>
&lt;li>Correctly configure each page class of the POM.&lt;/li>
&lt;li>Correctly read the user data and parametrize the test cases.&lt;/li>
&lt;li>Handle the flows of different test scenarios, especially that the Test checkout flow may require continuous page navigation and state maintenance.&lt;/li>
&lt;li>Assert on exceptional cases, such as the correctness of error messages.&lt;/li>
&lt;/ul>
&lt;p>It may also be necessary to confirm the synchronization of page elements. Although Playwright waits automatically, for example, confirming certain elements on the page to check whether the navigation after clicking a button has completed may make things more stable.&lt;/p>
&lt;p>For some asynchronous actions, such as elements changing after a button click, no waiting is needed because Playwright has already handled it internally.&lt;/p>
&lt;p>Overall, this design should be able to cover the required automated testing needs. Next, I need to write the concrete code files based on these ideas and verify that they work correctly.&lt;/p>
&lt;h3 id="concrete-implementation">Concrete Implementation
&lt;/h3>&lt;p>To complete the automated testing of the login and checkout flows for saucedemo.com based on pytest and Playwright, following the POM pattern, here is the detailed implementation plan:&lt;/p>
&lt;h3 id="project-structure">Project Structure
&lt;/h3>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-plaintext" data-lang="plaintext">&lt;span class="line">&lt;span class="cl">project-root/
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">├── tests/
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ ├── pages/
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ │ ├── login_page.py
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ │ ├── inventory_page.py
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ │ ├── cart_page.py
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ │ ├── checkout_page.py
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ │ └── checkout_overview_page.py
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ ├── test_login.py
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">│ └── test_checkout.py
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">├── conftest.py
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">├── user.yml
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">└── pytest.ini
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="installing-dependencies">Installing Dependencies
&lt;/h3>&lt;ol>
&lt;li>Install the required libraries:&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">pip install pytest playwright pyyaml pytest-playwright
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">playwright install
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="file-implementation">File Implementation
&lt;/h3>&lt;h4 id="useryml">user.yml
&lt;/h4>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">users&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">valid_user&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">username&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">standard_user&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">password&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">secret_sauce&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">invalid_password_user&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">username&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">standard_user&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">password&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">wrong_pass&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">locked_user&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">username&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">locked_out_user&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">password&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">secret_sauce&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">missing_username&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">username&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">password&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">secret_sauce&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">missing_password&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">username&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">standard_user&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">password&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h4 id="pageslogin_pagepy">pages/login_page.py
&lt;/h4>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">LoginPage&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="fm">__init__&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">page&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">username_input&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;[data-test=&amp;#34;username&amp;#34;]&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">password_input&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;[data-test=&amp;#34;password&amp;#34;]&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">login_button&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;[data-test=&amp;#34;login-button&amp;#34;]&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">error_message&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;[data-test=&amp;#34;error&amp;#34;]&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="nf">navigate&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Navigate to the login page&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">goto&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;https://www.saucedemo.com&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="nf">login&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">username&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">password&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Fill in and submit the login form&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">username_input&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">fill&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">username&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">password_input&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">fill&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">password&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">login_button&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">click&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="nf">get_error_message&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Get the error message text&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">error_message&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">inner_text&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h4 id="pagesinventory_pagepy">pages/inventory_page.py
&lt;/h4>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">InventoryPage&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="fm">__init__&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">page&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="nf">add_product_to_cart&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">product_name&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Add the specified product to the cart&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">product_id&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">product_name&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">lower&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">replace&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39; &amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;-&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="sa">f&lt;/span>&lt;span class="s1">&amp;#39;[data-test=&amp;#34;add-to-cart-&lt;/span>&lt;span class="si">{&lt;/span>&lt;span class="n">product_id&lt;/span>&lt;span class="si">}&lt;/span>&lt;span class="s1">&amp;#34;]&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">click&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="nf">go_to_cart&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Go to the cart page&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;.shopping_cart_link&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">click&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">CartPage&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">page&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h4 id="pagescart_pagepy">pages/cart_page.py
&lt;/h4>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;span class="lnt">2
&lt;/span>&lt;span class="lnt">3
&lt;/span>&lt;span class="lnt">4
&lt;/span>&lt;span class="lnt">5
&lt;/span>&lt;span class="lnt">6
&lt;/span>&lt;span class="lnt">7
&lt;/span>&lt;span class="lnt">8
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">CartPage&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="fm">__init__&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">page&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="nf">checkout&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Go to the checkout page&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;[data-test=&amp;#34;checkout&amp;#34;]&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">click&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">CheckoutPage&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">page&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h4 id="pagescheckout_pagepy">pages/checkout_page.py
&lt;/h4>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">CheckoutPage&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="fm">__init__&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">page&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">first_name_input&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;[data-test=&amp;#34;firstName&amp;#34;]&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">last_name_input&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;[data-test=&amp;#34;lastName&amp;#34;]&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">postal_code_input&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;[data-test=&amp;#34;postalCode&amp;#34;]&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">continue_button&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;[data-test=&amp;#34;continue&amp;#34;]&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">error_message&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;[data-test=&amp;#34;error&amp;#34;]&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="nf">fill_shipping_info&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">first_name&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">last_name&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">postal_code&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Fill in the shipping information&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">first_name_input&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">fill&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">first_name&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">last_name_input&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">fill&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">last_name&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">postal_code_input&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">fill&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">postal_code&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="nf">continue_to_overview&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Submit and go to the order overview&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">continue_button&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">click&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="nf">get_error_message&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Get the error message text&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">error_message&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">inner_text&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h4 id="pagescheckout_overview_pagepy">pages/checkout_overview_page.py
&lt;/h4>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="k">class&lt;/span> &lt;span class="nc">CheckoutOverviewPage&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="fm">__init__&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">page&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">finish_button&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;[data-test=&amp;#34;finish&amp;#34;]&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">confirmation_message&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">locator&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;.complete-header&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="nf">finish_checkout&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Complete the order&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">finish_button&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">click&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">def&lt;/span> &lt;span class="nf">get_confirmation_message&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="bp">self&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="s2">&amp;#34;&amp;#34;&amp;#34;Get the order completion confirmation message&amp;#34;&amp;#34;&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="bp">self&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">confirmation_message&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">inner_text&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h4 id="conftestpy">conftest.py
&lt;/h4>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;span class="lnt">29
&lt;/span>&lt;span class="lnt">30
&lt;/span>&lt;span class="lnt">31
&lt;/span>&lt;span class="lnt">32
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="kn">import&lt;/span> &lt;span class="nn">pytest&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">import&lt;/span> &lt;span class="nn">yaml&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">playwright.sync_api&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">Page&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">tests.pages.login_page&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">LoginPage&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">tests.pages.inventory_page&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">InventoryPage&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">tests.pages.cart_page&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">CartPage&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">tests.pages.checkout_page&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">CheckoutPage&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@pytest.fixture&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">scope&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="s2">&amp;#34;session&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">users&lt;/span>&lt;span class="p">():&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">with&lt;/span> &lt;span class="nb">open&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;user.yml&amp;#39;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s1">&amp;#39;r&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="k">as&lt;/span> &lt;span class="n">f&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">data&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">yaml&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">safe_load&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">f&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">data&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;users&amp;#39;&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@pytest.fixture&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">login_page&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">page&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">Page&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">login_page&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">LoginPage&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">page&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">login_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">navigate&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">login_page&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@pytest.fixture&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">inventory_page&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">login_page&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">LoginPage&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">users&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">login_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">login&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">users&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;valid_user&amp;#39;&lt;/span>&lt;span class="p">][&lt;/span>&lt;span class="s1">&amp;#39;username&amp;#39;&lt;/span>&lt;span class="p">],&lt;/span> &lt;span class="n">users&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;valid_user&amp;#39;&lt;/span>&lt;span class="p">][&lt;/span>&lt;span class="s1">&amp;#39;password&amp;#39;&lt;/span>&lt;span class="p">])&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">InventoryPage&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">login_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">page&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@pytest.fixture&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">cart_page&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">inventory_page&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">InventoryPage&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">inventory_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">go_to_cart&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@pytest.fixture&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">checkout_page&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">cart_page&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="n">CartPage&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">cart_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">checkout&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h4 id="test_loginpy">test_login.py
&lt;/h4>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="kn">import&lt;/span> &lt;span class="nn">pytest&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@pytest.mark.parametrize&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;user_key, expected_success, expected_error&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;valid_user&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="kc">True&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="kc">None&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;invalid_password_user&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="kc">False&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;Epic sadface: Username and password do not match&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;locked_user&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="kc">False&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;Epic sadface: Sorry, this user has been locked out.&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;missing_username&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="kc">False&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;Epic sadface: Username is required&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;missing_password&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="kc">False&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;Epic sadface: Password is required&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">])&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">test_login&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">login_page&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">users&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">user_key&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">expected_success&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">expected_error&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">user&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">users&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="n">user_key&lt;/span>&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">login_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">login&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">user&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;username&amp;#39;&lt;/span>&lt;span class="p">],&lt;/span> &lt;span class="n">user&lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="s1">&amp;#39;password&amp;#39;&lt;/span>&lt;span class="p">])&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">if&lt;/span> &lt;span class="n">expected_success&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">assert&lt;/span> &lt;span class="n">login_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">url&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="s2">&amp;#34;https://www.saucedemo.com/inventory.html&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">else&lt;/span>&lt;span class="p">:&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">assert&lt;/span> &lt;span class="n">login_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">get_error_message&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="n">expected_error&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h4 id="test_checkoutpy">test_checkout.py
&lt;/h4>&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="kn">import&lt;/span> &lt;span class="nn">pytest&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">test_successful_checkout&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">inventory_page&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">checkout_page&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">inventory_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">add_product_to_cart&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;sauce-labs-backpack&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">checkout_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">fill_shipping_info&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;John&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;Doe&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;12345&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">checkout_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">continue_to_overview&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">overview_page&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">CheckoutOverviewPage&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">checkout_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">page&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">overview_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">finish_checkout&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">assert&lt;/span> &lt;span class="n">overview_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">get_confirmation_message&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="s2">&amp;#34;Thank you for your order!&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@pytest.mark.parametrize&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;first_name, last_name, postal_code, expected_error&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;Doe&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;12345&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;Error: First Name is required&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;John&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;12345&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;Error: Last Name is required&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">(&lt;/span>&lt;span class="s2">&amp;#34;John&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;Doe&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="s2">&amp;#34;Error: Postal Code is required&amp;#34;&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">])&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">def&lt;/span> &lt;span class="nf">test_checkout_errors&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">checkout_page&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">first_name&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">last_name&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">postal_code&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">expected_error&lt;/span>&lt;span class="p">):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">checkout_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">fill_shipping_info&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">first_name&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">last_name&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">postal_code&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">checkout_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">continue_to_overview&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">assert&lt;/span> &lt;span class="n">checkout_page&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">get_error_message&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="o">==&lt;/span> &lt;span class="n">expected_error&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="key-points-and-explanation">Key Points and Explanation
&lt;/h3>&lt;ol>
&lt;li>
&lt;p>&lt;strong>POM Design Pattern&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Each page (such as the login page or the inventory page) is encapsulated as a class, with page elements and operations abstracted into methods, thereby improving code reusability and maintainability.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Data-Driven Testing&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>User data is separated from the test code and stored in a YAML file, which improves maintainability and makes it easy to add new test scenarios.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Exceptional Scenario Coverage&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Parametrized tests verify whether different erroneous inputs (such as a locked user, a wrong password, or a missing required field) trigger the correct error prompt.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Fixture Management&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>pytest fixtures are used to manage the browser and page objects, ensuring the independence of each test case and reducing duplicate code.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Playwright Auto-Waiting Mechanism&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Playwright&amp;rsquo;s built-in auto-waiting ensures that elements are in an interactable state before being operated on, enhancing test stability.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;p>This solution covers both normal and exceptional business flows, ensuring automated verification of the core functional points (login, cart, checkout) and improving software quality.&lt;/p>
&lt;h3 id="conclusion">Conclusion
&lt;/h3>&lt;p>Referring to the results given, they can be executed successfully with almost no fine-tuning, which indeed greatly improves our efficiency in automation implementation. What is most valuable is that the thinking process provided by DeepSeek is also of great reference value for the key points of our code implementation and test case design!&lt;/p></description></item></channel></rss>