{"curso":"mcp-chrome","steps":[{"id":"automacao-idempotente","content":[{"type":"glossary","value":"","data":{"terms":[{"term":"Idempotência","def":"Propriedade de uma ação que, repetida, entrega o mesmo resultado de ter rodado uma vez. Consultar saldo é idempotente; sacar não é, a menos que alguém no caminho reconheça que aquele saque já aconteceu. É o carimbo de \"já processado\" que impede a segunda via de virar segunda cobrança."},{"term":"Chave de idempotência","def":"Identificador único gerado antes da primeira tentativa e repetido em todas as retentativas, para que o destino devolva o registro original em vez de criar um gêmeo. É como o número de protocolo de um atendimento: apresentar o mesmo número duas vezes não abre dois chamados."}]}},{"type":"text","value":"Uma automação pode falhar depois de enviar uma ação e antes de receber a confirmação. Repetir tudo pode criar dois registros. Idempotência é a propriedade de repetir uma operação sem acrescentar um novo efeito indevido. Na prática, precisamos conferir estado, identificar a operação e saber onde retomar."},{"type":"text","value":"#### [icone:file-text] Exemplo: o cadastro foi criado, mas a resposta se perdeu\n\nO formulário enviou os dados e o servidor criou o registro 1041. A conexão caiu antes de mostrar a confirmação. Antes de tentar novamente, precisamos saber se a repetição devolverá 1041 ou criará outro registro."},{"type":"figure","value":"<svg role=\"img\" viewBox=\"0 0 360 952\" style=\"width:100%;height:auto;display:block;margin:0 auto;max-width:400px\" font-family=\"inherit\" xmlns=\"http://www.w3.org/2000/svg\">\n  <title>Linha do tempo comparando a retentativa sem chave de idempotência, que cria dois registros no destino, e a mesma sequência com chave, que converge para um único registro</title><desc>A mesma sequência em duas faixas: sem chave de idempotência a retentativa cria um segundo registro; com chave, o servidor reconhece a repetição e devolve o registro que já existia.</desc>\n  <style>\n    @media (prefers-reduced-motion: no-preference) {\n      .idup-p { animation: idup-entrar 0.45s ease-out both; }\n      .idup-a1 { animation-delay: 0.05s; }\n      .idup-a2 { animation-delay: 0.25s; }\n      .idup-a3 { animation-delay: 0.45s; }\n      .idup-a4 { animation-delay: 0.65s; }\n      .idup-a5 { animation-delay: 0.85s; }\n      .idup-b1 { animation-delay: 1.05s; }\n      .idup-b2 { animation-delay: 1.25s; }\n      .idup-b3 { animation-delay: 1.45s; }\n      .idup-b4 { animation-delay: 1.65s; }\n      .idup-b5 { animation-delay: 1.85s; }\n      .idup-corte { animation: idup-bater 2.8s ease-in-out 1.1s 3 both; }\n      @keyframes idup-entrar { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }\n      @keyframes idup-bater { 0%, 60%, 100% { opacity: 1; } 78% { opacity: 0.45; } }\n    }\n  </style>\n\n  <text x=\"16\" y=\"24\" fill=\"var(--danger)\" font-size=\"14\" font-weight=\"700\">Sem chave de idempotência:</text>\n  <text x=\"16\" y=\"42\" fill=\"var(--danger)\" font-size=\"14\" font-weight=\"700\">a repetição vira um segundo registro</text>\n  <rect x=\"8\" y=\"52\" width=\"344\" height=\"420\" rx=\"12\" fill=\"var(--danger-light)\" stroke=\"var(--danger)\" stroke-width=\"1.5\"/>\n\n  <g stroke=\"var(--danger)\" stroke-width=\"2\" fill=\"var(--danger)\">\n    <line x1=\"36\" y1=\"97\" x2=\"36\" y2=\"119\"/><path d=\"M 36 123 l -5 -9 l 10 0 z\" stroke=\"none\"/>\n    <line x1=\"36\" y1=\"149\" x2=\"36\" y2=\"171\"/><path d=\"M 36 175 l -5 -9 l 10 0 z\" stroke=\"none\"/>\n    <line x1=\"36\" y1=\"201\" x2=\"36\" y2=\"223\"/><path d=\"M 36 227 l -5 -9 l 10 0 z\" stroke=\"none\"/>\n    <line x1=\"36\" y1=\"253\" x2=\"36\" y2=\"296\" stroke-dasharray=\"5 4\"/><path d=\"M 36 300 l -5 -9 l 10 0 z\" stroke=\"none\"/>\n  </g>\n\n  <g class=\"idup-p idup-a1\">\n    <circle cx=\"36\" cy=\"84\" r=\"13\" fill=\"var(--danger)\"/><text x=\"36\" y=\"89\" text-anchor=\"middle\" fill=\"var(--text-on-accent)\" font-size=\"14\" font-weight=\"700\">1</text>\n    <text x=\"60\" y=\"89\" font-size=\"14\"><tspan fill=\"var(--text-muted)\">09:00:00</tspan><tspan dx=\"10\" fill=\"var(--text)\" font-weight=\"700\">POST enviado</tspan></text>\n  </g>\n  <g class=\"idup-p idup-a2\">\n    <circle cx=\"36\" cy=\"136\" r=\"13\" fill=\"var(--danger)\"/><text x=\"36\" y=\"141\" text-anchor=\"middle\" fill=\"var(--text-on-accent)\" font-size=\"14\" font-weight=\"700\">2</text>\n    <text x=\"60\" y=\"134\" font-size=\"14\"><tspan fill=\"var(--text-muted)\">09:00:00</tspan><tspan dx=\"10\" fill=\"var(--text)\" font-weight=\"700\">Servidor cria</tspan></text>\n    <text x=\"60\" y=\"152\" fill=\"var(--text)\" font-size=\"14\">o registro nº 1041</text>\n  </g>\n  <g class=\"idup-p idup-a3\">\n    <circle cx=\"36\" cy=\"188\" r=\"13\" fill=\"var(--danger)\"/><text x=\"36\" y=\"193\" text-anchor=\"middle\" fill=\"var(--text-on-accent)\" font-size=\"14\" font-weight=\"700\">3</text>\n    <text x=\"60\" y=\"186\" font-size=\"14\"><tspan fill=\"var(--text-muted)\">09:00:15</tspan><tspan dx=\"10\" fill=\"var(--text)\" font-weight=\"700\">Resposta se perde</tspan></text>\n    <text x=\"60\" y=\"204\" fill=\"var(--text)\" font-size=\"14\">tempo esgotado</text>\n  </g>\n  <g class=\"idup-corte\" style=\"transform-origin:318px 188px\">\n    <circle cx=\"318\" cy=\"188\" r=\"13\" fill=\"var(--bg-white)\" stroke=\"var(--danger)\" stroke-width=\"2\"/>\n    <path d=\"M 312 182 l 12 12 M 324 182 l -12 12\" stroke=\"var(--danger)\" stroke-width=\"2.5\" stroke-linecap=\"round\"/>\n  </g>\n  <g class=\"idup-p idup-a4\">\n    <circle cx=\"36\" cy=\"240\" r=\"13\" fill=\"var(--danger)\"/><text x=\"36\" y=\"245\" text-anchor=\"middle\" fill=\"var(--text-on-accent)\" font-size=\"14\" font-weight=\"700\">4</text>\n    <text x=\"60\" y=\"238\" font-size=\"14\"><tspan fill=\"var(--text-muted)\">09:00:16</tspan><tspan dx=\"10\" fill=\"var(--text)\" font-weight=\"700\">Repete o POST</tspan></text>\n    <text x=\"60\" y=\"256\" fill=\"var(--text)\" font-size=\"14\">cria o nº 1042</text>\n  </g>\n\n  <g class=\"idup-p idup-a5\">\n    <text x=\"60\" y=\"290\" fill=\"var(--text-muted)\" font-size=\"14\">destino</text>\n    <path d=\"M 60 306 a 50 11 0 0 1 100 0 v 70 a 50 11 0 0 1 -100 0 z\" fill=\"var(--bg-white)\" stroke=\"var(--danger)\" stroke-width=\"1.5\"/>\n    <ellipse cx=\"110\" cy=\"306\" rx=\"50\" ry=\"11\" fill=\"var(--bg-white)\" stroke=\"var(--danger)\" stroke-width=\"1.5\"/>\n    <rect x=\"70\" y=\"322\" width=\"80\" height=\"22\" rx=\"4\" fill=\"var(--danger-light)\" stroke=\"var(--danger)\" stroke-width=\"1.2\"/>\n    <text x=\"110\" y=\"338\" text-anchor=\"middle\" fill=\"var(--danger)\" font-size=\"14\">nº 1041</text>\n    <rect x=\"70\" y=\"350\" width=\"80\" height=\"22\" rx=\"4\" fill=\"var(--danger-light)\" stroke=\"var(--danger)\" stroke-width=\"1.2\"/>\n    <text x=\"110\" y=\"366\" text-anchor=\"middle\" fill=\"var(--danger)\" font-size=\"14\">nº 1042</text>\n    <rect x=\"60\" y=\"398\" width=\"240\" height=\"28\" rx=\"14\" fill=\"var(--danger)\"/>\n    <text x=\"180\" y=\"417\" text-anchor=\"middle\" fill=\"var(--text-on-accent)\" font-size=\"14\" font-weight=\"700\">2 registros, 1 pessoa</text>\n  </g>\n  <text x=\"20\" y=\"446\" fill=\"var(--danger)\" font-size=\"14\">Aqui mora o dano: a requisição funcionou,</text>\n  <text x=\"20\" y=\"464\" fill=\"var(--danger)\" font-size=\"14\">a resposta é que se perdeu.</text>\n\n  <text x=\"16\" y=\"504\" fill=\"var(--success-text)\" font-size=\"14\" font-weight=\"700\">Com chave de idempotência:</text>\n  <text x=\"16\" y=\"522\" fill=\"var(--success-text)\" font-size=\"14\" font-weight=\"700\">a repetição devolve o mesmo registro</text>\n  <rect x=\"8\" y=\"532\" width=\"344\" height=\"412\" rx=\"12\" fill=\"var(--success-light)\" stroke=\"var(--success)\" stroke-width=\"1.5\"/>\n\n  <g stroke=\"var(--success)\" stroke-width=\"2\" fill=\"var(--success)\">\n    <line x1=\"36\" y1=\"577\" x2=\"36\" y2=\"599\"/><path d=\"M 36 603 l -5 -9 l 10 0 z\" stroke=\"none\"/>\n    <line x1=\"36\" y1=\"629\" x2=\"36\" y2=\"651\"/><path d=\"M 36 655 l -5 -9 l 10 0 z\" stroke=\"none\"/>\n    <line x1=\"36\" y1=\"681\" x2=\"36\" y2=\"703\"/><path d=\"M 36 707 l -5 -9 l 10 0 z\" stroke=\"none\"/>\n    <line x1=\"36\" y1=\"733\" x2=\"36\" y2=\"796\" stroke-dasharray=\"5 4\"/><path d=\"M 36 800 l -5 -9 l 10 0 z\" stroke=\"none\"/>\n  </g>\n\n  <g class=\"idup-p idup-b1\">\n    <circle cx=\"36\" cy=\"564\" r=\"13\" fill=\"var(--success)\"/><text x=\"36\" y=\"569\" text-anchor=\"middle\" fill=\"var(--text-on-accent)\" font-size=\"14\" font-weight=\"700\">1</text>\n    <text x=\"60\" y=\"562\" font-size=\"14\"><tspan fill=\"var(--text-muted)\">09:00:00</tspan><tspan dx=\"10\" fill=\"var(--text)\" font-weight=\"700\">POST enviado</tspan></text>\n    <text x=\"60\" y=\"580\" fill=\"var(--success-text)\" font-size=\"14\">Idempotency-Key: 8f2c…</text>\n  </g>\n  <g class=\"idup-p idup-b2\">\n    <circle cx=\"36\" cy=\"616\" r=\"13\" fill=\"var(--success)\"/><text x=\"36\" y=\"621\" text-anchor=\"middle\" fill=\"var(--text-on-accent)\" font-size=\"14\" font-weight=\"700\">2</text>\n    <text x=\"60\" y=\"614\" font-size=\"14\"><tspan fill=\"var(--text-muted)\">09:00:00</tspan><tspan dx=\"10\" fill=\"var(--text)\" font-weight=\"700\">Servidor cria</tspan></text>\n    <text x=\"60\" y=\"632\" fill=\"var(--text)\" font-size=\"14\">o registro nº 1041</text>\n  </g>\n  <g class=\"idup-p idup-b3\">\n    <circle cx=\"36\" cy=\"668\" r=\"13\" fill=\"var(--success)\"/><text x=\"36\" y=\"673\" text-anchor=\"middle\" fill=\"var(--text-on-accent)\" font-size=\"14\" font-weight=\"700\">3</text>\n    <text x=\"60\" y=\"666\" font-size=\"14\"><tspan fill=\"var(--text-muted)\">09:00:15</tspan><tspan dx=\"10\" fill=\"var(--text)\" font-weight=\"700\">Resposta se perde</tspan></text>\n    <text x=\"60\" y=\"684\" fill=\"var(--text)\" font-size=\"14\">tempo esgotado</text>\n  </g>\n  <g>\n    <circle cx=\"318\" cy=\"668\" r=\"12\" fill=\"var(--bg-white)\" stroke=\"var(--text-muted)\" stroke-width=\"1.8\"/>\n    <path d=\"M 313 663 l 10 10 M 323 663 l -10 10\" stroke=\"var(--text-muted)\" stroke-width=\"2.2\" stroke-linecap=\"round\"/>\n  </g>\n  <g class=\"idup-p idup-b4\">\n    <circle cx=\"36\" cy=\"720\" r=\"13\" fill=\"var(--success)\"/><text x=\"36\" y=\"725\" text-anchor=\"middle\" fill=\"var(--text-on-accent)\" font-size=\"14\" font-weight=\"700\">4</text>\n    <text x=\"60\" y=\"718\" font-size=\"14\"><tspan fill=\"var(--text-muted)\">09:00:16</tspan><tspan dx=\"10\" fill=\"var(--text)\" font-weight=\"700\">Repete a MESMA chave</tspan></text>\n    <text x=\"60\" y=\"736\" fill=\"var(--success-text)\" font-size=\"14\">Idempotency-Key: 8f2c…</text>\n    <text x=\"60\" y=\"754\" fill=\"var(--text)\" font-size=\"14\">devolve o nº 1041</text>\n  </g>\n\n  <g class=\"idup-p idup-b5\">\n    <text x=\"60\" y=\"790\" fill=\"var(--text-muted)\" font-size=\"14\">destino</text>\n    <path d=\"M 60 806 a 50 11 0 0 1 100 0 v 42 a 50 11 0 0 1 -100 0 z\" fill=\"var(--bg-white)\" stroke=\"var(--success)\" stroke-width=\"1.5\"/>\n    <ellipse cx=\"110\" cy=\"806\" rx=\"50\" ry=\"11\" fill=\"var(--bg-white)\" stroke=\"var(--success)\" stroke-width=\"1.5\"/>\n    <rect x=\"70\" y=\"822\" width=\"80\" height=\"22\" rx=\"4\" fill=\"var(--success-light)\" stroke=\"var(--success)\" stroke-width=\"1.2\"/>\n    <text x=\"110\" y=\"838\" text-anchor=\"middle\" fill=\"var(--success-text)\" font-size=\"14\">nº 1041</text>\n    <rect x=\"60\" y=\"870\" width=\"240\" height=\"28\" rx=\"14\" fill=\"var(--success)\"/>\n    <text x=\"180\" y=\"889\" text-anchor=\"middle\" fill=\"var(--text-on-accent)\" font-size=\"14\" font-weight=\"700\">1 registro</text>\n  </g>\n  <text x=\"20\" y=\"918\" fill=\"var(--success-text)\" font-size=\"14\">A chave já vista faz o servidor devolver</text>\n  <text x=\"20\" y=\"936\" fill=\"var(--success-text)\" font-size=\"14\">o registro original, sem criar outro.</text>\n</svg>","label":"A mesma sequência em duas faixas: sem chave de idempotência a retentativa cria um segundo registro; com chave, o servidor reconhece a repetição e devolve o registro que já existia."},{"type":"text","value":"O fim do tempo de espera no cliente não prova que o servidor cancelou a operação. O efeito pode ter ocorrido. Confira o estado no destino ou use a proteção contra duplicidade oferecida por ele."},{"type":"callout","label":"Regra de ouro","value":"Espere por um resultado observável. Para repetir uma escrita, use a chave da mesma operação quando o destino oferecer esse contrato. Se a confirmação ficou incerta e o destino não protege contra duplicação, confira o registro antes de reenviar."},{"type":"text","value":"Comece pela espera, porque é o erro mais comum e o mais barato de corrigir. Dormir três segundos parece razoável até você perceber que o número está errado nos dois sentidos ao mesmo tempo.\n\nNa rede lenta, três segundos são curtos demais e o passo seguinte age sobre uma página que ainda não terminou de responder. Na rede rápida, são desperdício puro, multiplicado por centenas de passos até virar minutos de espera por execução."},{"type":"text","value":"#### [icone:code] Exemplo de espera\n\nO trecho abaixo pertence a um teste Playwright, com `page` fornecida pelo teste. Ele espera a confirmação antes de avançar. Ajuste nomes e mensagens ao formulário de laboratório."},{"type":"code","language":"javascript","value":"import { expect } from \"@playwright/test\";\n\nawait page.getByRole(\"button\", { name: \"Salvar cadastro\" }).click();\nawait expect(page.getByText(\"Cadastro criado com sucesso\")).toBeVisible({\n  timeout: 15000,\n});\nawait page.getByRole(\"button\", { name: \"Continuar\" }).click();","codeHtml":"<span class=\"line\"><span class=\"cc-LG_FCO\">import</span><span class=\"cc-0lkzTf\"> {</span><span class=\"cc-Zg_G8Q\"> expect </span><span class=\"cc-0lkzTf\">}</span><span class=\"cc-LG_FCO\"> from</span><span class=\"cc-Vmk6LI\"> \"@playwright/test\"</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">await</span><span class=\"cc-Zg_G8Q\"> page</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">getByRole</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-Vmk6LI\">\"button\"</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-0lkzTf\"> {</span><span class=\"cc-Zg_G8Q\"> name</span><span class=\"cc-gX46La\">:</span><span class=\"cc-Vmk6LI\"> \"Salvar cadastro\"</span><span class=\"cc-0lkzTf\"> }</span><span class=\"cc-Zg_G8Q\">)</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">click</span><span class=\"cc-Zg_G8Q\">()</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">await</span><span class=\"cc-Np3vnr\"> expect</span><span class=\"cc-Zg_G8Q\">(page</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">getByText</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-Vmk6LI\">\"Cadastro criado com sucesso\"</span><span class=\"cc-Zg_G8Q\">))</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">toBeVisible</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-0lkzTf\">{</span></span>\n<span class=\"line\"><span class=\"cc-Zg_G8Q\">  timeout</span><span class=\"cc-gX46La\">:</span><span class=\"cc-wVAnzj\"> 15000</span><span class=\"cc-0lkzTf\">,</span></span>\n<span class=\"line\"><span class=\"cc-0lkzTf\">}</span><span class=\"cc-Zg_G8Q\">)</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">await</span><span class=\"cc-Zg_G8Q\"> page</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">getByRole</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-Vmk6LI\">\"button\"</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-0lkzTf\"> {</span><span class=\"cc-Zg_G8Q\"> name</span><span class=\"cc-gX46La\">:</span><span class=\"cc-Vmk6LI\"> \"Continuar\"</span><span class=\"cc-0lkzTf\"> }</span><span class=\"cc-Zg_G8Q\">)</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">click</span><span class=\"cc-Zg_G8Q\">()</span><span class=\"cc-0lkzTf\">;</span></span>"},{"type":"warning","value":"Nem toda ferramenta traz espera automática embutida. No chrome-devtools-mcp, o único mecanismo de espera documentado na referência de ferramentas é o wait_for, que aguarda um texto aparecer na página e aceita um prazo opcional. Ou seja: cabe a quem escreve o roteiro intercalar a verificação entre as ações. Se você encadear clique com clique sem nada no meio, está apostando no tempo de resposta."},{"type":"figure","value":"<div data-captura-real=\"playwright83-1\" style=\"display:grid;gap:14px\"><div class=\"cp-rotulo\">Na fonte</div><img class=\"cp-img-link\" src=\"https://midia.brasilgeo.ai/educacao/capturas-executivas-20261024/playwright83-1.webp\" width=\"1200\" height=\"800\" alt=\"Mudanças de página e de quadro exigem uma referência atual ao estado.\" loading=\"lazy\" decoding=\"async\" style=\"display:block;width:100%;height:auto;max-width:900px;margin:0 auto\" /><div class=\"cp-meta\"><a href=\"https://github.com/microsoft/playwright-mcp/releases/tag/v0.0.83\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"cp-link\">Consultar a fonte original</a><span style=\"color:var(--text-muted)\">Captura em 24/10/2026</span></div></div>","label":"Mudanças de página e de quadro exigem uma referência atual ao estado."},{"type":"flow","title":"Enviar uma vez e conferir","value":"1. Preparar: Defina dados e chave da operação antes do envio.\n2. Enviar: Use o contrato de idempotência do destino.\n3. Conferir: Busque o identificador e o estado final.\n4. Retomar: Reutilize a mesma chave somente para a mesma operação.","data":{"title":"Enviar uma vez e conferir","steps":[{"label":"Preparar","sub":"Defina dados e chave da operação antes do envio."},{"label":"Enviar","sub":"Use o contrato de idempotência do destino."},{"label":"Conferir","sub":"Busque o identificador e o estado final."},{"label":"Retomar","sub":"Reutilize a mesma chave somente para a mesma operação."}]}},{"type":"text","value":"A segunda fonte de fragilidade é onde você aponta. Um seletor CSS profundo descreve o caminho até o elemento dentro de uma estrutura que muda toda semana. Uma coordenada de pixel descreve onde o elemento estava numa janela daquele tamanho, naquele dia.\n\nPapel, rótulo acessível e texto visível descrevem outra coisa: a **intenção**. Um botão chamado \"Salvar cadastro\" continua sendo esse botão depois do redesenho, porque o nome é justamente o que o produto não muda por acaso."},{"type":"figure","value":"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 320 568\" width=\"100%\" role=\"img\" aria-labelledby=\"aid1-t aid1-d\" font-family=\"inherit\" style=\"width:100%;height:auto;display:block;margin:0 auto;max-width:440px\"><title id=\"aid1-t\">Comparação entre ancorar a ação em seletor CSS profundo e coordenada de pixel, que erram o alvo quando um banner de cookies empurra o layout, e ancorar em papel, rótulo acessível e texto visível, que continuam acertando o botão.</title><desc id=\"aid1-d\">Seletor profundo e coordenada apontam para uma estrutura e uma posição; papel, rótulo e texto apontam para a intenção. Quando um banner empurra o layout, só a âncora estável continua acertando.</desc><defs><marker id=\"aid1-seta\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerWidth=\"7\" markerHeight=\"7\" orient=\"auto\"><path d=\"M0 0L10 5L0 10z\" fill=\"var(--text-muted)\"/></marker></defs><style>@media (prefers-reduced-motion: no-preference){.aid1-in{opacity:0;animation:aid1-entrar .5s ease-out both}.aid1-n1{animation-delay:0.08s}.aid1-n2{animation-delay:0.20s}.aid1-n3{animation-delay:0.32s}.aid1-n4{animation-delay:0.44s}.aid1-n5{animation-delay:0.56s}.aid1-n6{animation-delay:0.68s}.aid1-n7{animation-delay:0.80s}.aid1-n8{animation-delay:0.92s}.aid1-n9{animation-delay:1.04s}.aid1-n10{animation-delay:1.16s}.aid1-n11{animation-delay:1.28s}.aid1-n12{animation-delay:1.40s}@keyframes aid1-entrar{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}}}</style><g class=\"aid1-in aid1-n1\"><rect x=\"12\" y=\"12\" width=\"296\" height=\"220.7\" rx=\"8\" fill=\"var(--danger-light)\" stroke=\"var(--danger)\" stroke-width=\"2\"/><text x=\"24\" y=\"38.3\" text-anchor=\"start\" font-size=\"15\" font-weight=\"700\" fill=\"var(--danger)\">Âncora frágil: estrutura e</text><text x=\"24\" y=\"58.5\" text-anchor=\"start\" font-size=\"15\" font-weight=\"700\" fill=\"var(--danger)\">posição</text><text x=\"24\" y=\"80.4\" text-anchor=\"start\" font-size=\"14\" font-family=\"ui-monospace, SFMono-Regular, Menlo, monospace\" fill=\"var(--text)\">div.container &gt;</text><text x=\"24\" y=\"99.3\" text-anchor=\"start\" font-size=\"14\" font-family=\"ui-monospace, SFMono-Regular, Menlo, monospace\" fill=\"var(--text)\">div:nth-child(3)</text><text x=\"24\" y=\"118.2\" text-anchor=\"start\" font-size=\"14\" font-family=\"ui-monospace, SFMono-Regular, Menlo, monospace\" fill=\"var(--text)\">&gt; form &gt; button.btn-primary</text><text x=\"24\" y=\"137.1\" text-anchor=\"start\" font-size=\"14\" font-family=\"ui-monospace, SFMono-Regular, Menlo, monospace\" fill=\"var(--text)\">coordenada x: 612, y: 388</text><text x=\"24\" y=\"162.0\" text-anchor=\"start\" font-size=\"14\" font-weight=\"700\" fill=\"var(--success-text)\">sexta: layout previsto → botão</text><text x=\"24\" y=\"180.9\" text-anchor=\"start\" font-size=\"14\" font-weight=\"700\" fill=\"var(--success-text)\">Salvar: acerta</text><text x=\"24\" y=\"199.8\" text-anchor=\"start\" font-size=\"14\" font-weight=\"700\" fill=\"var(--danger)\">segunda: com banner Aceitar</text><text x=\"24\" y=\"218.7\" text-anchor=\"start\" font-size=\"14\" font-weight=\"700\" fill=\"var(--danger)\">cookies → erra</text></g><g class=\"aid1-in aid1-n2\"><rect x=\"12\" y=\"246.70000000000005\" width=\"296\" height=\"220.7\" rx=\"8\" fill=\"var(--success-light)\" stroke=\"var(--success)\" stroke-width=\"2\"/><text x=\"24\" y=\"273.0\" text-anchor=\"start\" font-size=\"15\" font-weight=\"700\" fill=\"var(--success-text)\">Âncora estável: intenção</text><text x=\"24\" y=\"293.2\" text-anchor=\"start\" font-size=\"15\" font-weight=\"700\" fill=\"var(--success-text)\">declarada</text><text x=\"24\" y=\"315.1\" text-anchor=\"start\" font-size=\"14\" fill=\"var(--text)\">papel: button</text><text x=\"24\" y=\"334.0\" text-anchor=\"start\" font-size=\"14\" fill=\"var(--text)\">rótulo acessível: Salvar cadastro</text><text x=\"24\" y=\"352.9\" text-anchor=\"start\" font-size=\"14\" fill=\"var(--text-muted)\">texto visível: Salvar</text><text x=\"24\" y=\"377.8\" text-anchor=\"start\" font-size=\"14\" font-weight=\"700\" fill=\"var(--success-text)\">sexta: layout previsto → papel</text><text x=\"24\" y=\"396.7\" text-anchor=\"start\" font-size=\"14\" font-weight=\"700\" fill=\"var(--success-text)\">+ nome → Salvar: acerta</text><text x=\"24\" y=\"415.6\" text-anchor=\"start\" font-size=\"14\" font-weight=\"700\" fill=\"var(--success-text)\">segunda: com banner Aceitar</text><text x=\"24\" y=\"434.5\" text-anchor=\"start\" font-size=\"14\" font-weight=\"700\" fill=\"var(--success-text)\">cookies → papel + nome →</text><text x=\"24\" y=\"453.4\" text-anchor=\"start\" font-size=\"14\" font-weight=\"700\" fill=\"var(--success-text)\">Salvar: acerta</text></g><text x=\"160\" y=\"490.4\" text-anchor=\"middle\" font-size=\"14\" fill=\"var(--text-muted)\">O pixel e o caminho do DOM descrevem</text><text x=\"160\" y=\"509.4\" text-anchor=\"middle\" font-size=\"14\" fill=\"var(--text-muted)\">uma estrutura que muda toda semana.</text><text x=\"160\" y=\"534.4\" text-anchor=\"middle\" font-size=\"14\" fill=\"var(--text-muted)\">Papel, rótulo e texto descrevem a</text><text x=\"160\" y=\"553.4\" text-anchor=\"middle\" font-size=\"14\" fill=\"var(--text-muted)\">intenção e sobrevivem ao redesenho.</text></svg>","label":"Seletor profundo e coordenada apontam para uma estrutura e uma posição; papel, rótulo e texto apontam para a intenção. Quando um banner empurra o layout, só a âncora estável continua acertando."},{"type":"tip","value":"Use as referências da leitura atual para confirmar o alvo. No Playwright MCP elas podem aparecer como e5; no DevTools MCP, como uid. Depois de uma mudança de página ou estado, releia antes de agir."},{"type":"text","value":"#### [icone:code] Exemplo de envio com repetição\n\nSalve como `enviar-lead.mjs`. A função recebe URL, dados e chave. Gere uma chave para cada operação e guarde-a antes do envio; use a mesma ao retomar essa operação. O próximo exemplo testa a função com um destino simulado, sem rede."},{"type":"code","language":"javascript","value":"// enviar-lead.mjs\n// O destino precisa documentar suporte a Idempotency-Key.\nexport async function enviarLead(url, dados, chave, enviar = fetch, esperar = (ms) => new Promise((r) => setTimeout(r, ms))) {\n  if (!chave) throw new Error(\"Informe a chave desta operação.\");\n  for (let tentativa = 1; tentativa <= 3; tentativa++) {\n    let resposta;\n    try {\n      resposta = await enviar(url, {\n        method: \"POST\",\n        headers: {\"Content-Type\": \"application/json\", \"Idempotency-Key\": chave},\n        body: JSON.stringify(dados),\n      });\n    } catch (erro) {\n      if (tentativa === 3) throw erro;\n      await esperar(500 * 2 ** (tentativa - 1));\n      continue;\n    }\n    if (resposta.status >= 500 && tentativa < 3) {\n      await esperar(500 * 2 ** (tentativa - 1));\n      continue;\n    }\n    if (!resposta.ok) throw new Error(`Envio recusado: HTTP ${resposta.status}`);\n    return resposta.json();\n  }\n}\n\n// Até três tentativas no total. Erros 4xx interrompem este exemplo.\n// Para tratar 429, siga a política de espera do destino; não repita sem limite.","codeHtml":"<span class=\"line\"><span class=\"cc-9sSsV5\">// enviar-lead.mjs</span></span>\n<span class=\"line\"><span class=\"cc-9sSsV5\">// O destino precisa documentar suporte a Idempotency-Key.</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">export</span><span class=\"cc-LG_FCO\"> async</span><span class=\"cc-LG_FCO\"> function</span><span class=\"cc-Np3vnr\"> enviarLead</span><span class=\"cc-0lkzTf\">(</span><span class=\"cc-EHq2D4\">url</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-EHq2D4\"> dados</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-EHq2D4\"> chave</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-EHq2D4\"> enviar</span><span class=\"cc-gX46La\"> =</span><span class=\"cc-Zg_G8Q\"> fetch</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-Np3vnr\"> esperar</span><span class=\"cc-gX46La\"> =</span><span class=\"cc-0lkzTf\"> (</span><span class=\"cc-EHq2D4\">ms</span><span class=\"cc-0lkzTf\">)</span><span class=\"cc-LG_FCO\"> =></span><span class=\"cc-9pAnQC\"> new</span><span class=\"cc-Dtw0XN\"> Promise</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-0lkzTf\">(</span><span class=\"cc-EHq2D4\">r</span><span class=\"cc-0lkzTf\">)</span><span class=\"cc-LG_FCO\"> =></span><span class=\"cc-Np3vnr\"> setTimeout</span><span class=\"cc-Zg_G8Q\">(r</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-Zg_G8Q\"> ms))</span><span class=\"cc-0lkzTf\">)</span><span class=\"cc-0lkzTf\"> {</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">  if</span><span class=\"cc-Zg_G8Q\"> (</span><span class=\"cc-gX46La\">!</span><span class=\"cc-Zg_G8Q\">chave) </span><span class=\"cc-LG_FCO\">throw</span><span class=\"cc-9pAnQC\"> new</span><span class=\"cc-Np3vnr\"> Error</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-Vmk6LI\">\"Informe a chave desta operação.\"</span><span class=\"cc-Zg_G8Q\">)</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">  for</span><span class=\"cc-Zg_G8Q\"> (</span><span class=\"cc-LG_FCO\">let</span><span class=\"cc-Zg_G8Q\"> tentativa </span><span class=\"cc-gX46La\">=</span><span class=\"cc-wVAnzj\"> 1</span><span class=\"cc-0lkzTf\">;</span><span class=\"cc-Zg_G8Q\"> tentativa </span><span class=\"cc-gX46La\">&#x3C;=</span><span class=\"cc-wVAnzj\"> 3</span><span class=\"cc-0lkzTf\">;</span><span class=\"cc-Zg_G8Q\"> tentativa</span><span class=\"cc-gX46La\">++</span><span class=\"cc-Zg_G8Q\">) </span><span class=\"cc-0lkzTf\">{</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">    let</span><span class=\"cc-Zg_G8Q\"> resposta</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">    try</span><span class=\"cc-0lkzTf\"> {</span></span>\n<span class=\"line\"><span class=\"cc-Zg_G8Q\">      resposta </span><span class=\"cc-gX46La\">=</span><span class=\"cc-LG_FCO\"> await</span><span class=\"cc-Np3vnr\"> enviar</span><span class=\"cc-Zg_G8Q\">(url</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-0lkzTf\"> {</span></span>\n<span class=\"line\"><span class=\"cc-Zg_G8Q\">        method</span><span class=\"cc-gX46La\">:</span><span class=\"cc-Vmk6LI\"> \"POST\"</span><span class=\"cc-0lkzTf\">,</span></span>\n<span class=\"line\"><span class=\"cc-Zg_G8Q\">        headers</span><span class=\"cc-gX46La\">:</span><span class=\"cc-0lkzTf\"> {</span><span class=\"cc-Vmk6LI\">\"Content-Type\"</span><span class=\"cc-gX46La\">:</span><span class=\"cc-Vmk6LI\"> \"application/json\"</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-Vmk6LI\"> \"Idempotency-Key\"</span><span class=\"cc-gX46La\">:</span><span class=\"cc-Zg_G8Q\"> chave</span><span class=\"cc-0lkzTf\">},</span></span>\n<span class=\"line\"><span class=\"cc-Zg_G8Q\">        body</span><span class=\"cc-gX46La\">:</span><span class=\"cc-wVAnzj\"> JSON</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">stringify</span><span class=\"cc-Zg_G8Q\">(dados)</span><span class=\"cc-0lkzTf\">,</span></span>\n<span class=\"line\"><span class=\"cc-0lkzTf\">      }</span><span class=\"cc-Zg_G8Q\">)</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-0lkzTf\">    }</span><span class=\"cc-LG_FCO\"> catch</span><span class=\"cc-Zg_G8Q\"> (erro) </span><span class=\"cc-0lkzTf\">{</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">      if</span><span class=\"cc-Zg_G8Q\"> (tentativa </span><span class=\"cc-gX46La\">===</span><span class=\"cc-wVAnzj\"> 3</span><span class=\"cc-Zg_G8Q\">) </span><span class=\"cc-LG_FCO\">throw</span><span class=\"cc-Zg_G8Q\"> erro</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">      await</span><span class=\"cc-Np3vnr\"> esperar</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-wVAnzj\">500</span><span class=\"cc-gX46La\"> *</span><span class=\"cc-wVAnzj\"> 2</span><span class=\"cc-gX46La\"> **</span><span class=\"cc-Zg_G8Q\"> (tentativa </span><span class=\"cc-gX46La\">-</span><span class=\"cc-wVAnzj\"> 1</span><span class=\"cc-Zg_G8Q\">))</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">      continue</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-0lkzTf\">    }</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">    if</span><span class=\"cc-Zg_G8Q\"> (resposta</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Zg_G8Q\">status </span><span class=\"cc-gX46La\">>=</span><span class=\"cc-wVAnzj\"> 500</span><span class=\"cc-gX46La\"> &#x26;&#x26;</span><span class=\"cc-Zg_G8Q\"> tentativa </span><span class=\"cc-gX46La\">&#x3C;</span><span class=\"cc-wVAnzj\"> 3</span><span class=\"cc-Zg_G8Q\">) </span><span class=\"cc-0lkzTf\">{</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">      await</span><span class=\"cc-Np3vnr\"> esperar</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-wVAnzj\">500</span><span class=\"cc-gX46La\"> *</span><span class=\"cc-wVAnzj\"> 2</span><span class=\"cc-gX46La\"> **</span><span class=\"cc-Zg_G8Q\"> (tentativa </span><span class=\"cc-gX46La\">-</span><span class=\"cc-wVAnzj\"> 1</span><span class=\"cc-Zg_G8Q\">))</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">      continue</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-0lkzTf\">    }</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">    if</span><span class=\"cc-Zg_G8Q\"> (</span><span class=\"cc-gX46La\">!</span><span class=\"cc-Zg_G8Q\">resposta</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Zg_G8Q\">ok) </span><span class=\"cc-LG_FCO\">throw</span><span class=\"cc-9pAnQC\"> new</span><span class=\"cc-Np3vnr\"> Error</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-Vmk6LI\">`Envio recusado: HTTP </span><span class=\"cc-0lkzTf\">${</span><span class=\"cc-Zg_G8Q\">resposta</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Zg_G8Q\">status</span><span class=\"cc-0lkzTf\">}</span><span class=\"cc-Vmk6LI\">`</span><span class=\"cc-Zg_G8Q\">)</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">    return</span><span class=\"cc-Zg_G8Q\"> resposta</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">json</span><span class=\"cc-Zg_G8Q\">()</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-0lkzTf\">  }</span></span>\n<span class=\"line\"><span class=\"cc-0lkzTf\">}</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span class=\"cc-9sSsV5\">// Até três tentativas no total. Erros 4xx interrompem este exemplo.</span></span>\n<span class=\"line\"><span class=\"cc-9sSsV5\">// Para tratar 429, siga a política de espera do destino; não repita sem limite.</span></span>"},{"type":"warning","value":"A chave só protege se o outro lado a honrar. Cabeçalho de idempotência é contrato do destino, não mágica do cliente: se a API ignora o cabeçalho, ele vira enfeite e a duplicidade volta. Antes de confiar, leia a documentação do destino e teste enviando a mesma chave duas vezes de propósito, conferindo se voltou o mesmo identificador de registro."},{"type":"code","language":"javascript","value":"// Pseudocódigo: adapte às funções do seu destino.\n// Consultar antes de criar reduz repetição, mas duas execuções simultâneas\n// ainda podem consultar antes de qualquer uma gravar.\nconst existente = await buscarOperacao(chaveDaOperacao);\nif (existente) {\n  console.log(\"Registro encontrado:\", existente.id);\n} else {\n  // Use criação atômica com chave única quando o destino oferecer isso.\n  // Caso contrário, encaminhe uma escrita incerta para revisão.\n  await prepararParaRevisao(dados, chaveDaOperacao);\n}","codeHtml":"<span class=\"line\"><span class=\"cc-9sSsV5\">// Pseudocódigo: adapte às funções do seu destino.</span></span>\n<span class=\"line\"><span class=\"cc-9sSsV5\">// Consultar antes de criar reduz repetição, mas duas execuções simultâneas</span></span>\n<span class=\"line\"><span class=\"cc-9sSsV5\">// ainda podem consultar antes de qualquer uma gravar.</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">const</span><span class=\"cc-Zg_G8Q\"> existente </span><span class=\"cc-gX46La\">=</span><span class=\"cc-LG_FCO\"> await</span><span class=\"cc-Np3vnr\"> buscarOperacao</span><span class=\"cc-Zg_G8Q\">(chaveDaOperacao)</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">if</span><span class=\"cc-Zg_G8Q\"> (existente) </span><span class=\"cc-0lkzTf\">{</span></span>\n<span class=\"line\"><span class=\"cc-Zg_G8Q\">  console</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">log</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-Vmk6LI\">\"Registro encontrado:\"</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-Zg_G8Q\"> existente</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Zg_G8Q\">id)</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-0lkzTf\">}</span><span class=\"cc-LG_FCO\"> else</span><span class=\"cc-0lkzTf\"> {</span></span>\n<span class=\"line\"><span class=\"cc-9sSsV5\">  // Use criação atômica com chave única quando o destino oferecer isso.</span></span>\n<span class=\"line\"><span class=\"cc-9sSsV5\">  // Caso contrário, encaminhe uma escrita incerta para revisão.</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">  await</span><span class=\"cc-Np3vnr\"> prepararParaRevisao</span><span class=\"cc-Zg_G8Q\">(dados</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-Zg_G8Q\"> chaveDaOperacao)</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-0lkzTf\">}</span></span>"},{"type":"callout","label":"Na prática","value":"Guarde a chave junto do estado da execução, não só na memória do processo. Se o roteiro morrer no meio e você reiniciar, a chave precisa ser **a mesma** para que a retomada não vire uma segunda escrita. Chave em variável de processo morre com o processo; chave gravada em arquivo ou em banco sobrevive à retomada."},{"type":"figure","value":"<div data-captura-real=\"playwright-auth-2\" style=\"display:grid;gap:14px\"><div class=\"cp-rotulo\">Na fonte</div><img class=\"cp-img-link\" src=\"https://midia.brasilgeo.ai/educacao/capturas-executivas-20261024/playwright-auth-2.webp\" width=\"1200\" height=\"833\" alt=\"É possível preparar um estado de autenticação para uma execução autorizada.\" loading=\"lazy\" decoding=\"async\" style=\"display:block;width:100%;height:auto;max-width:900px;margin:0 auto\" /><div class=\"cp-meta\"><a href=\"https://playwright.dev/docs/auth\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"cp-link\">Consultar a fonte original</a><span style=\"color:var(--text-muted)\">Captura em 24/10/2026</span></div></div>","label":"É possível preparar um estado de autenticação para uma execução autorizada."},{"type":"text","value":"Se o botão não aparecer ou a resposta ficar incerta, pare e registre o ponto de interrupção. A retomada deve partir do estado conferido, sem improvisar uma segunda escrita."},{"type":"figure","value":"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 320 1293\" width=\"100%\" role=\"img\" aria-labelledby=\"aid2-t aid2-d\" font-family=\"inherit\" style=\"width:100%;height:auto;display:block;margin:0 auto;max-width:440px\"><title id=\"aid2-t\">Fluxograma do roteiro robusto: cinco passos em coluna, um ponto de verificação de estado entre cada par de passos e um ramo de desistência limpa saindo de cada verificação para uma única caixa de parada e relato.</title><desc id=\"aid2-d\">O roteiro que aguenta imprevisto tem um ponto de verificação entre cada par de passos, e todas as saídas negativas convergem para o mesmo lugar: parar e relatar. Desistência é caminho previsto, não exceção.</desc><defs><marker id=\"aid2-seta\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerWidth=\"7\" markerHeight=\"7\" orient=\"auto\"><path d=\"M0 0L10 5L0 10z\" fill=\"var(--text-muted)\"/></marker></defs><style>@media (prefers-reduced-motion: no-preference){.aid2-in{opacity:0;animation:aid2-entrar .5s ease-out both}.aid2-n1{animation-delay:0.08s}.aid2-n2{animation-delay:0.20s}.aid2-n3{animation-delay:0.32s}.aid2-n4{animation-delay:0.44s}.aid2-n5{animation-delay:0.56s}.aid2-n6{animation-delay:0.68s}.aid2-n7{animation-delay:0.80s}.aid2-n8{animation-delay:0.92s}.aid2-n9{animation-delay:1.04s}.aid2-n10{animation-delay:1.16s}.aid2-n11{animation-delay:1.28s}.aid2-n12{animation-delay:1.40s}@keyframes aid2-entrar{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}}}</style><text x=\"160\" y=\"27.5\" text-anchor=\"middle\" font-size=\"16\" font-weight=\"700\" fill=\"var(--text)\">Cada passo prova o anterior, e</text><text x=\"160\" y=\"49.0\" text-anchor=\"middle\" font-size=\"16\" font-weight=\"700\" fill=\"var(--text)\">a desistência tem um destino</text><text x=\"160\" y=\"70.5\" text-anchor=\"middle\" font-size=\"16\" font-weight=\"700\" fill=\"var(--text)\">só</text><g class=\"aid2-in aid2-n1\"><rect x=\"12\" y=\"84.5\" width=\"296\" height=\"62.2\" rx=\"8\" fill=\"var(--bg-white)\" stroke=\"var(--border)\" stroke-width=\"1.5\"/><circle cx=\"35\" cy=\"105.8\" r=\"11\" fill=\"var(--accent)\"/><text x=\"35\" y=\"110.8\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text-on-accent)\">1</text><text x=\"52\" y=\"110.8\" text-anchor=\"start\" font-size=\"15\" font-weight=\"700\" fill=\"var(--text)\">Abrir a página</text><text x=\"52\" y=\"132.7\" text-anchor=\"start\" font-size=\"14\" fill=\"var(--text-muted)\">no perfil de laboratório</text></g><line x1=\"160\" y1=\"146.65\" x2=\"160\" y2=\"168.65\" stroke=\"var(--text-muted)\" stroke-width=\"2\" marker-end=\"url(#aid2-seta)\"/><g class=\"aid2-in aid2-n2\"><polygon points=\"12,200.65 36,170.65 284,170.65 308,200.65 284,230.65 36,230.65\" fill=\"var(--bg-white)\" stroke=\"var(--accent)\" stroke-width=\"2\"/><text x=\"160\" y=\"195.7\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text)\">o estado esperado apareceu?</text><text x=\"160\" y=\"214.7\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text)\">se não → DESISTIR</text></g><line x1=\"160\" y1=\"230.65\" x2=\"160\" y2=\"259.65\" stroke=\"var(--text-muted)\" stroke-width=\"2\" marker-end=\"url(#aid2-seta)\"/><text x=\"170\" y=\"251.2\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text-muted)\">sim</text><g class=\"aid2-in aid2-n3\"><rect x=\"12\" y=\"261.65\" width=\"296\" height=\"62.1\" rx=\"8\" fill=\"var(--bg-white)\" stroke=\"var(--border)\" stroke-width=\"1.5\"/><circle cx=\"35\" cy=\"282.9\" r=\"11\" fill=\"var(--accent)\"/><text x=\"35\" y=\"287.9\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text-on-accent)\">2</text><text x=\"52\" y=\"287.9\" text-anchor=\"start\" font-size=\"15\" font-weight=\"700\" fill=\"var(--text)\">Ler a estrutura da página</text><text x=\"52\" y=\"309.8\" text-anchor=\"start\" font-size=\"14\" fill=\"var(--text-muted)\">leitura nova a cada transição</text></g><line x1=\"160\" y1=\"323.79999999999995\" x2=\"160\" y2=\"345.79999999999995\" stroke=\"var(--text-muted)\" stroke-width=\"2\" marker-end=\"url(#aid2-seta)\"/><g class=\"aid2-in aid2-n4\"><polygon points=\"12,377.79999999999995 36,347.79999999999995 284,347.79999999999995 308,377.79999999999995 284,407.79999999999995 36,407.79999999999995\" fill=\"var(--bg-white)\" stroke=\"var(--accent)\" stroke-width=\"2\"/><text x=\"160\" y=\"372.8\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text)\">o estado esperado apareceu?</text><text x=\"160\" y=\"391.8\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text)\">se não → DESISTIR</text></g><line x1=\"160\" y1=\"407.79999999999995\" x2=\"160\" y2=\"436.79999999999995\" stroke=\"var(--text-muted)\" stroke-width=\"2\" marker-end=\"url(#aid2-seta)\"/><text x=\"170\" y=\"428.3\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text-muted)\">sim</text><g class=\"aid2-in aid2-n5\"><rect x=\"12\" y=\"438.79999999999995\" width=\"296\" height=\"62.1\" rx=\"8\" fill=\"var(--bg-white)\" stroke=\"var(--border)\" stroke-width=\"1.5\"/><circle cx=\"35\" cy=\"460.0\" r=\"11\" fill=\"var(--accent)\"/><text x=\"35\" y=\"465.0\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text-on-accent)\">3</text><text x=\"52\" y=\"465.0\" text-anchor=\"start\" font-size=\"15\" font-weight=\"700\" fill=\"var(--text)\">Preencher o formulário</text><text x=\"52\" y=\"486.9\" text-anchor=\"start\" font-size=\"14\" fill=\"var(--text-muted)\">ancorando por papel e rótulo</text></g><line x1=\"160\" y1=\"500.94999999999993\" x2=\"160\" y2=\"522.9499999999999\" stroke=\"var(--text-muted)\" stroke-width=\"2\" marker-end=\"url(#aid2-seta)\"/><g class=\"aid2-in aid2-n6\"><polygon points=\"12,554.9499999999999 36,524.9499999999999 284,524.9499999999999 308,554.9499999999999 284,584.9499999999999 36,584.9499999999999\" fill=\"var(--bg-white)\" stroke=\"var(--accent)\" stroke-width=\"2\"/><text x=\"160\" y=\"549.9\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text)\">o estado esperado apareceu?</text><text x=\"160\" y=\"568.9\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text)\">se não → DESISTIR</text></g><line x1=\"160\" y1=\"584.9499999999999\" x2=\"160\" y2=\"613.9499999999999\" stroke=\"var(--text-muted)\" stroke-width=\"2\" marker-end=\"url(#aid2-seta)\"/><text x=\"170\" y=\"605.4\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text-muted)\">sim</text><g class=\"aid2-in aid2-n7\"><rect x=\"12\" y=\"615.9499999999999\" width=\"296\" height=\"62.1\" rx=\"8\" fill=\"var(--bg-white)\" stroke=\"var(--border)\" stroke-width=\"1.5\"/><circle cx=\"35\" cy=\"637.2\" r=\"11\" fill=\"var(--accent)\"/><text x=\"35\" y=\"642.2\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text-on-accent)\">4</text><text x=\"52\" y=\"642.2\" text-anchor=\"start\" font-size=\"15\" font-weight=\"700\" fill=\"var(--text)\">Escrever uma vez só</text><text x=\"52\" y=\"664.1\" text-anchor=\"start\" font-size=\"14\" font-family=\"ui-monospace, SFMono-Regular, Menlo, monospace\" fill=\"var(--accent-dark)\">Idempotency-Key: 8f2c…a91</text></g><line x1=\"160\" y1=\"678.0999999999999\" x2=\"160\" y2=\"700.0999999999999\" stroke=\"var(--text-muted)\" stroke-width=\"2\" marker-end=\"url(#aid2-seta)\"/><g class=\"aid2-in aid2-n8\"><polygon points=\"12,732.0999999999999 36,702.0999999999999 284,702.0999999999999 308,732.0999999999999 284,762.0999999999999 36,762.0999999999999\" fill=\"var(--bg-white)\" stroke=\"var(--accent)\" stroke-width=\"2\"/><text x=\"160\" y=\"727.1\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text)\">o estado esperado apareceu?</text><text x=\"160\" y=\"746.1\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text)\">se não → DESISTIR</text></g><line x1=\"160\" y1=\"762.0999999999999\" x2=\"160\" y2=\"791.0999999999999\" stroke=\"var(--text-muted)\" stroke-width=\"2\" marker-end=\"url(#aid2-seta)\"/><text x=\"170\" y=\"782.6\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text-muted)\">sim</text><g class=\"aid2-in aid2-n9\"><rect x=\"12\" y=\"793.0999999999999\" width=\"296\" height=\"101.3\" rx=\"8\" fill=\"var(--bg-white)\" stroke=\"var(--border)\" stroke-width=\"1.5\"/><circle cx=\"35\" cy=\"814.3\" r=\"11\" fill=\"var(--accent)\"/><text x=\"35\" y=\"819.3\" text-anchor=\"middle\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text-on-accent)\">5</text><text x=\"52\" y=\"819.3\" text-anchor=\"start\" font-size=\"15\" font-weight=\"700\" fill=\"var(--text)\">Confirmar o efeito na</text><text x=\"52\" y=\"839.6\" text-anchor=\"start\" font-size=\"15\" font-weight=\"700\" fill=\"var(--text)\">fonte</text><text x=\"52\" y=\"861.5\" text-anchor=\"start\" font-size=\"14\" fill=\"var(--text-muted)\">exatamente um registro no</text><text x=\"52\" y=\"880.4\" text-anchor=\"start\" font-size=\"14\" fill=\"var(--text-muted)\">destino</text></g><g class=\"aid2-in aid2-n10\"><rect x=\"12\" y=\"908.3999999999999\" width=\"296\" height=\"217.4\" rx=\"8\" fill=\"var(--danger-light)\" stroke=\"var(--danger)\" stroke-width=\"2\"/><text x=\"24\" y=\"933.3\" text-anchor=\"start\" font-size=\"14\" font-weight=\"700\" fill=\"var(--danger)\">todo “não” vem para cá</text><text x=\"24\" y=\"953.5\" text-anchor=\"start\" font-size=\"15\" font-weight=\"700\" fill=\"var(--danger)\">DESISTIR</text><text x=\"24\" y=\"975.4\" text-anchor=\"start\" font-size=\"14\" fill=\"var(--text)\">Parar. Não improvisar caminho</text><text x=\"24\" y=\"994.3\" text-anchor=\"start\" font-size=\"14\" fill=\"var(--text)\">alternativo.</text><text x=\"24\" y=\"1013.2\" text-anchor=\"start\" font-size=\"14\" font-weight=\"700\" fill=\"var(--text)\">Relatar três campos:</text><text x=\"24\" y=\"1032.1\" text-anchor=\"start\" font-size=\"14\" fill=\"var(--text)\">em qual passo parou</text><text x=\"24\" y=\"1051.0\" text-anchor=\"start\" font-size=\"14\" fill=\"var(--text)\">o que esperava</text><text x=\"24\" y=\"1070.0\" text-anchor=\"start\" font-size=\"14\" fill=\"var(--text)\">o que encontrou</text><text x=\"24\" y=\"1092.9\" text-anchor=\"start\" font-size=\"14\" fill=\"var(--danger)\">Nenhuma escrita é tentada depois</text><text x=\"24\" y=\"1111.8\" text-anchor=\"start\" font-size=\"14\" fill=\"var(--danger)\">disso.</text></g><text x=\"160\" y=\"1154.7\" text-anchor=\"middle\" font-size=\"14\" fill=\"var(--text-muted)\">Cada losango espera por um estado</text><text x=\"160\" y=\"1173.6\" text-anchor=\"middle\" font-size=\"14\" fill=\"var(--text-muted)\">observável da página. O prazo máximo</text><text x=\"160\" y=\"1192.5\" text-anchor=\"middle\" font-size=\"14\" fill=\"var(--text-muted)\">serve para desistir, nunca para</text><text x=\"160\" y=\"1211.4\" text-anchor=\"middle\" font-size=\"14\" fill=\"var(--text-muted)\">sincronizar.</text><text x=\"160\" y=\"1240.4\" text-anchor=\"middle\" font-size=\"14\" fill=\"var(--text-muted)\">Em sites reais o agente falha com</text><text x=\"160\" y=\"1259.4\" text-anchor=\"middle\" font-size=\"14\" fill=\"var(--text-muted)\">frequência: a desistência é caminho</text><text x=\"160\" y=\"1278.4\" text-anchor=\"middle\" font-size=\"14\" fill=\"var(--text-muted)\">previsto, não exceção.</text></svg>","label":"O roteiro que aguenta imprevisto tem um ponto de verificação entre cada par de passos, e todas as saídas negativas convergem para o mesmo lugar: parar e relatar. Desistência é caminho previsto, não exceção."},{"type":"callout","label":"Decisão","value":"Ao interromper, registre o passo, o resultado esperado, o observado e a chave da operação. Isso permite conferir o destino antes de repetir."},{"type":"warning","value":"Se houver um diálogo de confirmação, leia seu conteúdo e aplique a decisão prevista no teste. Aceitar um diálogo pode enviar ou excluir algo; não o feche automaticamente só para continuar."},{"type":"figure","value":"<div data-captura-real=\"playwright-isolation-1\" style=\"display:grid;gap:14px\"><div class=\"cp-rotulo\">Na fonte</div><img class=\"cp-img-link\" src=\"https://midia.brasilgeo.ai/educacao/capturas-executivas-20261024/playwright-isolation-1.webp\" width=\"1200\" height=\"833\" alt=\"Contextos separados evitam compartilhar estado entre testes.\" loading=\"lazy\" decoding=\"async\" style=\"display:block;width:100%;height:auto;max-width:900px;margin:0 auto\" /><div class=\"cp-meta\"><a href=\"https://playwright.dev/docs/browser-contexts\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"cp-link\">Consultar a fonte original</a><span style=\"color:var(--text-muted)\">Captura em 24/10/2026</span></div></div>","label":"Contextos separados evitam compartilhar estado entre testes."},{"type":"prompt","title":"Pedir ao agente o roteiro com as três travas","value":"Prepare um teste local sem rede para criar um cadastro fictício. Use o destino simulado abaixo: ele reconhece a chave, cria um único registro e simula a perda da primeira resposta.\n\nConfira três execuções com a mesma chave e os mesmos dados. Depois faça uma operação diferente com outra chave. Registre os identificadores. Não use clientes nem sistemas de produção."},{"type":"mockup","title":"Rodar o roteiro três vezes e ficar com um registro só","value":"$ node testar-lead.mjs\nIDs da mesma operação: 1041, 1041, 1041\nRegistros após três execuções: 1\nID da nova operação: 1042\nRegistros ao final: 2"},{"type":"code","language":"javascript","value":"// testar-lead.mjs: salve junto de enviar-lead.mjs e execute com Node.js.\nimport { enviarLead } from \"./enviar-lead.mjs\";\nconst registros = new Map();\nlet perderPrimeiraResposta = true;\nasync function destinoSimulado(_url, pedido) {\n  const chave = pedido.headers[\"Idempotency-Key\"];\n  const anterior = registros.get(chave);\n  if (anterior && anterior.corpo !== pedido.body) {\n    return {ok: false, status: 409};\n  }\n  if (!anterior) registros.set(chave, {id: 1041 + registros.size, corpo: pedido.body});\n  if (perderPrimeiraResposta) {\n    perderPrimeiraResposta = false;\n    throw new Error(\"Resposta perdida após a criação.\");\n  }\n  return {ok: true, status: 200, json: async () => ({id: registros.get(chave).id})};\n}\nconst ids = [];\nfor (let i = 0; i < 3; i++) {\n  const resultado = await enviarLead(\"https://destino.test/leads\", {nome: \"Pessoa de teste\"}, \"operacao-a\", destinoSimulado, async () => {});\n  ids.push(resultado.id);\n}\nconsole.log(\"IDs da mesma operação:\", ids.join(\", \"));\nconsole.log(\"Registros após três execuções:\", registros.size);\nconst nova = await enviarLead(\"https://destino.test/leads\", {nome: \"Outra pessoa de teste\"}, \"operacao-b\", destinoSimulado, async () => {});\nconsole.log(\"ID da nova operação:\", nova.id);\nconsole.log(\"Registros ao final:\", registros.size);\n\n// O mapa existe apenas nesta execução didática. Um sistema real precisa\n// guardar chave, dados e resultado de forma durável e atômica no destino.","codeHtml":"<span class=\"line\"><span class=\"cc-9sSsV5\">// testar-lead.mjs: salve junto de enviar-lead.mjs e execute com Node.js.</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">import</span><span class=\"cc-0lkzTf\"> {</span><span class=\"cc-Zg_G8Q\"> enviarLead </span><span class=\"cc-0lkzTf\">}</span><span class=\"cc-LG_FCO\"> from</span><span class=\"cc-Vmk6LI\"> \"./enviar-lead.mjs\"</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">const</span><span class=\"cc-Zg_G8Q\"> registros </span><span class=\"cc-gX46La\">=</span><span class=\"cc-9pAnQC\"> new</span><span class=\"cc-Np3vnr\"> Map</span><span class=\"cc-Zg_G8Q\">()</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">let</span><span class=\"cc-Zg_G8Q\"> perderPrimeiraResposta </span><span class=\"cc-gX46La\">=</span><span class=\"cc-wVAnzj\"> true</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">async</span><span class=\"cc-LG_FCO\"> function</span><span class=\"cc-Np3vnr\"> destinoSimulado</span><span class=\"cc-0lkzTf\">(</span><span class=\"cc-EHq2D4\">_url</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-EHq2D4\"> pedido</span><span class=\"cc-0lkzTf\">)</span><span class=\"cc-0lkzTf\"> {</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">  const</span><span class=\"cc-Zg_G8Q\"> chave </span><span class=\"cc-gX46La\">=</span><span class=\"cc-Zg_G8Q\"> pedido</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Zg_G8Q\">headers[</span><span class=\"cc-Vmk6LI\">\"Idempotency-Key\"</span><span class=\"cc-Zg_G8Q\">]</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">  const</span><span class=\"cc-Zg_G8Q\"> anterior </span><span class=\"cc-gX46La\">=</span><span class=\"cc-Zg_G8Q\"> registros</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">get</span><span class=\"cc-Zg_G8Q\">(chave)</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">  if</span><span class=\"cc-Zg_G8Q\"> (anterior </span><span class=\"cc-gX46La\">&#x26;&#x26;</span><span class=\"cc-Zg_G8Q\"> anterior</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Zg_G8Q\">corpo </span><span class=\"cc-gX46La\">!==</span><span class=\"cc-Zg_G8Q\"> pedido</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Zg_G8Q\">body) </span><span class=\"cc-0lkzTf\">{</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">    return</span><span class=\"cc-0lkzTf\"> {</span><span class=\"cc-Zg_G8Q\">ok</span><span class=\"cc-gX46La\">:</span><span class=\"cc-wVAnzj\"> false</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-Zg_G8Q\"> status</span><span class=\"cc-gX46La\">:</span><span class=\"cc-wVAnzj\"> 409</span><span class=\"cc-0lkzTf\">};</span></span>\n<span class=\"line\"><span class=\"cc-0lkzTf\">  }</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">  if</span><span class=\"cc-Zg_G8Q\"> (</span><span class=\"cc-gX46La\">!</span><span class=\"cc-Zg_G8Q\">anterior) registros</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">set</span><span class=\"cc-Zg_G8Q\">(chave</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-0lkzTf\"> {</span><span class=\"cc-Zg_G8Q\">id</span><span class=\"cc-gX46La\">:</span><span class=\"cc-wVAnzj\"> 1041</span><span class=\"cc-gX46La\"> +</span><span class=\"cc-Zg_G8Q\"> registros</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Zg_G8Q\">size</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-Zg_G8Q\"> corpo</span><span class=\"cc-gX46La\">:</span><span class=\"cc-Zg_G8Q\"> pedido</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Zg_G8Q\">body</span><span class=\"cc-0lkzTf\">}</span><span class=\"cc-Zg_G8Q\">)</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">  if</span><span class=\"cc-Zg_G8Q\"> (perderPrimeiraResposta) </span><span class=\"cc-0lkzTf\">{</span></span>\n<span class=\"line\"><span class=\"cc-Zg_G8Q\">    perderPrimeiraResposta </span><span class=\"cc-gX46La\">=</span><span class=\"cc-wVAnzj\"> false</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">    throw</span><span class=\"cc-9pAnQC\"> new</span><span class=\"cc-Np3vnr\"> Error</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-Vmk6LI\">\"Resposta perdida após a criação.\"</span><span class=\"cc-Zg_G8Q\">)</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-0lkzTf\">  }</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">  return</span><span class=\"cc-0lkzTf\"> {</span><span class=\"cc-Zg_G8Q\">ok</span><span class=\"cc-gX46La\">:</span><span class=\"cc-wVAnzj\"> true</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-Zg_G8Q\"> status</span><span class=\"cc-gX46La\">:</span><span class=\"cc-wVAnzj\"> 200</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-Np3vnr\"> json</span><span class=\"cc-gX46La\">:</span><span class=\"cc-LG_FCO\"> async</span><span class=\"cc-0lkzTf\"> ()</span><span class=\"cc-LG_FCO\"> =></span><span class=\"cc-Zg_G8Q\"> (</span><span class=\"cc-0lkzTf\">{</span><span class=\"cc-Zg_G8Q\">id</span><span class=\"cc-gX46La\">:</span><span class=\"cc-Zg_G8Q\"> registros</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">get</span><span class=\"cc-Zg_G8Q\">(chave)</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Zg_G8Q\">id</span><span class=\"cc-0lkzTf\">}</span><span class=\"cc-Zg_G8Q\">)</span><span class=\"cc-0lkzTf\">};</span></span>\n<span class=\"line\"><span class=\"cc-0lkzTf\">}</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">const</span><span class=\"cc-Zg_G8Q\"> ids </span><span class=\"cc-gX46La\">=</span><span class=\"cc-Zg_G8Q\"> []</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">for</span><span class=\"cc-Zg_G8Q\"> (</span><span class=\"cc-LG_FCO\">let</span><span class=\"cc-Zg_G8Q\"> i </span><span class=\"cc-gX46La\">=</span><span class=\"cc-wVAnzj\"> 0</span><span class=\"cc-0lkzTf\">;</span><span class=\"cc-Zg_G8Q\"> i </span><span class=\"cc-gX46La\">&#x3C;</span><span class=\"cc-wVAnzj\"> 3</span><span class=\"cc-0lkzTf\">;</span><span class=\"cc-Zg_G8Q\"> i</span><span class=\"cc-gX46La\">++</span><span class=\"cc-Zg_G8Q\">) </span><span class=\"cc-0lkzTf\">{</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">  const</span><span class=\"cc-Zg_G8Q\"> resultado </span><span class=\"cc-gX46La\">=</span><span class=\"cc-LG_FCO\"> await</span><span class=\"cc-Np3vnr\"> enviarLead</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-Vmk6LI\">\"https://destino.test/leads\"</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-0lkzTf\"> {</span><span class=\"cc-Zg_G8Q\">nome</span><span class=\"cc-gX46La\">:</span><span class=\"cc-Vmk6LI\"> \"Pessoa de teste\"</span><span class=\"cc-0lkzTf\">},</span><span class=\"cc-Vmk6LI\"> \"operacao-a\"</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-Zg_G8Q\"> destinoSimulado</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-LG_FCO\"> async</span><span class=\"cc-0lkzTf\"> ()</span><span class=\"cc-LG_FCO\"> =></span><span class=\"cc-0lkzTf\"> {}</span><span class=\"cc-Zg_G8Q\">)</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-Zg_G8Q\">  ids</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">push</span><span class=\"cc-Zg_G8Q\">(resultado</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Zg_G8Q\">id)</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-0lkzTf\">}</span></span>\n<span class=\"line\"><span class=\"cc-Zg_G8Q\">console</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">log</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-Vmk6LI\">\"IDs da mesma operação:\"</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-Zg_G8Q\"> ids</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">join</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-Vmk6LI\">\", \"</span><span class=\"cc-Zg_G8Q\">))</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-Zg_G8Q\">console</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">log</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-Vmk6LI\">\"Registros após três execuções:\"</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-Zg_G8Q\"> registros</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Zg_G8Q\">size)</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-LG_FCO\">const</span><span class=\"cc-Zg_G8Q\"> nova </span><span class=\"cc-gX46La\">=</span><span class=\"cc-LG_FCO\"> await</span><span class=\"cc-Np3vnr\"> enviarLead</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-Vmk6LI\">\"https://destino.test/leads\"</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-0lkzTf\"> {</span><span class=\"cc-Zg_G8Q\">nome</span><span class=\"cc-gX46La\">:</span><span class=\"cc-Vmk6LI\"> \"Outra pessoa de teste\"</span><span class=\"cc-0lkzTf\">},</span><span class=\"cc-Vmk6LI\"> \"operacao-b\"</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-Zg_G8Q\"> destinoSimulado</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-LG_FCO\"> async</span><span class=\"cc-0lkzTf\"> ()</span><span class=\"cc-LG_FCO\"> =></span><span class=\"cc-0lkzTf\"> {}</span><span class=\"cc-Zg_G8Q\">)</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-Zg_G8Q\">console</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">log</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-Vmk6LI\">\"ID da nova operação:\"</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-Zg_G8Q\"> nova</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Zg_G8Q\">id)</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"><span class=\"cc-Zg_G8Q\">console</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Np3vnr\">log</span><span class=\"cc-Zg_G8Q\">(</span><span class=\"cc-Vmk6LI\">\"Registros ao final:\"</span><span class=\"cc-0lkzTf\">,</span><span class=\"cc-Zg_G8Q\"> registros</span><span class=\"cc-gX46La\">.</span><span class=\"cc-Zg_G8Q\">size)</span><span class=\"cc-0lkzTf\">;</span></span>\n<span class=\"line\"></span>\n<span class=\"line\"><span class=\"cc-9sSsV5\">// O mapa existe apenas nesta execução didática. Um sistema real precisa</span></span>\n<span class=\"line\"><span class=\"cc-9sSsV5\">// guardar chave, dados e resultado de forma durável e atômica no destino.</span></span>"},{"type":"tip","value":"No laboratório de interface, teste também botão ausente, rede lenta e diálogo inesperado. Faça uma mudança por vez e confira se a rotina interrompe no ponto previsto."},{"type":"text","value":"#### [icone:list-checks] Confira o teste\n\nA mesma operação devolve 1041 nas três execuções e mantém um registro. Outra chave, com outra pessoa fictícia, cria 1042. Para uma integração real, confira também recuperação após reinício e escritas simultâneas no destino."},{"type":"fontes","value":"","data":{"items":[{"source":"Playwright MCP v0.0.83","date":"2026-09-28","url":"https://github.com/microsoft/playwright-mcp/releases/tag/v0.0.83"},{"source":"Authentication no Playwright","date":"documentação consultada em 2026-10-24","url":"https://playwright.dev/docs/auth"},{"source":"Isolation no Playwright","date":"documentação consultada em 2026-10-24","url":"https://playwright.dev/docs/browser-contexts"}]}}]}]}