@@ -64,13 +64,15 @@ extension RunnerTests {
6464 keyboardVisibleBeforeTap : Bool ? = nil
6565 ) -> TextEntryStabilization {
6666#if os( tvOS )
67- return TextEntryStabilization ( element : target , evidence : . focusEngine )
67+ return TextEntryStabilization ( element : target , evidence : . focusEngine , polls : 0 )
6868#else
6969 let keyboardVisibleAtEntry = keyboardVisibleBeforeTap ?? isKeyboardVisible ( app : app )
7070 let deadline = Date ( ) . addingTimeInterval ( TextEntryTiming . focusTimeout )
71+ var polls = 0
7172 while Date ( ) < deadline {
73+ polls += 1
7274 if let focused = focusedTextInput ( app : app ) {
73- return TextEntryStabilization ( element : focused , evidence : . focusedInput )
75+ return TextEntryStabilization ( element : focused , evidence : . focusedInput , polls : polls )
7476 }
7577#if os( iOS )
7678 // The tapped input's own read comes before the keyboard. While a software keyboard is
@@ -79,23 +81,23 @@ extension RunnerTests {
7981 // took focus.
8082 let read = target . flatMap ( ResolvedTextEntryInput . init ( reading : ) )
8183 if let read , let snapshot = read . snapshot , snapshotHasKeyboardFocus ( snapshot ) {
82- return TextEntryStabilization ( element : read . element , evidence : . inputReportsKeyboardFocus ( read ) )
84+ return TextEntryStabilization ( element : read . element , evidence : . inputReportsKeyboardFocus ( read ) , polls : polls )
8385 }
8486#endif
8587 // focusedTextInput is intentionally nil on iOS; the keyboard transitioning to visible after
8688 // our tap is also a focus-moved signal. Don't fast-path when it was already up.
8789 if keyboardBecameVisible ( app : app , wasVisibleAtEntry : keyboardVisibleAtEntry ) {
88- return TextEntryStabilization ( element : target , evidence : . keyboardAppeared )
90+ return TextEntryStabilization ( element : target , evidence : . keyboardAppeared , polls : polls )
8991 }
9092#if os( iOS )
9193 // The read came before the keyboard query, so it is not handed on as the post-focus read.
9294 if let read , keyboardFocusConfirmed ( app : app , read : read ) {
93- return TextEntryStabilization ( element : target , evidence : . focusQueryMatchesInput )
95+ return TextEntryStabilization ( element : target , evidence : . focusQueryMatchesInput , polls : polls )
9496 }
9597#endif
9698 sleepFor ( TextEntryTiming . pollInterval )
9799 }
98- return TextEntryStabilization ( element : target , evidence : nil )
100+ return TextEntryStabilization ( element : target , evidence : nil , polls : polls )
99101#endif
100102 }
101103
@@ -148,7 +150,12 @@ extension RunnerTests {
148150 target : target ,
149151 keyboardVisibleBeforeTap : keyboardVisibleBeforeTap
150152 )
151- NSLog ( " AGENT_DEVICE_RUNNER_TEXT_ENTRY_FOCUS evidence=%@ " , stabilized . evidence ? . name ?? " none " )
153+ NSLog (
154+ " %@%@ polls=%d " ,
155+ TextEntryFocusEvidence . logMarker ,
156+ stabilized . evidence ? . name ?? " none " ,
157+ stabilized . polls
158+ )
152159 if case . inputReportsKeyboardFocus ( let read ) = stabilized . evidence {
153160 return focusedTextEntryTarget ( read . element , read : read , requestedPoint : requestedPoint )
154161 }
0 commit comments