用于 WPF UI 自动化测试的 Selenium

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24970042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 12:14:04  来源:igfitidea点击:

Selenium for WPF UI automation testing

wpfselenium

提问by Vin

Can I use Seleniumto do WPF UI automation testing?

我可以使用Selenium进行 WPF UI 自动化测试吗?

回答by Gigi

Support for WPF automation exists in WPF itself. Check out AutomationPeer. This articlemight help. This articleis more detailed. All this is good if you want to automate interaction with the UI itself (the usefulness of which is debatable).

WPF 本身支持 WPF 自动化。查看AutomationPeer这篇文章可能会有所帮助。这篇文章比较详细。如果您想自动化与 UI 本身的交互(其有用性是有争议的),那么所有这些都很好。

Another course of action is to unit test the business logic without touching the UI - if the application uses MVVM then the loose coupling between View and ViewModel should make unit testing a breeze. I get the impression that you're more into automating the UI though.

另一种做法是在不接触 UI 的情况下对业务逻辑进行单元测试 - 如果应用程序使用 MVVM,那么 View 和 ViewModel 之间的松散耦合应该使单元测试变得轻而易举。我的印象是你更喜欢自动化 UI。

回答by Grzegorz Smulko

Yes, you can use Appiumwhich is based on Selenium.

是的,您可以使用基于 Selenium 的Appium

There is a pretty good introductory blog post by Scott Hanselman: WinAppDriver - Test any app with Appium's Selenium-like tests on Windows.

Scott Hanselman有一篇很好的介绍性博客文章:WinAppDriver - 在 Windows 上使用 Appium 的类似 Selenium 的测试来测试任何应用程序

You'll need the WinAppDriverthat "supports testing Universal Windows Platform (UWP) and Classic Windows (Win32) apps on Windows 10 PCs".

您将需要“支持在 Windows 10 PC 上测试通用 Windows 平台 (UWP) 和经典 Windows (Win32) 应用程序”的WinAppDriver

回答by Purus

Selenium can be used to automate only web applications. If your WPF is an windows application you can not automate it.

Selenium 只能用于自动化 Web 应用程序。如果您的 WPF 是 Windows 应用程序,则无法自动化。

If you WPF application runs in a web browser using XBAP, still you will not be able to automate the application. So the answer is NO.

如果您的 WPF 应用程序在使用 XBAP 的 Web 浏览器中运行,您仍然无法自动化应用程序。所以答案是否定的。