MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / argentElementCenter

Function argentElementCenter

scripts/bench/agent-control-benchmark.mjs:813–845  ·  view source on GitHub ↗
(udid, label)

Source from the content-addressed store, hash-verified

811}
812
813async function argentElementCenter(udid, label) {
814 const result = run("argent", ["run", "describe", "--udid", udid, "--json"], {
815 env: argentEnv,
816 timeoutMs: 30000,
817 });
818 if (!result.ok) {
819 throw new Error(`Argent describe failed while locating ${label}`);
820 }
821 let output = `${result.stdout}\n${result.stderr}`;
822 try {
823 const parsed = JSON.parse(result.stdout);
824 if (typeof parsed.description === "string") {
825 output = parsed.description;
826 }
827 } catch {
828 // Text output is also supported.
829 }
830 const escaped = label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
831 const regex = new RegExp(
832 `AX\\w+\\s+"${escaped}"[^\\n]*\\(([-0-9.]+),\\s*([-0-9.]+),\\s*([-0-9.]+),\\s*([-0-9.]+)\\)`,
833 "i",
834 );
835 const match = output.match(regex);
836 if (!match) {
837 throw new Error(`Could not find Argent AX element "${label}"`);
838 }
839 const [, x, y, width, height] = match.map(Number);
840 return {
841 label,
842 x: Number((x + width / 2).toFixed(4)),
843 y: Number((y + height / 2).toFixed(4)),
844 };
845}
846
847async function sample(tool, action, phase, count, fn) {
848 for (let index = 0; index < count; index += 1) {

Callers 1

benchmarkArgentFunction · 0.85

Calls 3

runFunction · 0.70
replaceMethod · 0.65
parseMethod · 0.45

Tested by

no test coverage detected