Getting Started
Here are the steps to write a WinAppDriver test:
1. Run WinAppDriver.exe as an administrator and leave it running. Note the address the application is listening to, you will need it later.
2. Add UnitTest project to the solution of your test application or create a separate solution.
3. Right-click the Unit Test project in Solution Explorer and select “Manage NuGet Packages…”. Install the latest stable Appium.WebDriver package.
4. Create “TestSession” class where you set the AppiumOptions as follows:
5. Rename the auto generated “UnitTest1” class to “RadControlsScenarios” which should inherit “TestSession”. Here is the place to mention that our sample test application consists of RadGridView, RadButton and RadDropDownButton controls.
6. Next, we should create “ClassInitialize” and “ClassCleanup” methods.
There are two general ways to write tests: Using WinAppDriver UI Recorder tool to record tests at runtime and writing tests from scratch using inspect.exe tool for locating elements in your application.
7. Launch the WinAppDriver UI Recorder and click “Record.” Hover over the “radButton1” and wait until it starts flashing blue. The Recorder’s status bar will change its text from “Active” to “XPath Ready”. Once you have recorded a sequence of steps you wish to reproduce, click “Pause” within the recorder. You can open the actions selector to make certain that all UI actions have been recorded.
All you need to do now is to click the “Generate and copy C# code to Clipboard” button to copy the code for all recorded actions. Paste this code into the TestMethod.
8. Now, lets write two more tests from scratch. The first scenario is deleting a row from RadGridView's Context Menu and verifying the RadGridView rows count.
9. Let’s continue with a scenario where we click a RadDropDownButton, followed by RadMenuItem in order to change the ApplicationThemeName.
10. Create a public static class WindowsElementExtensions.cs and define the FindElementByAbsoluteXPath method. You will need that if you use the UI Recorder tool for your tests.
Additionally, here you can write helper methods such as DoubleClick, RightClick or Click with a X and Y offset in order to test different scenarios.
11. Right-click the Unit Test project in Visual Studio and click “Run Tests”. The test will launch your application, repeat all recorded steps, and close the application afterwards. All test activity is logged in the WinAppDriver console.