Hand Coding Coded UI Tests [closed]
Asked Answered
U

4

10

Hi I am looking at using Coded UI Tests (CUIT) to test an application. I have tried the recording option and this is not flexible enough for me. If you use it on a different size screen it breaks.

I know you can hand code the tests but I cannot find any good examples of how to write a basic test. There are examples on here that use CUITe but these posts are from 2011 and I'm not sure how relevant they are anymore with the new upgrades to CUIT from Microsoft.

These tests need to be integrated with my build environments in Visual Studio 2012 Ultimate, that is why I'm not using Selenium.

And Code samples or links to good tutorials would be appreciated, but in particular I am looking for an exampl on how to start hand coding my CUITs

Underhill answered 21/6, 2013 at 14:52 Comment(4)
Have you tried working with the UI Automation Framework directly? It is what the Coded UI Tests are built off of. I like this tutorial of it: blog.functionalfun.net/2009/06/…Marcellamarcelle
Integrated into your build environment how?Bebebebeerine
we are looking into adding it to the build config the same way you would automate your unit tests. I'm still waiting on access rights to be able to edit the build config file but hopefully they won't be too longUnderhill
@Bebebebeerine here's a link to adding CUIT tests to your build environment msdn.microsoft.com/en-us/library/ms182465(v=vs.100).aspxUnderhill
D
6

The Code First coded UI test API project on CodePlex (http://codeduicodefirst.codeplex.com/) includes a project demo that you can download - application and tests. It's designed for building CUIT tests without the dependency on record/playback.

The biggest thing that you need if you're going to work on a code-only basis is a way to avoid the dependency on the autogenerated object map the CUIT recordings create. The Code-First project uses classes mapped to individual page objects to work around this - you'd need to extend the project code to work with desktop applications if I remember correctly.

(I am not affiliated with this project in any way - it's just the only hand-coding resource other than CUITe that I've found, and CUITe hasn't been updated in a while, the last I saw).

Domingadomingo answered 2/7, 2013 at 16:43 Comment(1)
The last update was in March 2012, and it has been downloaded 3 (!) times...Discordant
D
2

Not a lot of developers know this, but it's possible to create Code First tests with CodedUI. It's not being advocated, which is bad imo. I consider the Recording option as a fragile one. It uses mouse coords which means you have to recreate the tests when the UI changes...

The maintainable way would be to use the Page Object pattern (also used by other popular tools like Selenium). This creates an abstraction of the UI which gives you more flexibility and strong typing.

You get easy, readable and most of all maintainable code:

var storeHyperlink = new HtmlHyperlink(_browserWindow);
storeHyperlink.SearchProperties[HtmlHyperlink.PropertyNames.Id] = "StoreLink";
Mouse.Click(storeHyperlink);

Read more

Discordant answered 26/4, 2015 at 9:38 Comment(0)
C
1

Here is a video showing how to do Code First coded UI tests:

Coded UI Tests-DeepDive-Episode3-HandCoding

Crim answered 3/12, 2013 at 8:26 Comment(1)
The video you're referring to is at the bottom, in the Video's section: go.microsoft.com/fwlink/?LinkID=230575Discordant
R
1

Not sure if someone is still looking to find out how to best hand code the Coded UI tests but imo going to the record and playback route is going to be disappointing later on! Best way is to create an automation framework which defines individual objects which you want to interact with and have the page objects to handle your business logic. If you are testing web applications you can define objects using generic UITestControls or HtmlControls. For example:

public static UITestControl EditBox_Password
{
    get
    {
        if ( mEditBox_Password == null ||   ! mEditBox_Password.Exists )
        {
            mEditBox_Password = new UITestControl (browserWindow );
            mEditBox_Password.TechnologyName = "Web";
            mEditBox_Password.SearchProperties.Add (UITestControl.PropertyNames.ControlType , "Edit");
            mEditBox_Password.SearchProperties.Add ( UITestControl.PropertyNames.Name , "TxtPassword");
        }
        return mEditBox_Password ;
    }
}

If you are testing Windows-based applications then you can define objects using WinControls or WpfControls.

I recently bought a book on Amazon (Hand Coding Coded UI) which clearly defines how to setup the framework and create an easily maintainable code. Not sure if it is available in any book store but here is the link on Amazon if you want to have a look

https://www.amazon.com/dp/1547000856/ref=sr_1_1?s=books&ie=UTF8&qid=1496767488&sr=1-1&keywords=1547000856

I hope it is helpful.

Updated: Just googled it and there is a discount code for the book at http://www.arkenstone-ltd.com/testing-with-coded-ui/

Rhodic answered 26/6, 2017 at 7:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.