Winforms应用程序的Selenium驱动程序
任何贡献都受到欢迎:)
这个项目正在使用
为什么另一个驱动程序,当已经有https://github.com/microsoft/winappdriver时?我正在测试的应用程序非常大,其中包含许多元素,并且该驱动程序在某些XPath查询(请参阅此问题)上60秒后就在时间,然后将所有内容放在一起后,查询完成了2秒钟。
该项目依赖于MS UI自动化,该自动化是Windows可访问性API的一部分。
官方文档提到了对各种平台的支持:
在以下操作系统上支持UI自动化:Windows XP,Windows Server 2003,Windows Server 2003 R2,Windows Vista,Windows 7,Windows 10,Windows Server 2008,Windows Server 2008 R2,Windows Server 2012,Windows Server 2012 R2,Windows Server 2016和Windows Server 2016和Windows Server 2019。
我无法确认它将在这些平台上工作,因为我只在计算机上赢得了10个企业,但是所有必需的库都是项目的一部分。
据我所知,不需要开发人员模式。
目前,没有安装程序。克隆存储库并从源头构建可执行文件。使用WinAppDriver.ServerbinDebugWinAppDriver.Server.exe下的可执行文件
调用服务器时,必须使用最新的客户端驱动程序版本3.141.0.0。
Ok Yes ,可以通过设置acceptAlertButtonCaptions功能,并使用半分离的值列表来添加其他字幕Cancel , No ,可以通过设置dismissAlertButtonCaptions功能添加其他字幕,并使用半分离的值列表不受支持的硒命令
X Path支持:
//node[3] //node[@attribute = 'X'] 仅实现此Appium命令
将引用添加到Selenium.WebDriver v3.141.0(https://www.nuget.org/packages/selenium.webdriver/3.141.0),您准备出发。
驱动程序可以启动测试过程中的系统,也可以连接到运行过程。使用功能来定义要附加的过程。
如果没有提供命令行参数,将在默认IP地址http://127.0.0.1:4444 4444上启动服务器。
支持以下功能:
mode - start (默认值)或attachprocessId附加过程的IDprocessName附加过程的名称exePath或app启动该过程的可执行文件的路径(目前无法提供参数)appWorkingDir设置新过程的工作目录mainWindowTitle正则表达式,以帮助WinAppDriver缩小该过程以附加到sendKeyStrategy ( oneByOne | grouped | setValue ) - 用于在文本字段中键入文本的策略,默认值是oneByOne ,当前在会话期间无法更改此功能 public static RemoteWebDriver CreateSessionByStartingTheApplication()
{
DesiredCapabilities desktopCapabilities = new DesiredCapabilities();
desktopCapabilities.SetCapability("app", "<name of the program to start>");
// or "exePath" desktopCapabilities.SetCapability("exePath", "<path to the executable to start the process>");
// following capabilities should be provided for UWP applications like Calculator or Clocks & Alarms
// optional - to set the working directory
desktopCapabilities.SetCapability("appWorkingDir", "<path to run the process in>");
// optional - to identify the process
desktopCapabilities.SetCapability("processName", "<name of the process>");
// optional - to identify the main window
desktopCapabilities.SetCapability("mainWindowTitle", "<name of the process>");
return new RemoteWebDriver(
new CommandExec(new Uri("http://127.0.0.1:4444"),
TimeSpan.FromSeconds(60)),
desktopCapabilities);
}
public static RemoteWebDriver CreateSessionByAttachingToRunningProcess()
{
DesiredCapabilities desktopCapabilities = new DesiredCapabilities();
desktopCapabilities.SetCapability("mode", "attach");
// attach to process using process name
desktopCapabilities.SetCapability("processName", "<name of the process to attach to>");
// with (optional)
desktopCapabilities.SetCapability("windowTitle", "<regular expression to narrow down the list of matching processes>");
// or attach to process using process id
desktopCapabilities.SetCapability("processId", "<id of the process to attach to>");
return new RemoteWebDriver(
new CommandExec(new Uri("http://127.0.0.1:4444"),
TimeSpan.FromSeconds(60)),
desktopCapabilities);
}
推荐的元素位置使用XPath表达式(尽管表达式支持有限)
var webBrowser = session.FindElement(By.XPath("//Pane[@AutomationId='webBrowser']"));
支持的元素位置机制
TextBox#idWin应用程序中的Windows不像浏览器中的Windows。 Windows( ControlType.Window )可以嵌套在控制树内,例如在Tab元素中。
窗口可以使用XPath Expression var window = session.FindElement(By.XPath("/Window/Pane/Window[@AutomationId='WindowName']"));或通过切换到session.SwitchTo().Window("WindowName"); ,在第一个示例中,您将获得元素参考,在另一个示例中,内部上下文切换到新窗口,并且在窗口cloded session.Close()时可以处理以下操作期间缓存的元素。
请注意,诸如OpenQA.Selenium.Support.UI.SelectElement之类的元素包装器无效,因为内部select和option元素是期望的。
有一个丑陋的黑客,它绕过使用XPath Expression搜索子窗口时切换窗口的需求。默认情况下,搜索始于窗口的根部元素 - 主窗口或用户切换到 - 搜索子窗口的窗口失败,因为它不是当前根的直接子。修复程序开始搜索顶层的窗口。