What is the coded UI

Source: Internet
Author: User
Tags manual writing visual studio 2010

What isCoded UI

Coded UI test is a very powerful test tool that visual Studio 2010 provides for testing project (test Engineering), a framework for UI Automation testing, and an automated test that supports UI such as WIN32,WEB,WPF. Coded The UI supports automatic recording and manual authoring.

What Coded UI can do
    1. Open the Application
    2. Simulating user actions
    3. Get UI elements
    4. Uitestcontrol: base class for all UI class libraries
    5. Web test Class Library: HtmlControls (HTMLBUTTON,HTMLDIV, etc.)
    6. WinForm Test Class Library: Wincontrols (Winmenu,winwindow, etc.)
    7. WPF Test Class Library: Wpfcontrols (Wpfcheckbox,wpfpane, etc.)
Coded UI Main Class Library
    1. Uitestcontrol: base class for all UI class libraries
    2. Web test Class Library: HtmlControls (HTMLBUTTON,HTMLDIV, etc.)
    3. WinForm Test Class Library: Wincontrols (Winmenu,winwindow, etc.)
    4. WPF Test Class Library: Wpfcontrols (Wpfcheckbox,wpfpane, etc.)
Coded UI Results Validation class

Assert class: Microsoft.VisualStudio.QualityTools.UnitTesting

Common methods: IsTrue (), IsFalse (), IsNull (), AreEqual ()

Manually writing the coded UI Test

principle: manual writing is the same as the automatic recording principle, but more flexible. Automatic recording generated code is too Fanluan, not easy to modify maintenance, manual writing is easy to manage, can be used in accordance with the actual situation of some common programming methods, the code to do some customization, more readable, the extraction of public parts written general functions make the code easy to maintain.

Ideas:

Identify the program you want to test, and capture this control based on some of the properties of the program control

Perform some operations on the control based on test requirements

Extract control information According to requirements, control state, text information, control definition, etc.

Match the extracted information to the expected information

New coded UI Test project
    • Ibid. create a new test project, add coded UI test
    • Write the test method in the CodedUITest1.cs file. The method body of each test method must have [TestMethod] on it, in order to facilitate the VS2010 of the method execution tool to find the method.
    • Manually get page controls to use IE Developer Tools

Coded UI some ways to do it

Call the HtmlControls class library (there is a sample program later)

    • Open Browser: Call the Browserwindow class to instantiate a Browserwindow object

Browserwindow browser = browserwindow.launch (new Uri ("http://www.baidu.com"))

    • Get div control: Call the Htmldiv class to instantiate a Htmldiv object

Htmldiv Header = new Htmldiv (browser);

Header. Searchproperties[htmldiv.propertynames.class] = "S_tab";

    • Get text box: Call the Htmledit class to instantiate a Htmledit object

Htmledit Txtkeyword = new Htmledit (browser);

Txtkeyword.searchproperties[htmledit.propertynames.class] = "S_ipt";

    • Get button: Invokes the HtmlInputButton class to instantiate a HtmlInputButton object

HtmlInputButton btnsubmit = new HtmlInputButton (browser);

Btnsubmit.searchproperties[htmlinputbutton.propertynames.class] = "S_BTN";

And so on, there are smart hints in the code, or you can query the MSDN Web site to find the appropriate method

    • Mouse click: Mouse.click (HTMLControl);

Mouse.click (btnsubmit);

    • Validation result: Various methods of invoking the Assert class

Assert.istrue (imglogo.exists, "Logo doesn ' t exist!");

    • Wait for the browser to load complete: Browserwindow. Waitforcontrolready ();

    • Let the program wait: System.Threading.Thread.Sleep (number of milliseconds);

Sample program: Verify Baidu Search success
 Public classCodedUITest1 {[TestMethod] Public voidvarifyfeatures () {#regionOpen Browser Get control//Call Browserwindow Open Browser, open IE by defaultBrowserwindow browser = Browserwindow.launch (NewUri ("http://www.baidu.com")); //Open Other Browser methods//Process p = process.start (@ "C:\Users\XXX\AppData\Roaming\360se6\Application\360se.exe", "http://www.baidu.com"); //Browserwindow browser = browserwindow.fromprocess (p); //Find search text boxes based on propertiesHtmledit Txtkeyword =NewHtmledit (browser); Txtkeyword.searchproperties[htmledit.propertynames.class]="S_ipt"; //Find "Baidu button" based on attributesHtmlInputButton btnsubmit =NewHtmlInputButton (browser); Btnsubmit.searchproperties[htmlinputbutton.propertynames.class]="s_btn"; //Find header div based on attributesHtmldiv Header =NewHtmldiv (browser); Header. Searchproperties[htmldiv.propertynames.class]="S_tab"; #endregion            #regionVarious validation//wait for the browser to load completeBrowser.            Waitforcontrolready (); //Enter Test keywordsTxtkeyword.text ="Software Testing"; //Click on "Baidu button"Mouse.click (btnsubmit); //Verify that the keywords inside the search box are correct after the page jumpsAssert.istrue (TxtKeyWord.ValueAttribute.Contains ("Software Testing")); //Close BrowserBrowser.            Close (); #endregion        }    }
View Code

What is the coded UI

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.