Coded UI Test is a framework for UI test automation Visual Studio 2010 for Testing Project (Test Engineering) provided support for Win32, Web, WPF and other UI test automation, is a very powerful test tools, Coded UI supports automatic recording and manual write.
Coded UI can do
- Open the application
- Simulate user actions
- Gets UI elements
- UITestControl: base class for all UI library
- Web test library: HtmlControls (HtmlButton, HtmlDiv, etc.)
- Winform test library: WinControls (WinMenu, WinWindow, etc.)
- WPF test library: WpfControls (WpfCheckBox, WpfPane, etc.)
Coded UI Main Library
- UITestControl: base class for all UI library
- Web test library: HtmlControls (HtmlButton, HtmlDiv, etc.)
- Winform test library: WinControls (WinMenu, WinWindow, etc.)
- WPF test library: WpfControls (WpfCheckBox, WpfPane, etc.)
Coded UI based verification result
Assert类: Microsoft.VisualStudio.QualityTools.UnitTesting
Common methods: IsTrue (), IsFalse (), IsNull (), AreEqual ()
Manually write Coded UI Test
Principle: manual and automatic recording to write the same principle, but more flexible. Automatic code generation recording is too complicated mess, difficult to modify maintenance, easy to manage, then write the manual, you can use some common programming methods in accordance with the actual situation, do some custom code, more readable, extract the public part of making code easier to write generic functions maintain.
Ideas:
Clear program you want to test, according to some attribute this to capture control program controls
According to the test requirements for the controls do something
Controls on demand extraction of information, control status, text information, control definitions, etc.
The extracted information matches the desired information
New Coded UI Test Project
- Ibid create a new Test project, add Coded UI Test
- Writing Test Methods in CodedUITest1.cs file. Each of the above method body should have a test method [TestMethod], in order to facilitate carrying VS2010 discovery method for performing the process tool.
- Manual controls to get the page using IE Developer Tools
Some methods of operation Coded UI
HtmlControls library call (hereinafter sample program)
- Open a browser: Call BrowserWindow class to instantiate an object is BrowserWindow
BrowserWindow browser = BrowserWindow.Launch(new Uri("http://www.baidu.com"))
- Gets Div Controls: call HtmlDiv class to instantiate an object a HtmlDiv
HtmlDiv header = new HtmlDiv(browser);
header.SearchProperties[HtmlDiv.PropertyNames.Class] = "s_tab";
- Get the text box: Call HtmlEdit class to instantiate an object is HtmlEdit
HtmlEdit txtKeyWord = new HtmlEdit(browser);
txtKeyWord.SearchProperties[HtmlEdit.PropertyNames.Class] = "s_ipt";
- Gets buttons: call HtmlInputButton class to instantiate an object a HtmlInputButton
HtmlInputButton btnSubmit = new HtmlInputButton(browser);
btnSubmit.SearchProperties[HtmlInputButton.PropertyNames.Class] = "s_btn";
And so on, there will be smart tips in the code, or visit the MSDN Web site to find the appropriate method
- Mouse click: Mouse.Click (HtmlControl);
Mouse.Click(btnSubmit);
- Validation results: calling various methods Assert class
Assert.IsTrue(imgLogo.Exists, "Logo doesn't exist!");
- Wait for the browser to load completion: BrowserWindow .WaitForControlReady ();
- Let the program waits: System.Threading.Thread.Sleep (milliseconds);