Skip to content

Commit 3f66a02

Browse files
committed
Updated ReadMe to reference new /Docs/ directory. Added /Docs/ directory to host all related WinAppDriver documentation.
1 parent 755e338 commit 3f66a02

10 files changed

+539
-267
lines changed

Docs/AuthoringTestScripts.md

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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

Docs/CI_AzureDevOps.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## WinAppDriver in CI with Azure Pipelines
2+
3+
### Prerequisites to run WinAppDriver in CI
4+
The following are prequisites for running UI tests with WinAppDriver in Azure DevOps:
5+
6+
1. An agent running on Windows 10 configured as interactive is required.
7+
8+
- The following hosted agents are supported: [HostedVS2019](https://github.com/Microsoft/azure-pipelines-image-generation/blob/master/images/win/Vs2019-Server2019-Readme.md) and [HostedVS2017](https://github.com/Microsoft/azure-pipelines-image-generation/blob/master/images/win/Vs2017-Server2016-Readme.md).
9+
- If you wish to use a private agent, please refer to the Azure documentation [here](https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/v2-windows?view=azure-devops) on setting one up.
10+
- If the hosted agents do not meet your requirement, try using a private agent. More information on this [below](https://github.com/Microsoft/WinAppDriver/wiki/Continuous-Integration-with-WinAppDriver/_edit#getting-started-with-a-sample-build-pipeline).
11+
1. Use Azure Pipelines - [get started today for free](https://azure.microsoft.com/en-us/pricing/details/devops/azure-pipelines/).
12+
13+
### WinAppDriver Task for Azure Pipelines
14+
There's now a dedicated [WinAppDriver Pipelines Task](https://marketplace.visualstudio.com/items?itemName=WinAppDriver.winappdriver-pipelines-task) available on the Azure Marketplace to help you easily enable and configure WinAppDriver from inside your DevOps Pipeline. To get started, install the WinAppDriver task onto your DevOps organization from [here](https://marketplace.visualstudio.com/acquisition?itemName=WinAppDriver.winappdriver-pipelines-task), or you can search through the **Add Tasks** menu from inside your Pipeline Editor -
15+
16+
<p align="center"><img src="https://raw.githubusercontent.com/hassanuz/Sandbox/master/snippets/AzurePipelines/Task/downloadTask.PNG" width="700" align="middle"></p>
17+
18+
Once installed, the WinAppDriver task can be added to your pipeline.
19+
20+
<p align="center"><img src="https://raw.githubusercontent.com/hassanuz/Sandbox/master/snippets/AzurePipelines/Task/pipelineAddTask.PNG" width="700" align="middle"></p>
21+
22+
It is recommended to place the WinAppDriver task in conjunction with a separate Test Runner utility - in this case our pipeline has been pre-equipped with the Visual Studio Test Runner Task to drive the test cases.
23+
24+
<p align="center"><img src="https://raw.githubusercontent.com/hassanuz/Sandbox/master/snippets/AzurePipelines/Task/startTaskAdded.PNG" width="300" align="middle"></p>
25+
26+
We can now configure the task - you can see that automatically the Task is named to "Start - WinAppDriver". It is not required to pass in any arguments, but it is recommended to set the System Resolution on Agent to **1080P** - this will be especially important to declare on a hosted agent.
27+
28+
<p align="center"><img src="https://raw.githubusercontent.com/hassanuz/Sandbox/master/snippets/AzurePipelines/Task/startTaskOptions.PNG" width="700" align="middle"></p>
29+
30+
Once configured, it's recommended to add another instance of the WinAppDriver task, this time having it be configured to "Stop" WinAppDriver on the agent. The "Stop- WinAppDriver" instance of the task should be placed after the VS Test task, so that WinAppDriver is terminated on the agent once all the test cases have been executed.
31+
32+
<p align="center"><img src="https://raw.githubusercontent.com/hassanuz/Sandbox/master/snippets/AzurePipelines/Task/stopTaskOptions.PNG" width="700" align="middle"></p>
33+
34+
Congratulations! Assuming all went well, you can now view the captured WinAppDriver logs from the Summary Panel of the "Close - WinAppDriver" instance of the task.
35+
36+
<p align="center"><img src="https://raw.githubusercontent.com/hassanuz/Sandbox/master/snippets/AzurePipelines/Task/ResultsSummary.PNG" width="700" align="middle"></p>
37+
38+
And the WinAppDriver logs,
39+
40+
<p align="center"><img src="https://raw.githubusercontent.com/hassanuz/Sandbox/master/snippets/AzurePipelines/Task/Results.PNG" width="700" align="middle"></p>
41+
42+
Finally after you've finished with all the steps above, don't forget to add the finishing touches to your repository by embedding the official [Azure Pipelines status badge](https://docs.microsoft.com/en-us/azure/devops/pipelines/create-first-pipeline?view=azure-devops&tabs=tfs-2018-2#add-a-status-badge-to-your-repository)!

0 commit comments

Comments
 (0)