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

Function wait_for_batch_selector

packages/server/src/main/batch.rs:683–723  ·  view source on GitHub ↗
(
    bridge: &NativeBridge,
    udid: &str,
    args: &StepOptions,
)

Source from the content-addressed store, hash-verified

681}
682
683fn wait_for_batch_selector(
684 bridge: &NativeBridge,
685 udid: &str,
686 args: &StepOptions,
687) -> Result<(), crate::error::AppError> {
688 let selector = batch_selector_from_args(args);
689 if selector.id.is_none()
690 && selector.label.is_none()
691 && selector.value.is_none()
692 && selector.element_type.is_none()
693 {
694 return Err(crate::error::AppError::bad_request(
695 "wait-for/assert requires a selector flag.",
696 ));
697 }
698
699 let timeout_ms = args
700 .value("timeout-ms")
701 .or_else(|| args.value("wait-timeout-ms"))
702 .and_then(|value| value.parse::<u64>().ok())
703 .unwrap_or(5_000);
704 let poll_interval_ms = args
705 .value("poll-interval-ms")
706 .and_then(|value| value.parse::<u64>().ok())
707 .unwrap_or(100)
708 .max(10);
709 let deadline = std::time::Instant::now() + Duration::from_millis(timeout_ms);
710
711 loop {
712 let snapshot = bridge.accessibility_snapshot(udid, None)?;
713 if snapshot_contains_element(&snapshot, &selector) {
714 return Ok(());
715 }
716 if timeout_ms == 0 || std::time::Instant::now() >= deadline {
717 return Err(crate::error::AppError::not_found(
718 "No accessibility element matched the selector.",
719 ));
720 }
721 sleep_ms(poll_interval_ms);
722 }
723}
724
725fn snapshot_contains_element(snapshot: &Value, selector: &ElementSelector) -> bool {
726 snapshot

Callers 1

run_batch_stepFunction · 0.85

Calls 6

batch_selector_from_argsFunction · 0.85
sleep_msFunction · 0.85
valueMethod · 0.80
maxMethod · 0.80

Tested by

no test coverage detected