|
| 1 | +using Microsoft.Win32; |
| 2 | +using OpenQA.Selenium; |
| 3 | +using OpenQA.Selenium.Appium; |
| 4 | +using OpenQA.Selenium.Appium.Windows; |
| 5 | + |
| 6 | +namespace WinDynamicDesktop.Tests |
| 7 | +{ |
| 8 | + public class SystemTests : IDisposable |
| 9 | + { |
| 10 | + private const string AppiumServerUrl = "http://127.0.0.1:4723"; |
| 11 | + private readonly string AppPath = Path.GetFullPath(@"..\..\..\bin\WinDynamicDesktop.exe"); |
| 12 | + private readonly WindowsDriver<WindowsElement> driver; |
| 13 | + |
| 14 | + public SystemTests() |
| 15 | + { |
| 16 | + var appCapabilities = new AppiumOptions(); |
| 17 | + appCapabilities.AddAdditionalCapability("app", AppPath); |
| 18 | + appCapabilities.AddAdditionalCapability("platformName", "Windows"); |
| 19 | + appCapabilities.AddAdditionalCapability("deviceName", "WindowsPC"); |
| 20 | + driver = new WindowsDriver<WindowsElement>(new Uri(AppiumServerUrl), appCapabilities); |
| 21 | + driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5); |
| 22 | + } |
| 23 | + |
| 24 | + [Fact, Trait("type", "system")] |
| 25 | + public void ShouldUpdateWallpaper() |
| 26 | + { |
| 27 | + driver.FindElementByXPath("//Window[@Name='Select Language']").Click(); |
| 28 | + driver.FindElementByXPath("//Button[@Name='OK']").Click(); |
| 29 | + Thread.Sleep(TimeSpan.FromSeconds(1)); |
| 30 | + |
| 31 | + driver.SwitchTo().Window(driver.WindowHandles[0]); |
| 32 | + driver.FindElementByXPath("//Window[@Name='Configure Schedule']").Click(); |
| 33 | + driver.FindElementByAccessibilityId("radioButton1").Click(); |
| 34 | + driver.FindElementByAccessibilityId("locationBox").SendKeys("New York NY"); |
| 35 | + driver.FindElementByXPath("//Button[@Name='OK']").Click(); |
| 36 | + driver.SwitchTo().Window(driver.WindowHandles.Last()); |
| 37 | + driver.FindElementByXPath("//Button[@Name='Yes']").Click(); |
| 38 | + Thread.Sleep(TimeSpan.FromSeconds(1)); |
| 39 | + |
| 40 | + driver.SwitchTo().Window(driver.WindowHandles[0]); |
| 41 | + driver.FindElementByXPath("//Window[@Name='Select Theme']").Click(); |
| 42 | + driver.FindElementByAccessibilityId("listView1").SendKeys(Keys.Control + Keys.End); |
| 43 | + driver.FindElementByXPath("//ListItem[@Name='Windows 11']").Click(); |
| 44 | + driver.FindElementByXPath("//Button[@Name='Apply']").Click(); |
| 45 | + |
| 46 | + Assert.Contains(["scripts", "settings.json", "themes"], |
| 47 | + Directory.GetFileSystemEntries(Path.GetDirectoryName(AppPath)).Select(Path.GetFileName).ToArray()); |
| 48 | + Assert.StartsWith(Path.Combine(Path.GetDirectoryName(AppPath), "themes", "Windows_11", "img"), GetWallpaperPath()); |
| 49 | + } |
| 50 | + |
| 51 | + public void Dispose() |
| 52 | + { |
| 53 | + driver?.Quit(); |
| 54 | + } |
| 55 | + |
| 56 | + private string? GetWallpaperPath() |
| 57 | + { |
| 58 | + using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop")) |
| 59 | + { |
| 60 | + return key?.GetValue("WallPaper") as string; |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments