Dennisaa

WinForms

May 8th, 2015
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.83 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 WindowsFormsControlsTest {
  12.  
  13.         /// <summary>
  14.         /// Simple execution (I do not claim it is a real test) of a Windows Forms app containing a number
  15.         /// of distinct controls.
  16.         /// This was originally generated using the Coded UI Test Builder, but with the noise of
  17.         /// the endless Windows titles etc. removed.
  18.         /// This is to be converted to a Page Pattern and more ambitiously will be technology agnostic.
  19.         /// </summary>
  20.         [TestMethod]
  21.         public void WindowsFormsTypeControlsAreExecuted() {
  22.  
  23.             var simpleCalculator = ApplicationUnderTest.Launch(@"c:\temp\WindowsFormsApplication1.exe");
  24.  
  25.             // outer Window control...
  26.             var topLevelCalculatorWindow = new WinWindow(simpleCalculator);
  27.             topLevelCalculatorWindow.SearchProperties.Add(new PropertyExpression(WinWindow.PropertyNames.ClassName,
  28.                 "WindowsForms10.Window", PropertyExpressionOperator.Contains));
  29.  
  30.             // Button: it seems that you have to put text in the button, for that is how the button is found...
  31.             var buttonControl = new WinWindow(topLevelCalculatorWindow);
  32.             buttonControl.SearchProperties[WinWindow.PropertyNames.ControlName] = "MybuttonControlName";
  33.             var calcButton = new WinButton(buttonControl);
  34.             calcButton.SearchProperties.Add(WinButton.PropertyNames.Name, "Click Me");
  35.             Mouse.Click(calcButton);
  36.  
  37.             // TextBox...
  38.             var editControl = new WinWindow(topLevelCalculatorWindow);
  39.             editControl.SearchProperties[WinWindow.PropertyNames.ControlName] = "textbox42";
  40.             var textBox = new WinEdit(editControl);
  41.             textBox.Text = "The way you were";
  42.  
  43.             // CheckBox...
  44.             var checkBoxControl = new WinWindow(topLevelCalculatorWindow);
  45.             checkBoxControl.SearchProperties[WinWindow.PropertyNames.ControlName] = "checkBox1";
  46.             var checkBox = new WinCheckBox(checkBoxControl);
  47.             checkBox.Checked = true;
  48.  
  49.             //  ComboBox...
  50.             var comboControl = new WinWindow(topLevelCalculatorWindow);
  51.             comboControl.SearchProperties[WinWindow.PropertyNames.ControlName] = "comboBox1";
  52.             var combo = new WinComboBox(comboControl);
  53.             for (int i = 0; i < 3; i++) {
  54.                 combo.SelectedIndex = i;
  55.                 Playback.Wait(500);
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment