Is there any way to automate windows forms testing?

C#.Netvb.netWinformsAutomated Tests

C# Problem Overview


I am familiar with nunit for unit testing of the business layer however I am looking now to automate the test of the win forms gui layer.

I have seen watin and the watin recorder for automating tests on web application by accessing the controls and automating them. However I am struggling to find a watin equivalent for windows forms (written in c# or vb.net) preferably that is open source.

Does one exist or are all products based on recording mouse and keyboard presses?

Update: I have looked at this blog post on white and it seems the sort of thing I am looking for. The blog post raises some issues but as white is only in version 0.6 these may be resolved. Be interested if others have used white or any others for comparison.

C# Solutions


Solution 1 - C#

Check out http://www.codeplex.com/white and http://nunitforms.sourceforge.net/. We've used the White project with success.

Same Answer to a previous question

Edit

The White project has moved, and is now located on GitHub as part of TestStack.

Solution 2 - C#

AutomatedQA's TestComplete is a good testing application to automate GUI testing. It supports more than just Windows Forms also, so you can reuse it for other applications. It is not open source and this is the best that I have found. I haven't seen an open source equivalent to WatiN. It does have a free trial, for you decide if you like it or not. The main reason I went with it, is that it really is cost effective, compared to other testing applications.

Solution 3 - C#

As a new alternative, I can give you FlaUI (https://github.com/Roemer/FlaUI). It is basically a complete re-write of white with more features and a clean code-base.

Solution 4 - C#

As far as I know, White is an abstraction layer over the top of Microsoft's UI Automation framework. I have written a similar layer that we use internally on our projects and it works great. So White would definattley be worth a look

Microsoft have released the source to UI Automation, so if necessary you should be able to debug right down the whole stack if necessary.

The really cool thing is that with licence cost, you can scale up and run as many machines as you like for execution.

We run inside VSTS and link our results to requirements, but you can use c# express and nUnit and get first class tools and languages for little to no cost.

Solution 5 - C#

Here are some links from MSDN Magazine on automatic testing code:

  • Using UIAutomation Bugslayer March 2007
  • Using PowerShell Test Run December 2007
  • Tester, a utility for recording mouse clicks and keystrokes, then playing them back & program checking behaviour. Excellent for unmanaged code. Uses windows handles so may not work well for managed code. Bugslayer March 2002.

Solution 6 - C#

The list

Please check the updated list at the: List of Automated Testing (TDD/BDD/ATDD/SBE) Tools and Frameworks for .NET: User Interface Testing

Framework Comment
Coded UI Discontinued
FlaUI
NUnitForms Discontinued
Squish GUI Tester
TestComplete
TestStack.White
WinAppDriver

What Microsoft recommends

WinAppDriver

Microsoft recommends to use WinAppDriver:

> Windows Application Driver (WinAppDriver) is a service to support > Selenium-like UI Test Automation on Windows Applications. This service > supports testing Universal Windows Platform (UWP), Windows Forms > (WinForms), Windows Presentation Foundation (WPF), and Classic Windows > (Win32) apps on Windows 10 PCs.

Coded UI (Visual Studio ≤ 2019)

Previously, Coded UI, a Visual Studio built-in feature and part of the UI Automation, was recommended for application UI testing (it's deprecated now):

> Coded UI Test for automated UI-driven functional testing is > deprecated. Visual Studio 2019 is the last version where Coded UI Test > will be available. We recommend using Selenium for testing web apps > and Appium with WinAppDriver for testing desktop and UWP apps. > Consider Xamarin.UITest for testing iOS and Android apps using the > NUnit test framework.

> Automated tests that drive your application through its user interface > (UI) are known as coded UI tests (CUITs). These tests include > functional testing of the UI controls. They let you verify that the > whole application, including its user interface, is functioning > correctly. Coded UI Tests are particularly useful where there is > validation or other logic in the user interface, for example in a web > page. They are also frequently used to automate an existing manual > test.

Read more at: https://docs.microsoft.com/en-us/visualstudio/test/use-ui-automation-to-test-your-code

Solution 7 - C#

WinAppDriver is a Selenium-like UI test automation service for testing Windows applications including Windows Forms applications. It can be used with Appium, a test automation framework.

Solution 8 - C#

You could check out the Microsoft [UI Automation][1] framework. This has been included in .NET since version 3.0. This is actually what the White framework uses anyway.

[1]: http://msdn.microsoft.com/en-us/library/aa348551.aspx "UI Automation"

Solution 9 - C#

You may also use Winium(https://github.com/2gis/Winium) that works on multiple Windows platform besides Windows 10 and is similar to Selenium with extra features that support controlling the application remotely.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohnView Question on Stackoverflow
Solution 1 - C#denis phillipsView Answer on Stackoverflow
Solution 2 - C#Dale RaganView Answer on Stackoverflow
Solution 3 - C#RoemerView Answer on Stackoverflow
Solution 4 - C#Bruce McLeodView Answer on Stackoverflow
Solution 5 - C#MarkJView Answer on Stackoverflow
Solution 6 - C#Dariusz WoźniakView Answer on Stackoverflow
Solution 7 - C#fractorView Answer on Stackoverflow
Solution 8 - C#Sam WarwickView Answer on Stackoverflow
Solution 9 - C#Sumedh SoniView Answer on Stackoverflow