22using OpenQA . Selenium ;
33using OpenQA . Selenium . Appium ;
44using OpenQA . Selenium . Appium . Windows ;
5+ using System . Windows . Automation ;
56
67namespace WinDynamicDesktop . Tests
78{
@@ -28,13 +29,13 @@ public void ShouldUpdateWallpaper()
2829 driver . FindElementByXPath ( "//Button[@Name='OK']" ) . Click ( ) ;
2930 Thread . Sleep ( TimeSpan . FromSeconds ( 5 ) ) ;
3031
32+ if ( HandleLocationPrompt ( ) ) Thread . Sleep ( TimeSpan . FromSeconds ( 2 ) ) ;
3133 driver . SwitchTo ( ) . Window ( driver . WindowHandles [ 0 ] ) ;
3234 driver . FindElementByXPath ( "//Window[@Name='Configure Schedule']" ) . Click ( ) ;
3335 driver . FindElementByAccessibilityId ( "radioButton1" ) . Click ( ) ;
3436 driver . FindElementByAccessibilityId ( "locationBox" ) . SendKeys ( "New York NY" ) ;
3537 driver . FindElementByXPath ( "//Button[@Name='OK']" ) . Click ( ) ;
3638 Thread . Sleep ( TimeSpan . FromSeconds ( 2 ) ) ;
37- driver . SwitchTo ( ) . Window ( driver . WindowHandles . Last ( ) ) ;
3839 driver . FindElementByXPath ( "//Button[@Name='Yes']" ) . Click ( ) ;
3940 Thread . Sleep ( TimeSpan . FromSeconds ( 5 ) ) ;
4041
@@ -43,6 +44,7 @@ public void ShouldUpdateWallpaper()
4344 driver . FindElementByAccessibilityId ( "listView1" ) . SendKeys ( Keys . Control + Keys . End ) ;
4445 driver . FindElementByXPath ( "//ListItem[@Name='Windows 11']" ) . Click ( ) ;
4546 driver . FindElementByXPath ( "//Button[@Name='Apply']" ) . Click ( ) ;
47+ Thread . Sleep ( TimeSpan . FromSeconds ( 2 ) ) ;
4648
4749 Assert . Contains ( [ "scripts" , "settings.json" , "themes" ] ,
4850 Directory . GetFileSystemEntries ( Path . GetDirectoryName ( AppPath ) ) . Select ( Path . GetFileName ) . ToArray ( ) ) ;
@@ -54,6 +56,20 @@ public void Dispose()
5456 driver ? . Quit ( ) ;
5557 }
5658
59+ private bool HandleLocationPrompt ( )
60+ {
61+ var dialogMatcher = new PropertyCondition ( AutomationElement . NameProperty , "Let Windows and apps access your location?" ) ;
62+ var buttonMatcher = new PropertyCondition ( AutomationElement . NameProperty , "Yes" ) ;
63+ AutomationElement dialog = AutomationElement . RootElement . FindFirst ( TreeScope . Children , dialogMatcher ) ;
64+ if ( dialog ? . FindFirst ( TreeScope . Descendants , buttonMatcher ) is AutomationElement yesButton &&
65+ yesButton . GetCurrentPattern ( InvokePattern . Pattern ) is InvokePattern invokePattern )
66+ {
67+ invokePattern . Invoke ( ) ;
68+ return true ;
69+ }
70+ return false ;
71+ }
72+
5773 private string ? GetWallpaperPath ( )
5874 {
5975 using ( RegistryKey key = Registry . CurrentUser . OpenSubKey ( @"Control Panel\Desktop" ) )
0 commit comments