@@ -1665,5 +1665,47 @@ static void WaitForNone(Func<IUIElement> query,
1665
1665
{
1666
1666
Wait ( query , i => i == null , timeoutMessage , timeout , retryFrequency ) ;
1667
1667
}
1668
+
1669
+ /// <summary>
1670
+ /// Assert an element exists and is visible.
1671
+ /// </summary>
1672
+ public static bool DoesElementExist ( this IApp app , string automationId )
1673
+ {
1674
+ var exists = false ;
1675
+
1676
+ var elements = app . FindElements ( automationId ) ;
1677
+ exists = elements . Count > 0 ;
1678
+
1679
+ return exists && elements . First ( ) . IsDisplayed ( ) ;
1680
+ }
1681
+
1682
+ /// <summary>
1683
+ /// Assert an element found by text exists and is visible.
1684
+ /// </summary>
1685
+ public static IUIElement ? FindVisibleElementByText ( this IApp app , string text , int timeoutInSeconds = 3 )
1686
+ {
1687
+ string beforeMessage = $ "Find visible element by text: '{ text } ' - { DateTime . Now . ToString ( "HH:mm:ss" ) } ";
1688
+ Console . WriteLine ( beforeMessage ) ;
1689
+
1690
+ var timeout = TimeSpan . FromSeconds ( timeoutInSeconds ) ;
1691
+ var stopwatch = Stopwatch . StartNew ( ) ;
1692
+
1693
+ while ( stopwatch . Elapsed < timeout )
1694
+ {
1695
+ var elementIsVisible = app . FindElementByText ( text ) ? . IsDisplayed ( ) ;
1696
+ if ( elementIsVisible is not null && elementIsVisible . Value )
1697
+ {
1698
+ var element = app . FindElementByText ( text ) ;
1699
+ string afterMessage = $ "Found visible element by text: { text } - { DateTime . Now . ToString ( "HH:mm:ss" ) } ";
1700
+ Console . WriteLine ( afterMessage ) ;
1701
+ return element ;
1702
+ }
1703
+ Thread . Sleep ( 100 ) ;
1704
+ }
1705
+ stopwatch . Stop ( ) ;
1706
+ string notVisibleMessage = $ "Element with text: { text } not visible within timeout - { DateTime . Now . ToString ( "HH:mm:ss" ) } ";
1707
+ Console . WriteLine ( notVisibleMessage ) ;
1708
+ return null ;
1709
+ }
1668
1710
}
1669
1711
}
0 commit comments