|
| 1 | +## Authoring Your Own Test Script |
| 2 | + |
| 3 | +You can choose any programming language or tools supported by Appium/Selenium to write your test scripts. In the example below, we will author the test script in C# using Microsoft Visual Studio. |
| 4 | + |
| 5 | +### Creating a Test Project |
| 6 | + |
| 7 | +1. Open **Microsoft Visual Studio 2015** or **Microsoft Visual Studio 2017** |
| 8 | + > **Note**: in Visual Studio 2017 make sure you have the optional **.NET desktop development** workload installed |
| 9 | +2. Create the test project and solution. I.e. Select **New Project > Templates > Visual C# > Test > Unit Test Project** |
| 10 | +3. Once created, select **Project > Manage NuGet Packages... > Browse** and search for **Appium.WebDriver** |
| 11 | +4. Install the **Appium.WebDriver** NuGet packages for the test project |
| 12 | +5. Start writing your test (see sample code under [samples](/Samples/)) |
| 13 | + |
| 14 | +### Testing a Universal Windows Platform Application |
| 15 | + |
| 16 | +To test a UWP app, simply specify the **Application Id** for the application you want to test in the **app** capabilities entry when you are creating a session. You can also specify launching arguments if your application supports them through **appArguments** capability. Below is an example of creating a test session for Windows **Alarms & Clock** app written in C#: |
| 17 | + |
| 18 | +```c# |
| 19 | +// Launch the Alarms & Clock app |
| 20 | +DesiredCapabilities appCapabilities = new DesiredCapabilities(); |
| 21 | +appCapabilities.SetCapability("app", "Microsoft.WindowsAlarms_8wekyb3d8bbwe!App"); |
| 22 | +AlarmClockSession = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities); |
| 23 | + |
| 24 | +// Use the session to control the app |
| 25 | +AlarmClockSession.FindElementByAccessibilityId("AddAlarmButton").Click(); |
| 26 | +AlarmClockSession.FindElementByAccessibilityId("AlarmNameTextBox").Clear(); |
| 27 | +``` |
| 28 | + |
| 29 | +> You can find the **Application Id** of your application in the generated `AppX\vs.appxrecipe` file under `RegisteredUserModeAppID` node. E.g. `c24c8163-548e-4b84-a466-530178fc0580_scyf5npe3hv32!App` |
| 30 | +
|
| 31 | +### Testing a Classic Windows Application |
| 32 | + |
| 33 | +To test a classic Windows app, specify the **full executable path** for the app under test in the **app** capabilities entry when creating a new session. Similar with modern (UWP) app, you can specify launching arguments through **appArguments** capability. But unlike modern apps, you can also specify the app working directory for a classic app through "appWorkingDir" capability. Below is an example of creating a test session for the **Notepad** app that opens `MyTestFile.txt` in `C:\MyTestFolder\`. |
| 34 | + |
| 35 | +```c# |
| 36 | +// Launch Notepad |
| 37 | +DesiredCapabilities appCapabilities = new DesiredCapabilities(); |
| 38 | +appCapabilities.SetCapability("app", @"C:\Windows\System32\notepad.exe"); |
| 39 | +appCapabilities.SetCapability("appArguments", @"MyTestFile.txt"); |
| 40 | +appCapabilities.SetCapability("appWorkingDir", @"C:\MyTestFolder\"); |
| 41 | +NotepadSession = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities); |
| 42 | + |
| 43 | +// Use the session to control the app |
| 44 | +NotepadSession.FindElementByClassName("Edit").SendKeys("This is some text"); |
| 45 | +``` |
| 46 | +## Inspecting UI Elements |
| 47 | + |
| 48 | +The latest Microsoft Visual Studio version by default includes the Windows SDK with a great tool to inspect the application you are testing. This tool allows you to see every UI element/node that you can query using Windows Application Driver. This **inspect.exe** tool can be found under the Windows SDK folder which is typically `C:\Program Files (x86)\Windows Kits\10\bin\x86` |
| 49 | + |
| 50 | +More detailed documentation on Inspect is available on MSDN <https://msdn.microsoft.com/library/windows/desktop/dd318521(v=vs.85).aspx>. |
| 51 | +## Supported Locators to Find UI Elements |
| 52 | + |
| 53 | +Windows Application Driver supports various locators to find UI element in the application session. The table below shows all supported locator strategies with their corresponding UI element attributes shown in **inspect.exe**. |
| 54 | + |
| 55 | +| Client API | Locator Strategy | Matched Attribute in inspect.exe | Example | |
| 56 | +|------------------------------ |------------------ |---------------------------------------- |-------------- | |
| 57 | +| FindElementByAccessibilityId | accessibility id | AutomationId | AppNameTitle | |
| 58 | +| FindElementByClassName | class name | ClassName | TextBlock | |
| 59 | +| FindElementById | id | RuntimeId (decimal) | 42.333896.3.1 | |
| 60 | +| FindElementByName | name | Name | Calculator | |
| 61 | +| FindElementByTagName | tag name | LocalizedControlType (upper camel case) | Text | |
| 62 | +| FindElementByXPath | xpath | Any | //Button[0] | |
| 63 | + |
| 64 | +## Supported Capabilities |
| 65 | + |
| 66 | +Below are the capabilities that can be used to create Windows Application Driver session. |
| 67 | + |
| 68 | +| Capabilities | Descriptions | Example | |
| 69 | +|-------------------- |------------------------------------------------------- |------------------------------------------------------- | |
| 70 | +| app | Application identifier or executable full path | Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge | |
| 71 | +| appArguments | Application launch arguments | https://github.com/Microsoft/WinAppDriver | |
| 72 | +| appTopLevelWindow | Existing application top level window to attach to | `0xB822E2` | |
| 73 | +| appWorkingDir | Application working directory (Classic apps only) | `C:\Temp` | |
| 74 | +| platformName | Target platform name | Windows | |
| 75 | +| platformVersion | Target platform version | 1.0 |
0 commit comments