Learn to use Visual Studio, Visual Studio Online, Application Insights and Team Foundation Server to decrease rework, increase transparency into your application and increase the rate at which you can ship high quality software throughout the application lifecycle
More videos »
In the last few months since Windows 8 RTM’ed, we have seen the number of apps on the Windows Store grow significantly. There are several different aspects to shipping a great app to the Store. One of these is testing your app to ensure that the bugs are flushed out and you have automated tests in place to ensure that you can make regression free enhancements to your app.
Visual Studio 2012 enabled Manual testing and Unit testing for Store apps. In the subsequent updates, we continued to enhance these features. Several customers were asking when Coded UI tests could be used for UI testing the Store apps and I am very happy to say that with Visual Studio 2013 Preview, you can now use Coded UI tests to test XAML based Windows Store apps.
So let’s take a look at what’s new and different. Additional posts will come over the next few days to take you into more details.
Writing a Coded UI test for XAML based Store app is super easy. When you install Visual Studio 2013 Preview on Windows 8.1, you will see a new template under the Windows Store node that lets you create Coded UI Test for your app.
After you create a new project, you will be shown the familiar Generate Code dialog.
A few changes to note here:
Similar to the specialized classes that Coded UI test provides for testing WinForms/WPF/Web applications, we have a set of new specialized classes available that you can use for authoring the test.
These are available under the Microsoft.VisualStudio.TestTools.UITesting.WindowsRuntimeControls namespace and all controls are prefixed with Xaml. So XamlButton, XamlList, XamlFlipView etc are the specialized classes to use. WinRT controls such as the Settings charm or the tiles on the start screen are not XAML controls. So when you generate code for tests that say, want to launch an app using the tile or test the Settings charm integration, classes under the namespace Microsoft.VisualStudio.TestTools.UITesting.DirectUIControls are your friend!
And, the familiar Html* classes are available for testing scenarios that involve testing HTML content hosted inside a Webview control in the app.
The store apps deliver a great experience with Touch and Coded UI test would be incomplete without supporting Touch Gestures. All touch gestures are supported and you can use the Microsoft.VisualStudio.TestTools.UITesting.Gesture class to write appropriate touch actions to act on controls of interest. For example, to Tap on a button, you can now write:
The cool thing is, you do not need a Touch monitor to be able to run tests that use these gestures. Gestures are simulated under the hood by sending appropriate messages to the input subsystem of the OS.
Of course, Mouse actions are available as well. So, for e.g., Mouse.Click and Gesture.Tap would have the same effect of triggering an action on a control and you can use them interchangeably to suit the needs of your test.
With the new app model introduced in Windows 8, you cannot launch a Store app using an executable path like you could in the desktop world. The same goes for launching an app via your test code. You can launch an app in two ways:
XamlWindow myAppWindow = XamlWindow.Launch(stringThatIdentifiesMyApp);
where stringThatIdentifiesMyApp is the unique identifier that Windows uses to identify a Store app. You can obtain this string value by observing the app tile in CUIT builder and copy/pasting the AutomationId property of the tile control, like so:
The rest of the CUIT experience stays the same and you can continue to use the features you are familiar with. For e.g., you can add assertions using the CUIT Builder, use the HTML Logs for troubleshooting, the WaitFor* to wait for specific events during playback, data drive your CUI test just the way you could do when testing desktop apps.
First things first, install Windows 8.1 Preview and VS 2013 Preview if you haven’t already.
For those of you that have not used Coded UI test before, or want to see these new features in action on a pre-canned test, I am attaching a sample Coded UI Test project I created for testing the multiply functionality of the calculator app that ships inbox with Windows 8.1. Just download and build the project and execute the test from Test Explorer.
Alternately, if you would like to do a walkthrough by creating a simple Store app and writing a Coded UI test for that sample app, this msdn link can help you get started.
We are excited about our customers using Coded UI Test to test their XAML based store apps and look forward to hearing your feedback.
So I have been able to create a Test suite using Coded UI for our app but currently I am stuck at 2 places:
1) I am unable to save any changes made to the code in Designer.cs file, it saves it initially but on adding any new element it reverts back
2) I run into the below error during run-time again and again even though the elements can be found :
Test method threw exception:
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotAvailableException: The control is not available or not valid. ---> System.Windows.Automation.ElementNotAvailableException: Element not available ---> System.Runtime.InteropServices.COMException: An event was unable to invoke any of the subscribers (Exception from HRESULT: 0x80040201)
Please can you help me out here? I appreciate your help!!
Waiting to hear back from you as I blocked from automating further due to above issues.
@Testuser: Please use the UIMap editor to delete controls, and assertion methods from the UIMap.uitest file - this will automatically delete from the UIMap.Designer.cs file - the designer.cs file should never be hand-edited as any subsequent edits to the UIMap will re-generate the code behind and your changes will be lost.
@Testuser: Have you specified a control for the Keyboard.SendKeys method when you send the Backspace keys?
@Manu Gowda: Yes, the code in designer.cs file is auto-generated. Any changes made to it will be lost when you update your UIMap. To preserve changes made manually, please move the relevant code to UIMap.cs file.
For the UITestControlNotAvailableException, can you describe what the test is doing when you run into the issue? Can you see if using SearchConfiguration.AlwaysSearch as described here fixes the issue?
Are there any plans to support WinJS apps with Coded UI before final release of VS 2013?
@Pr: No, VS 2013 does not support Coded UI Test for WinJS apps.
Relatively new to Windows UI Automation, I have a framework which launches a Modern UI app and runs the automation. The framework code and the app codebase is entirely in C#. How do I get the code coverage with such a framework? Any help will be appreciated. Will this Coded UI help me to get the code coverage?
@Rahul: Code coverage for Windows Store apps is not supported currently.
How can we parse data from different worksheets of a single excel file?
Currently I can parse the data through single worksheet by using below code but I want to parse the data from multiple worksheets of an excel for our tests. Can you please let me know if there is way to do so?
I use below currently:
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\TestData.xlsx;Persist Security Info=False;Extended Properties='Excel 12.0 Xml;HDR=YES'","Sheet1$",DataAccessMethod.Sequential),TestMethod]