-
[WPF] UI Test with AppiumC#/WPF 2024. 6. 13. 13:32
WinAppDriver
https://github.com/Microsoft/WinAppDriver?tab=readme-ov-file
https://github.com/Microsoft/WinAppDriver/releases
UI Recorder
https://github.com/microsoft/WinAppDriver/releases/tag/UIR-v1.1
https://github.com/microsoft/WinAppDriver/blob/master/Docs/UsingUIRecorder.md
public class TestsBase { private const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723"; private const string ApplicationPath = "D:\\TFS\\LSStudio\\SRC\\trunk\\Services\\LS.DevSquare.Service.Manager\\LS.DevSquare.Service.Manager\\Working\\Debug\\net7.0-windows\\LS.DevSquare.Service.Manager.Main.exe"; private const string DeviceName = "WindowsPC"; private const int WaitForAppLaunch = 5; private const string WinAppDriverPath = @"C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe"; private static Process winAppDriverProcess; public WindowsDriver<WindowsElement> AppSession { get; private set; } public WindowsDriver<WindowsElement> DesktopSession { get; private set; } private static void StartWinAppDriver() { ProcessStartInfo psi = new ProcessStartInfo(WinAppDriverPath); psi.UseShellExecute = true; psi.Verb = "runas"; // run as administrator winAppDriverProcess = Process.Start(psi); } public void Initialize() { StartWinAppDriver(); var appiumOptions = new AppiumOptions(); appiumOptions.AddAdditionalCapability("app", ApplicationPath); appiumOptions.AddAdditionalCapability("deviceName", DeviceName); appiumOptions.AddAdditionalCapability(capabilityName: "platformName", capabilityValue: "Windows"); appiumOptions.AddAdditionalCapability("ms:waitForAppLaunch", WaitForAppLaunch); this.AppSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), appiumOptions); Assert.IsNotNull(AppSession); Assert.IsNotNull(AppSession.SessionId); AppSession.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5); AppiumOptions optionsDesktop = new AppiumOptions(); optionsDesktop.AddAdditionalCapability("app", "Root"); optionsDesktop.AddAdditionalCapability("deviceName", DeviceName); appiumOptions.AddAdditionalCapability(capabilityName: "ms:experimental-webdriver", capabilityValue: true); DesktopSession = new WindowsDriver<WindowsElement>(new Uri(WindowsApplicationDriverUrl), optionsDesktop); //CloseTrialDialog(); } //protected void CloseTrialDialog() //{ // this.GetElementByName("Telerik UI for WPF Trial").FindElementByName("Cancel").Click(); //} public void Cleanup() { // Close the session if (AppSession != null) { AppSession.Close(); AppSession.Quit(); } // Close the desktopSession if (DesktopSession != null) { DesktopSession.Close(); DesktopSession.Quit(); } } public static void StopWinappDriver() { // Stop the WinAppDriverProcess if (winAppDriverProcess != null) { foreach (var process in Process.GetProcessesByName("WinAppDriver")) { process.Kill(); } } } protected void SelectAllText() { Actions action = new Actions(AppSession); action.KeyDown(Keys.Control).SendKeys("a"); action.KeyUp(Keys.Control); action.Perform(); } protected void PerformDelete() { Actions action = new Actions(AppSession); action.SendKeys(Keys.Delete); action.Perform(); } protected void PerformEnter() { Actions action = new Actions(AppSession); action.SendKeys(Keys.Enter); action.Perform(); } protected void WriteText(string text) { Actions action = new Actions(AppSession); action.SendKeys(text); action.Perform(); } }
[TestClass] public class UnitTest1 : TestsBase { [TestInitialize] public void TestInitialize() { this.Initialize(); } [TestCleanup] public void TestCleanup() { this.Cleanup(); } [ClassCleanup] public static void ClassCleanusp() { StopWinappDriver(); } [TestMethod] public void TestAutomationIdEtcSelect() { var etcButton = AppSession.FindElementByAccessibilityId("Home"); etcButton.Click(); //WindowsElement newEmployeeWindow = null; //while (newEmployeeWindow == null) // newEmployeeWindow = AppSession.FindElementByName("Employee (New)"); //newEmployeeWindow.FindElementByName("First Name").FindElementByClassName("TextEdit").SendKeys("John"); //newEmployeeWindow.FindElementByName("Save & Close").Click(); } }
=>
!!!!!!!!!!!!!!!!!!! App 디렉토리 지정해주지 않으면 DXDynamicModule 이 dll 못찾음. !!!!!!!!!!!!!!!!!!!
appiumOptions.AddAdditionalCapability("appWorkingDir", AppDirectoryPath);
테스트하고자 하는 Application을 기준으로 함.
appiumOptions.AddAdditionalCapability("app", ApplicationPath);
테스트하고자하는 Application의 주소를 지정.
private const string ApplicationPath = "D:\\TFS\\LSStudio\\SRC\\trunk\\Services\\LS.DevSquare.Service.Manager\\LS.DevSquare.Service.Manager\\Working\\Debug\\net7.0-windows\\LS.DevSquare.Service.Manager.Main.exe";
Desktop(윈도우 바탕화면 상태)을 기준으로 함.appiumOptions.AddAdditionalCapability("app", "Root");
WAD UIRecorder
C# Code
// LeftClick on Button "숨겨진 아이콘 표시" at (25,46) Console.WriteLine("LeftClick on Button \"숨겨진 아이콘 표시\" at (25,46)"); string xpath_LeftClickButton숨겨진아이콘표시_25_46 = "/Pane[@ClassName=\"#32769\"][@Name=\"데스크톱 1\"]/Pane[@ClassName=\"Shell_TrayWnd\"][@Name=\"작업 표시줄\"]/Pane[@ClassName=\"Windows.UI.Input.InputSite.WindowClass\"]/Button[@Name=\"숨겨진 아이콘 표시\"][@AutomationId=\"SystemTrayIcon\"]"; var winElem_LeftClickButton숨겨진아이콘표시_25_46 = DesktopSession.FindElementByXPath(xpath_LeftClickButton숨겨진아이콘표시_25_46); if (winElem_LeftClickButton숨겨진아이콘표시_25_46 != null) { winElem_LeftClickButton숨겨진아이콘표시_25_46.Click(); } else { Console.WriteLine($"Failed to find element using xpath: {xpath_LeftClickButton숨겨진아이콘표시_25_46}"); return; }
FindElementByXPath
: 모니터의 위치주소를 기반으로 Element찾음. ( 주로 DesktopSession 으로 호출.)
FindElementByName
: 이름으로 Element찾음. (주로 AppSession으로 호출 .)
FindElementByAccessibilityId
: AutomationProperties.AutomationId="keyValue" 로 Element찾음. (주로 AppSession으로 호출 .)
How To Test Controls With Appium | WPF Controls | DevExpress Documentation
DevExpress WPF Controls support the Appium framework with WinAppDriver UI test automation. This topic shows how to prepare the environment and create a test. Prepare the Environment Follow the steps below to use Appium with DevExpress WPF Controls: Enable
docs.devexpress.com
https://www.telerik.com/blogs/get-your-wpf-apps-automated-appium
Get Your WPF Apps Automated With Appium
Automate your WPF app with Appium, Windows Application Driver and UI Recorder tool.
www.telerik.com
Automated UI Tests (UI Automation, Appium, Coded UI) | WinForms Controls | DevExpress Documentation
User interface (UI) testing verifies that all visual elements of an application function correctly. UI tests can be carried out manually by human testers, or with the help of automated testing tools. Automated testing is faster, more reliable, and more cos
docs.devexpress.com
728x90'C# > WPF' 카테고리의 다른 글
[WPF] ItemsControl , UIelement 반복 (0) 2024.06.26 [WPF] Async Await (0) 2024.06.19 [WPF] Ioc resolve constructor parameter (0) 2024.06.07 [WPF] dotnet build (0) 2024.05.16 [WPF] TextBox Placeholder, Wartermark (0) 2024.05.16 댓글