Skip to content

Automate browser based workflows with AI

Stop the Task V3 answer check from holding radio and checkbox picks (SKY-18212) (#8899)

Shuchang Zhengb172e91e7431
diff --git a/skyvern/forge/taskv3/answer_basis_audit.py b/skyvern/forge/taskv3/answer_basis_audit.py
index ebef35dd4..f9e53f147 100644
--- a/skyvern/forge/taskv3/answer_basis_audit.py
+++ b/skyvern/forge/taskv3/answer_basis_audit.py
@@ -71,19 +71,15 @@ def _may_move_on(tool: str, args: dict[str, Any]) -> bool:
return _may_submit(tool, args) and not (tool == "click" and _MENU_ROW.search(_selector(args)))
-def apply_answer_basis_audit(tools: list[ToolSpec], audit: AnswerBasisAudit | None) -> Callable[[], int] | None:
- """Wraps the tools; returns 1 while the last moving action was refused, for the run's end (a hold never cleared)."""
+def apply_answer_basis_audit(tools: list[ToolSpec], audit: AnswerBasisAudit | None) -> None:
if audit is None:
- return None
+ return
# Each answer's audit starts when it is recorded, so the call overlaps the model's next turns instead of delaying
# the moving click.
pending: dict[Field, tuple[str, asyncio.Task[list[RecordedAnswer]]]] = {}
flagged: dict[Field, str] = {}
refused: set[tuple[Field, str]] = set()
- picks: set[Field] = set()
- checked = next((spec.choice_checked for spec in tools if spec.choice_checked is not None), None)
open_menu: dict[str, Field | None] = {"field": None}
- holding = [0]
def record(field: Field, value: str) -> None:
previous = pending.pop(field, None)
@@ -101,18 +97,6 @@ def apply_answer_basis_audit(tools: list[ToolSpec], audit: AnswerBasisAudit | No
LOG.warning("taskv3 answer basis audit raised; not blocking", exc_info=True)
return False
- async def unpicked() -> None:
- # A pick holds only while it is still checked: picking another option, or unchecking it, takes it back.
- for pick in [f for f in flagged if f in picks]:
- if checked is not None and await checked(pick[1]) is False:
- del flagged[pick]
-
- def unresolved(task: asyncio.Task[list[RecordedAnswer]]) -> bool:
- return not task.done() or (not task.cancelled() and task.exception() is None and bool(task.result()))
-
- def settled() -> list[Field]:
- return [f for f, (_, task) in pending.items() if task.done() and unresolved(task)]
-
async def hold(
spec: ToolSpec, args: dict[str, Any], entering: tuple[Field, str] | None = None, appends: bool = False
) -> bool:
@@ -121,7 +105,6 @@ def apply_answer_basis_audit(tools: list[ToolSpec], audit: AnswerBasisAudit | No
field, (value, task) = pending.popitem()
if await found(task):
flagged[field] = value
- await unpicked()
shown = dict(flagged)
untyped = None
# The answer a call enters is judged as if it had landed, recording nothing, and never twice once refused.
@@ -133,7 +116,6 @@ def apply_answer_basis_audit(tools: list[ToolSpec], audit: AnswerBasisAudit | No
refused.add(entering)
shown[entering[0]] = entering[1]
untyped = entering[0]
- holding[0] = 0
if not shown:
return False
# A click cannot be told from a submit before it lands, so only the flagged field's own control, or a row of an
@@ -142,7 +124,6 @@ def apply_answer_basis_audit(tools: list[ToolSpec], audit: AnswerBasisAudit | No
selector, menu_row = await spec.address_probe(args) if spec.address_probe else (_selector(args), False)
if menu_row or any(selector == field[1] for field in flagged):
return True
- holding[0] = 1
LOG.info("taskv3 answer basis hold", tool=spec.name, flagged=len(shown))
named = "; ".join(
f"'{q}' with '{v}' (field {s}; not typed, nothing was entered or pressed)"
@@ -178,14 +159,7 @@ def apply_answer_basis_audit(tools: list[ToolSpec], audit: AnswerBasisAudit | No
entering = ((label.strip(), selector), text)
elif not selector:
LOG.info("taskv3 answer basis probe missed", tool=_tool)
- # Read before the call, which rewrites a ref to its selector. A radio or checkbox click picks an answer, so it
- # waits on no earlier answer; it is held only while another kind of answer is already flagged.
- choice = _spec.choice_probe(args) if _spec.choice_probe is not None else None
- repair = (
- _may_move_on(_tool, args)
- and (choice is None or any(f not in picks for f in [*flagged, *settled()]))
- and await hold(_spec, args, entering, not args.get("clear", True))
- )
+ repair = _may_move_on(_tool, args) and await hold(_spec, args, entering, not args.get("clear", True))
result = await _handler(args)
data = _data(result)
picked = str(data.get(PICKED_OPTION_DATA_KEY) or "") if _tool == "click" and result.status == "ok" else ""
@@ -206,21 +180,6 @@ def apply_answer_basis_audit(tools: list[ToolSpec], audit: AnswerBasisAudit | No
return result
# The ref resolver rewrites args["selector"] in place, so this is the selector the call acted on.
field = (_label(result), _selector(args))
- if choice is not None:
- # Each picked option is its own answer under its group's question; picking it again is not a second
- # chance at the judge.
- field = (choice[0], field[1])
- picks.add(field)
- if data.get("page_transitioned"):
- # Only a flag still standing, or a judgment still running, counts.
- await unpicked()
- waiting = any(unresolved(task) for _, task in pending.values())
- LOG.info(
- "taskv3 answer basis pick advanced", pick_advanced=1, flag_pending=int(bool(flagged) or waiting)
- )
- if flagged.get(field) != choice[1]:
- record(field, choice[1])
- return result
if entering is not None and field == entering[0]:
record(field, "")
return result
@@ -235,6 +194,3 @@ def apply_answer_basis_audit(tools: list[ToolSpec], audit: AnswerBasisAudit | No
return result
spec.handler = wrapped
-
- # A flag the model cleared after its last refused move is not a hold that persisted.
- return lambda: int(bool(holding[0] and flagged))
diff --git a/skyvern/forge/taskv3/engine.py b/skyvern/forge/taskv3/engine.py
index e23f7744d..22efa4e18 100644
--- a/skyvern/forge/taskv3/engine.py
+++ b/skyvern/forge/taskv3/engine.py
@@ -651,7 +651,7 @@ async def run_task_v3_agent_loop(
step=step,
)
)
- answer_hold = apply_answer_basis_audit(tools, answer_audit)
+ apply_answer_basis_audit(tools, answer_audit)
# Only the acting model gets typed rows: the judge and re-ask read `model_goal` on their own model, and an oversized
# judge prompt fails open. Rows stay unminted because resolve_typed_text was chained to refs above.
prompt_goal = model_goal
@@ -793,7 +793,6 @@ async def run_task_v3_agent_loop(
age_default_reason=age_default_reason,
application_defaults_rendered=bool(application_defaults_text),
application_defaults_reason=application_defaults_reason,
- answer_hold_at_end=answer_hold() if answer_hold is not None else None,
# The run's model, so exposure rates on this line split per model like the re-ask line's.
llm_key=llm_caller.llm_key,
unlisted_reask=outcome.unlisted_reask,
diff --git a/skyvern/forge/taskv3/loop.py b/skyvern/forge/taskv3/loop.py
index 0be95ae94..17178b276 100644
--- a/skyvern/forge/taskv3/loop.py
+++ b/skyvern/forge/taskv3/loop.py
@@ -654,10 +654,6 @@ class ToolSpec:
address_probe: Callable[[dict[str, Any]], Awaitable[tuple[str, bool]]] | None = None
# The selector, name and kind of the field a type call is about to enter, read before it acts; set on type alone.
answer_probe: Callable[[dict[str, Any]], Awaitable[tuple[str, str, str]]] | None = None
- # The question and caption observe read for a radio or checkbox ref, and whether a picked one is still checked;
- # set on click alone.
- choice_probe: Callable[[dict[str, Any]], tuple[str, str] | None] | None = None
- choice_checked: Callable[[str], Awaitable[bool | None]] | None = None
@property
def touches_page(self) -> bool:
diff --git a/skyvern/forge/taskv3/tools.py b/skyvern/forge/taskv3/tools.py
index 4a08bef02..a0eb20231 100644
--- a/skyvern/forge/taskv3/tools.py
+++ b/skyvern/forge/taskv3/tools.py
@@ -7008,19 +7008,6 @@ _SKINNED_CHECKBOX_PROBE_JS = (
}"""
)
-# Whether a picked radio or checkbox is still checked, native or ARIA; null when it cannot be read.
-_CHOICE_CHECKED_JS = (
- r"""(arg) => {
- const _q = """
- + _ROOT_QUERY_JS
- + r""";
- const el = _q.find(arg.sel);
- if (!el) return null;
- if (el.type === 'radio' || el.type === 'checkbox') return !!el.checked;
- const a = el.getAttribute('aria-checked');
- return a === 'true' ? true : a === 'false' ? false : null;
-}"""
-)
# Read twice (before and after the forced click): a proxy that does not sync from its native input
# must fail loud, not read as a successful toggle.
_CHECKBOX_CHECKED_JS = (
@@ -22008,26 +21995,6 @@ def build_browser_tools(
return "", False
return str(resolved.get("selector") or ""), bool((result.data or {}).get("menu_row"))
- _pick_realms: dict[str, Any] = {}
-
- def _click_choice(args: dict[str, Any]) -> tuple[str, str] | None:
- # Read from observe's own record of the ref, so the answer is filed under the question observe showed.
- ref = REF_SELECTOR_RE.match(str(args.get("selector") or "")) if args.get("mark") is None else None
- entry = _observe_manifest.get(int(ref.group(1))) if ref else None
- if not entry or not entry.get("question") or not entry.get("choice"):
- return None
- # A pick is read back in the frame and document it was observed in, under the selector the click leaves in its
- # arguments; a selector seen in two live frames or documents is read nowhere, so its hold stays. A detached
- # frame is replaced, not counted.
- key, realm = str(entry.get("selector") or ""), (entry.get("owner"), str(entry.get("document") or ""))
- prior: Any = _pick_realms.get(key, realm)
- try:
- gone = prior[0].is_detached() is True
- except Exception:
- gone = False
- _pick_realms[key] = realm if prior == realm or gone else _UNKNOWN_REALM
- return entry["question"], entry.get("option") or ""
-
def _with_pick_echo(handler: ToolHandler) -> ToolHandler:
# Names the question observe bound the clicked option to, so a wrong pairing is visible in the result.
@functools.wraps(handler)
@@ -22058,19 +22025,6 @@ def build_browser_tools(
return wrapped
- async def _choice_checked(selector: str) -> bool | None:
- realm = _pick_realms.get(selector, (None, ""))
- if realm is _UNKNOWN_REALM:
- return None
- try:
- target = realm[0] or _current_page()
- # A postback or a frame that navigated in place can put another control under the same marker.
- if realm[1] and realm[1] != await _realm_document_id(target):
- return None
- return await _probe_evaluate(target, _CHOICE_CHECKED_JS, selector, {"sel": selector, "el": None})
- except Exception:
- return None
-
async def _answer_target(args: dict[str, Any]) -> ToolResult:
page, error = await _resolve_page()
if error is not None:
@@ -22328,8 +22282,6 @@ def build_browser_tools(
_tool_spec.handler = _with_pick_echo(_tool_spec.handler)
_tool_spec.toggle_probe = _click_targets_toggle
_tool_spec.address_probe = _click_address
- _tool_spec.choice_probe = _click_choice
- _tool_spec.choice_checked = _choice_checked
elif _tool_spec.name == "type":
_tool_spec.answer_probe = _answer_field
# Inside the download signal, so a download notice stays the last thing in a result.
diff --git a/tests/unit/test_taskv3_answer_basis_audit.py b/tests/unit/test_taskv3_answer_basis_audit.py
index 7881fce2d..9b88bd6aa 100644
--- a/tests/unit/test_taskv3_answer_basis_audit.py
+++ b/tests/unit/test_taskv3_answer_basis_audit.py
@@ -1,4 +1,3 @@
-import asyncio
from typing import Any
import pytest
@@ -47,20 +46,11 @@ async def _answer(args: dict[str, Any]) -> tuple[str, str, str]:
return str(args.get("_probed", args.get("selector"))), str(args.get("_label", "")), args.get("_kind", "textbox")
-def _tools(dispatched: list[tuple[str, dict[str, Any]]], page: dict[str, bool] | None = None) -> list[ToolSpec]:
- # Which radios and checkboxes the fake page shows checked; a pick sets the states it lists in `_sets`.
- page = {} if page is None else page
-
- async def checked(selector: str) -> bool | None:
- return page.get(selector)
-
+def _tools(dispatched: list[tuple[str, dict[str, Any]]]) -> list[ToolSpec]:
def make(name: str) -> ToolSpec:
async def handler(args: dict[str, Any]) -> ToolResult:
dispatched.append((name, args))
sel = str(args.get("selector") or "")
- if "_choice" in args:
- page.update(args.get("_sets", {}))
- return ToolResult("ok", f"clicked {sel}", {"page_transitioned": args.get("_advances", False)})
if args.get("_fail"):
return ToolResult("error", f"{name} failed", {}, error_class="not_editable")
if name == "click" and "_row" in args:
@@ -77,14 +67,7 @@ def _tools(dispatched: list[tuple[str, dict[str, Any]]], page: dict[str, bool] |
probe = _answer if name == "type" else None
return ToolSpec(
- name=name,
- description="",
- parameters={},
- handler=handler,
- address_probe=_address,
- answer_probe=probe,
- choice_probe=(lambda args: args.get("_choice")) if name == "click" else None,
- choice_checked=checked if name == "click" else None,
+ name=name, description="", parameters={}, handler=handler, address_probe=_address, answer_probe=probe
)
names = ("click", "type", "select_option", "select_combobox", "press_key", CODE_TOOL_NAME, "observe")
@@ -170,22 +153,18 @@ async def test_two_fields_with_the_same_label_are_audited_apart() -> None:
async def test_the_refusal_stops_only_on_a_required_question_and_a_cleared_answer_lifts_the_hold() -> None:
dispatched: list[tuple[str, dict[str, Any]]] = []
tools = _tools(dispatched)
- holding = apply_answer_basis_audit(tools, _Audit(flag={"Canadian", "Yes"}))
- assert holding is not None
+ apply_answer_basis_audit(tools, _Audit(flag={"Canadian", "Yes"}))
await _by_name(tools, "type").handler({"selector": "#nat", "text": "Canadian", "_label": "Nationality"})
await _by_name(tools, "select_combobox").handler({"selector": "#auth", "value": "Yes", "_label": "Authorized?"})
message = await _held(tools, "click", {"selector": "#next"})
- # A run that ended here would end held: the pre-registered count of holds never cleared.
- assert holding() == 1
assert "if the question is required, stop" in message and "if it is optional, clear it and continue" in message
assert "'Nationality' answered 'Canadian'" in message and "'Authorized?' answered 'Yes'" in message
await _by_name(tools, "type").handler({"selector": "#nat", "text": "", "_label": "Nationality"})
await _by_name(tools, "select_combobox").handler({"selector": "#auth", "value": "", "_label": "Authorized?"})
- assert holding() == 0
await _by_name(tools, "click").handler({"selector": "#next"})
- assert ("click", {"selector": "#next"}) in dispatched and holding() == 0
+ assert ("click", {"selector": "#next"}) in dispatched
@pytest.mark.asyncio
@@ -329,97 +308,3 @@ async def test_a_typed_enter_the_probe_cannot_place_is_still_recorded_after_the_
await _by_name(tools, "type").handler({**TYPED, "_probed": "#elsewhere", "text": "Yes"})
await _by_name(tools, "click").handler({"selector": "#submit"})
assert [name for name, _ in dispatched] == ["type", "click"] and len(audit.seen) == 2
-
-
-AUTH_Q = "Are you legally authorized to work in the United States?"
-
-
-def _pick(ref: str, question: str, option: str, sets: dict[str, bool]) -> dict[str, Any]:
- return {"selector": ref, "_choice": (question, option), "_sets": sets}
-
-
-async def test_a_picked_option_is_an_answer_held_only_while_it_stays_checked() -> None:
- dispatched: list[tuple[str, dict[str, Any]]] = []
- tools = _tools(dispatched)
- audit = _Audit(flag={"No"})
- apply_answer_basis_audit(tools, audit)
- click = _by_name(tools, "click").handler
-
- # A pick moves nothing on, so it is never held itself; the submit after an unsupported one is.
- await click(_pick("ref=3", AUTH_Q, "No", {"ref=3": True}))
- message = await _held(tools, "click", {"selector": "#submit"})
- assert f"'{AUTH_Q}' answered 'No'" in message
- # Picking the flagged option again is not a second chance at the judge.
- audit.flag = set()
- await click(_pick("ref=3", AUTH_Q, "No", {"ref=3": True}))
- await _held(tools, "click", {"selector": "#submit"})
- audit.flag = {"No"}
- # Another option of the group unchecks it on the page, whatever its question reads as now, and that lifts the hold.
- await click(_pick("ref=4", "Authorized? Yes No Decline", "Decline", {"ref=3": False, "ref=4": True}))
- await click({"selector": "#submit"})
- assert dispatched[-1] == ("click", {"selector": "#submit"})
-
-
[email protected]("state", [False, None], ids=["unchecked", "unreadable"])
-async def test_an_unchecked_pick_lifts_its_hold_and_an_unreadable_one_keeps_it(state: bool | None) -> None:
- page: dict[str, bool] = {}
- tools = _tools([], page)
- apply_answer_basis_audit(tools, _Audit(flag={"No"}))
- click = _by_name(tools, "click").handler
- await click(_pick("ref=7", "Which of these apply to you?", "No", {"ref=7": True}))
- await click(_pick("ref=8", "Which of these apply to you?", "Veteran", {"ref=8": True}))
- await _held(tools, "click", {"selector": "#submit"})
- if state is None:
- del page["ref=7"]
- await _held(tools, "click", {"selector": "#submit"})
- else:
- await click(_pick("ref=7", "Which of these apply to you?", "No", {"ref=7": False}))
- await click({"selector": "#submit"})
- # Two groups that read alike stay apart: each option is its own answer.
- await click(_pick("ref=9", "Do you hold a licence?", "No", {"ref=9": True}))
- await click(_pick("ref=10", "Do you hold a licence?", "Yes", {"ref=10": True}))
- await _held(tools, "click", {"selector": "#submit"})
-
-
-async def test_a_pick_that_moves_the_page_on_is_counted_with_whether_a_flag_was_pending() -> None:
- tools = _tools([])
- apply_answer_basis_audit(tools, _Audit(flag={"No"}))
- click = _by_name(tools, "click").handler
- with capture_logs() as logs:
- await click({**_pick("ref=3", AUTH_Q, "No", {"ref=3": True}), "_advances": True})
- await click({**_pick("ref=4", "Do you need sponsorship?", "Yes", {"ref=4": True}), "_advances": True})
- await click(_pick("ref=5", "Willing to relocate?", "Yes", {"ref=5": True}))
- advanced = [e["flag_pending"] for e in logs if e["event"] == "taskv3 answer basis pick advanced"]
- assert advanced == [0, 1]
-
-
-async def test_a_pick_is_held_while_another_kind_of_answer_is_flagged() -> None:
- dispatched: list[tuple[str, dict[str, Any]]] = []
- tools = _tools(dispatched)
- apply_answer_basis_audit(tools, _Audit(flag={"Canadian"}))
- await _by_name(tools, "type").handler({"selector": "#nat", "text": "Canadian", "_label": "Nationality"})
- await asyncio.sleep(0)
-
- # The pick could move the page on past the flagged answer, as any other click could.
- assert "'Nationality' answered 'Canadian'" in await _held(
- tools, "click", _pick("ref=4", "Willing to relocate?", "Yes", {"ref=4": True})
- )
- assert [name for name, _ in dispatched] == ["type"]
-
-
-async def test_a_pick_that_moves_the_page_on_counts_no_flag_the_judge_cleared() -> None:
- tools = _tools([])
- apply_answer_basis_audit(tools, _Audit(flag=set()))
- click = _by_name(tools, "click").handler
- with capture_logs() as logs:
- await _by_name(tools, "type").handler({"selector": "#name", "text": "Ada", "_label": "First name"})
- await asyncio.sleep(0)
- await click({**_pick("ref=3", AUTH_Q, "Yes", {"ref=3": True}), "_advances": True})
- await asyncio.sleep(0)
- await click({**_pick("ref=4", "Willing to relocate?", "Yes", {"ref=4": True}), "_advances": True})
- assert [e["flag_pending"] for e in logs if e["event"] == "taskv3 answer basis pick advanced"] == [0, 0]
diff --git a/tests/unit/test_taskv3_tools.py b/tests/unit/test_taskv3_tools.py
index c09fefc15..052058809 100644
--- a/tests/unit/test_taskv3_tools.py
+++ b/tests/unit/test_taskv3_tools.py
@@ -10494,152 +10494,6 @@ async def test_an_answer_typed_with_enter_is_held_before_enter_submits_the_form(
assert judge.calls == 2
-@_skip_no_browser
-async def test_a_radio_or_checkbox_answer_is_held_under_the_question_observe_shows() -> None:
- html = (
- '<form onsubmit="window.__submitted = true; return false">'
- "<fieldset><legend>Are you legally authorized to work in the United States?</legend>"
- '<label><input type="radio" name="auth" value="y">Yes</label>'
- '<label><input type="radio" name="auth" value="n">No</label>'
- '<label><input type="radio" name="auth" value="d">I prefer not to answer</label></fieldset>'
- "<fieldset><legend>Which of these apply to you?</legend>"
- '<label><input type="checkbox" name="x" value="a">No</label>'
- '<label><input type="checkbox" name="x" value="b">Veteran</label></fieldset>'
- '<div role="radiogroup" aria-label="Will you need visa sponsorship?" onclick="for (const b of this.children) '
- "b.setAttribute('aria-checked', String(b === event.target))\">"
- '<button type="button" role="radio" aria-checked="false">No</button>'
- '<button type="button" role="radio" aria-checked="false">Decline to answer</button></div>'
- '<button id="submit">Submit</button></form>'
- )
- async with _content_page(html) as page:
- tools = build_browser_tools(_fixed_page_provider(page))
- apply_answer_basis_audit(tools, _FlagAnswers("No"))
- click = _tool(tools, "click").handler
- seen = (await _tool(tools, "observe").handler({})).content
- radio_no, decline = _ref_line(seen, "radio 'No'"), _ref_line(seen, "radio 'I prefer not to answer'")
- check_no = _ref_line(seen, "checkbox 'No'")
-
- # A pick is an answer, not a move: it goes through, and the submit after it is held under the question observe
- # shows (which carries the option captions after it).
- await click({"selector": radio_no})
- with pytest.raises(
- ToolRefusal, match="'Are you legally authorized to work in the United States\\?[^']*' answered 'No'"
- ):
- await click({"selector": "#submit"})
- await click({"selector": decline})
- # A checked box is an answer of its own, and unchecking it takes the answer back.
- await click({"selector": check_no})
- with pytest.raises(ToolRefusal, match="'Which of these apply to you\\?[^']*' answered 'No'"):
- await click({"selector": "#submit"})
- await click({"selector": check_no})
- # A button that declares itself a radio is a pick too.
- seen = (await _tool(tools, "observe").handler({})).content
- await click({"selector": _ref_line(seen, "button/button 'No'")})
- with pytest.raises(ToolRefusal, match="'Will you need visa sponsorship\\?[^']*' answered 'No'"):
- await click({"selector": "#submit"})
- await click({"selector": _ref_line(seen, "Decline to answer")})
- await click({"selector": "#submit"})
- assert await page.evaluate("() => window.__submitted") is True
-
-
-@_skip_no_browser
-async def test_a_radio_answer_in_a_frame_is_read_back_in_its_frame() -> None:
- inner = (
- "<fieldset><legend>Are you legally authorized to work in the United States?</legend>"
- "<label><input type=radio name=auth>No</label><label><input type=radio name=auth>I prefer not to answer</label>"
- "</fieldset>"
- )
- html = f'<iframe srcdoc="{inner}" style="width:600px;height:200px"></iframe><button id="submit">Submit</button>'
- async with _content_page(html) as page:
- await page.wait_for_timeout(300)
- tools = build_browser_tools(_fixed_page_provider(page))
- apply_answer_basis_audit(tools, _FlagAnswers("No"))
- click = _tool(tools, "click").handler
- seen = (await _tool(tools, "observe").handler({})).content
- await click({"selector": _ref_line(seen, "radio 'No'")})
- with pytest.raises(ToolRefusal):
- await click({"selector": "#submit"})
- await click({"selector": _ref_line(seen, "radio 'I prefer not to answer'")})
- await click({"selector": "#submit"})
-
-
-@_skip_no_browser
-async def test_a_radio_answer_in_a_recreated_frame_is_read_in_the_new_frame() -> None:
- inner = (
- "<fieldset><legend>Are you legally authorized to work in the United States?</legend>"
- "<label><input type=radio name=auth>No</label><label><input type=radio name=auth>I prefer not to answer</label>"
- "</fieldset>"
- )
- html = f'<div id="step"><iframe srcdoc="{inner}"></iframe></div><button id="submit">Submit</button>'
- async with _content_page(html) as page:
- await page.wait_for_timeout(300)
- tools = build_browser_tools(_fixed_page_provider(page))
- apply_answer_basis_audit(tools, _FlagAnswers("No"))
- click = _tool(tools, "click").handler
- for _ in range(2):
- seen = (await _tool(tools, "observe").handler({})).content
- await click({"selector": _ref_line(seen, "radio 'No'")})
- with pytest.raises(ToolRefusal):
- await click({"selector": "#submit"})
- await click({"selector": _ref_line(seen, "radio 'I prefer not to answer'")})
- await click({"selector": "#submit"})
- await page.evaluate(
- "(h) => { document.querySelector('#step').innerHTML = h; }", f'<iframe srcdoc="{inner}"></iframe>'
- )
- await page.wait_for_timeout(300)
-
-
-_POSTBACK_AUTH = (
- "<fieldset><legend>Are you legally authorized to work in the United States?</legend>"
- "<label><input type=radio name=auth>No</label><label><input type=radio name=auth>I prefer not to answer</label>"
- "</fieldset>"
-)
-# The page after a postback: the answer is still checked, and a group ahead of it renumbers the markers.
-_POSTBACK_AFTER = (
- "<fieldset><legend>Preferred shift</legend>"
- "<label><input type=radio name=shift>Day</label><label><input type=radio name=shift>Night</label></fieldset>"
- "<fieldset><legend>Are you legally authorized to work in the United States?</legend>"
- "<label><input type=radio name=auth checked>No</label>"
- "<label><input type=radio name=auth>I prefer not to answer</label></fieldset>"
-)
-
-
-@_skip_no_browser
[email protected]("where", ["page", "frame"])
-async def test_a_held_pick_stays_held_after_its_document_is_replaced(where: str) -> None:
- # Its old marker may name another, unchecked control in the new document, which must not lift the hold.
- if where == "page":
- html = _POSTBACK_AUTH + '<button id="submit">Submit</button>'
- else:
- html = f'<iframe id="step" srcdoc="{_POSTBACK_AUTH}"></iframe><button id="submit">Submit</button>'
- async with _content_page("") as page:
- # A real navigation, as a postback is: a new window, whose markers count again from the start.
- pages = {"/form": html, "/posted": _POSTBACK_AFTER + '<button id="submit">Submit</button>'}
- await page.route(
- "http://form.test/**",
- lambda route: route.fulfill(body=pages[route.request.url.split("form.test")[1]], content_type="text/html"),
- )
- await page.goto("http://form.test/form")
- await page.wait_for_timeout(300)
- tools = build_browser_tools(_fixed_page_provider(page))
- apply_answer_basis_audit(tools, _FlagAnswers("No"))
- click = _tool(tools, "click").handler
- seen = (await _tool(tools, "observe").handler({})).content
- await click({"selector": _ref_line(seen, "radio 'No'")})
- if where == "page":
- await page.goto("http://form.test/posted")
- else:
- await page.evaluate("(h) => document.getElementById('step').setAttribute('srcdoc', h)", _POSTBACK_AFTER)
- await page.wait_for_timeout(300)
- await _tool(tools, "observe").handler({})
- with pytest.raises(ToolRefusal, match="answered 'No'"):
- await click({"selector": "#submit"})
-
-
@_skip_no_browser
@pytest.mark.asyncio
async def test_dom_a_menu_note_lists_no_rows_it_cannot_read_whole() -> None: