Appium-Drivers-Windows 系统管理员 2023-01-15 09:28 117阅读 0赞 ### The Windows Driver ### * * * * * Requirements and Support * Usage * Capabilities * Setup * Writing Tests for the Windows Driver * * Java Samples * C\# Samples * Javascript/node Samples * Create Test Project * Universal Windows Platform App Testing * Classic Windows App Testing * Starting a Session * Inspecting UI Elements Appium has the ability to automate Windows PC Desktop apps. This driver relies on a project from Microsoft called WinAppDriver, which is an Appium-compatible WebDriver server for Windows Desktop apps (and more in the future). WinAppDriver is often abbreviated “WAD”. WAD is bundled with Appium and does not need to be installed separately. Appium能够自动化Windows PC桌面apps. 这个dirver依靠Microsoft的一个叫WinAppDriver 这是一个Appium-compatible WebDriver server为Windows Desktop apps(未来有更多) WinAppDriver通常缩写为“WAD” WAD与Appium捆绑在一起,不需要单独安装 The Windows Driver supports testing of Universal Windows Platform (UWP) and Classic Windows (Win32) applications. Windows Driver支持测试通用Windows Platform(UWP) 和Win32 applications. In addition to the WAD repo, development of the Appium driver takes place at the appium-windows-driver repo. 除WAD repo外, 也可在 appium-windows-driver repo开发 Appium driver ##### Requirements and Support ##### In addition to Appium’s general requirements: * Windows PC with Windows 10 or up`win10以上` * Ability to enter Administrator mode`可以进入管理员模式` ##### Usage ##### The way to start a session using the Windows driver is to include the `platformName` capability in your new session request, with the value `Windows`. Also, ensure that you set the `deviceName` capability to `WindowsPC` as well. Of course, you must also include an appropriate `app` capability, at a minimum (see below). 开始会话使用Windows driver应包含platformName capability在你的新会话请求中 并且值为Windows 此外确保你的deviceName capability也设置为WindowsPC 当然,你必须至少包括适当的app ##### Capabilities ##### The Windows driver supports a number of standard Appium capabilities. See below for how these should be used specifically with the Windows driver. Windows driver支持多标准Appium功能 ##### Setup ##### To test a Windows app, simply make sure you have turned developer mode on. 要测试Windows app,仅需确认你的开发者模式开启 When running Appium (whether Appium Desktop or from the command line), ensure that you have started the app / cmd prompt as an administrator. 运行Appium时(无论是Appium Desktop还是命令行), 确保是管理员启动app/cmd ##### Writing Tests for the Windows Driver ##### 为Windows Driver写一个测试 You could begin by taking a look at some existing samples: ###### Java Samples ###### 1. Open the sample folder as an existing project in a Java IDE such as IntelliJ. For example: CalculatorTest 2. In the Java IDE build and run the test 在Java IDE中,打开示例文件夹作为现有项目 例如:CalculatorTest 2 在Java IDE建立和运行测试 ###### C\# Samples ###### 1. Pull and open CalculatorTest.sln under CalculatorTest 2. In Visual Studio 2015 with the test solution open build the test and select Test > Run > All Tests 拖出并打开CalculatorTest.sln在CalculatorTest下 在Visual Studio 2015带有的测试方案打开创建这个测试 并且选择Test > Run > All Tests ###### Javascript/node Samples ###### 1.Using selenium-webdriver`使用selenium-webdriver` Examples on selenium-appium`样例放在selenium-appium上` selenium-webdriver-winappdriver-example If you want to write tests from scratch, 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 2015. 如果你想从头开始编写测试, 你可以选择Appium/Selenium支持的编程语言和工具并写测试脚本 下面示例中: 我们将以C#用Microsoft Visual Studio 2015编写脚本 ###### Create Test Project ###### 1.Open Microsoft Visual Studio 2015`打开VS2015` 2.Create the test project and solution. I.e. select New Project > Templates > Visual C\# > Test > Unit Test Project`闯将项目` 3.Once created, select Project > Manage NuGet Packages… > Browse and search for Appium.WebDriver`浏览搜索 Appium.WebDriver` 4.Install the Appium.WebDriver NuGet packages for the test project`为项目安装Appium.WebDriver NuGet packages` 5.Start writing your test (see sample code under \[samples\])`开始编写你的测试(查看示例代码)` ###### Universal Windows Platform App Testing ###### To test a UWP app, you can use any Selenium supported language and simply specify the Application Id for the app under test in the app capabilities entry. Below is an example of creating a test session for Windows Alarms & Clock app written in C\#: 为测试UWP app, 你可以使用任何Selenium支持的语言 并且只需在app capabilities中加入指定被测Application Id 下面是一个样例关于创建测试会话为Windows Alarms&Clock app以C#编写的 // Launch the AlarmClock app DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("app", "Microsoft.WindowsAlarms_8wekyb3d8bbwe!App"); AlarmClockSession = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities); // Control the AlarmClock app AlarmClockSession.FindElementByAccessibilityId("AddAlarmButton").Click(); AlarmClockSession.FindElementByAccessibilityId("AlarmNameTextBox").Clear(); When testing the application you authored yourself, you can find the Application Id in the generated `AppX\vs.appxrecipe` file under `RegisteredUserNmodeAppID` node. E.g. `c24c8163-548e-4b84-a466-530178fc0580_scyf5npe3hv32!App` 当测试你自己编写的application时, 你可以查找Application Id在...文件下 ###### Classic Windows App Testing ###### To test a classic Windows app, you can also use any Selenium supported language and specify the full executable path for the app under test in the app capabilities entry. Below is an example of creating a test session for Windows Notepad app: 要测试一个经典Windows app, 你仍可以使用任何Selenium支持的语言 并且在app capabilities加入完整可执行路径 下面是一个关于为Windows Notepad app建立会话的样例 // Launch Notepad DesiredCapabilities appCapabilities = new DesiredCapabilities(); appCapabilities.SetCapability("app", @"C:\Windows\System32\notepad.exe"); NotepadSession = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities); // Control the Notepad app NotepadSession.FindElementByClassName("Edit").SendKeys("This is some text"); ###### Starting a Session ###### As mentioned above, you should additionally use these capabilities to ensure you are getting a Windows App automation session: 如上所述, 你应该用这些功能来确保你的Windows App 是自动会话的 `platformName`: `Windows deviceName: WindowsPC app`: the appID of the Windows app for testing, or the path to the .exe file ###### Inspecting UI Elements ###### Microsoft Visual Studio 2015 by default includes Windows SDK that provides 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 such as `C:\Program Files (x86)\Windows Kits\10\bin\x86`. The tool will show various element attributes. The table below shows you which Appium locator strategy you should use to find elements with the corresponding attributes. Microsoft Visual Studio 2015通过默认包含的Windows SDK为检查你正在测试的pplication提供很大的帮助. 此工具允许你查看所有UI element/node你能询问使用的Windows Application Driver 工具的位置 <table> <thead> <tr> <th align="left">LocatorStrategy</th> <th align="left">Matched Attribute</th> </tr> </thead> <tbody> <tr> <td align="left">accessibility id</td> <td align="left">AutomationId</td> </tr> <tr> <td align="left">class name</td> <td align="left">ClassName</td> </tr> <tr> <td align="left">name</td> <td align="left">Name</td> </tr> </tbody> </table>
还没有评论,来说两句吧...