Hand Coding Coded UI Tests [closed]

2019-03-26 05:27发布

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

4条回答
smile是对你的礼貌
2楼-- · 2019-03-26 06:02

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).

查看更多
迷人小祖宗
3楼-- · 2019-03-26 06:11

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

Coded UI Tests-DeepDive-Episode3-HandCoding

查看更多
唯我独甜
4楼-- · 2019-03-26 06:20

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

查看更多
smile是对你的礼貌
5楼-- · 2019-03-26 06:24

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/

查看更多
登录 后发表回答