Advertisement
Dennisaa

Coded UI - WinForms

May 7th, 2015
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 KB | None | 0 0
  1. using Microsoft.VisualStudio.TestTools.UITesting;
  2. using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;
  5.  
  6. namespace CodedUITestProject8 {
  7.     /// <summary>
  8.     /// Simple sandbox app for testing MSAA controls, i.e. Windows Forms
  9.     /// </summary>
  10.     [CodedUITest]
  11.     public class myCalcCodedUITest1 {
  12.  
  13.         /// <summary>
  14.         /// Very simple test of a Windows Forms app containing a single button and a single text box.
  15.         /// This was originally generated using the UI Test... what is it called? But with the noise of
  16.         /// the endless Windows titles etc. removed.
  17.         /// This is to be converted to a Page Pattern and more ambitiously will be technology agnostic.
  18.         /// </summary>
  19.         [TestMethod]
  20.         public void AButtonIsClickedAndTextisEnteredInAnEditControl() {
  21.  
  22.             var simpleCalculator = ApplicationUnderTest.Launch(@"c:\temp\WindowsFormsApplication1.exe");
  23.             var topLevelCalculatorWindow = new WinWindow(simpleCalculator);
  24.             topLevelCalculatorWindow.SearchProperties.Add(new PropertyExpression(WinWindow.PropertyNames.ClassName,
  25.                 "WindowsForms10.Window", PropertyExpressionOperator.Contains));
  26.  
  27.             // Button...
  28.             var buttonControl = new WinWindow(topLevelCalculatorWindow);
  29.             buttonControl.SearchProperties[WinWindow.PropertyNames.ControlName] = "MybuttonControlName";
  30.  
  31.             var calcButton = new WinButton(buttonControl);
  32.             calcButton.SearchProperties.Add(WinButton.PropertyNames.Name, "MyDisplayText");
  33.             Mouse.Click(calcButton);
  34.  
  35.             // TextBox...
  36.             var editControl = new WinWindow(topLevelCalculatorWindow);
  37.             editControl.SearchProperties[WinWindow.PropertyNames.ControlName] = "textbox42";
  38.  
  39.             var textBox = new WinEdit(editControl);
  40.             textBox.Text = "The way you were";
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement