Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.VisualStudio.TestTools.UITesting;
- using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;
- namespace CodedUITestProject8 {
- /// <summary>
- /// Simple sandbox app for testing MSAA controls, i.e. Windows Forms
- /// </summary>
- [CodedUITest]
- public class WindowsFormsControlsTest {
- /// <summary>
- /// Simple execution (I do not claim it is a real test) of a Windows Forms app containing a number
- /// of distinct controls.
- /// This was originally generated using the Coded UI Test Builder, but with the noise of
- /// the endless Windows titles etc. removed.
- /// This is to be converted to a Page Pattern and more ambitiously will be technology agnostic.
- /// </summary>
- [TestMethod]
- public void WindowsFormsTypeControlsAreExecuted() {
- var simpleCalculator = ApplicationUnderTest.Launch(@"c:\temp\WindowsFormsApplication1.exe");
- // outer Window control...
- var topLevelCalculatorWindow = new WinWindow(simpleCalculator);
- topLevelCalculatorWindow.SearchProperties.Add(new PropertyExpression(WinWindow.PropertyNames.ClassName,
- "WindowsForms10.Window", PropertyExpressionOperator.Contains));
- // Button: it seems that you have to put text in the button, for that is how the button is found...
- var buttonControl = new WinWindow(topLevelCalculatorWindow);
- buttonControl.SearchProperties[WinWindow.PropertyNames.ControlName] = "MybuttonControlName";
- var calcButton = new WinButton(buttonControl);
- calcButton.SearchProperties.Add(WinButton.PropertyNames.Name, "Click Me");
- Mouse.Click(calcButton);
- // TextBox...
- var editControl = new WinWindow(topLevelCalculatorWindow);
- editControl.SearchProperties[WinWindow.PropertyNames.ControlName] = "textbox42";
- var textBox = new WinEdit(editControl);
- textBox.Text = "The way you were";
- // CheckBox...
- var checkBoxControl = new WinWindow(topLevelCalculatorWindow);
- checkBoxControl.SearchProperties[WinWindow.PropertyNames.ControlName] = "checkBox1";
- var checkBox = new WinCheckBox(checkBoxControl);
- checkBox.Checked = true;
- // ComboBox...
- var comboControl = new WinWindow(topLevelCalculatorWindow);
- comboControl.SearchProperties[WinWindow.PropertyNames.ControlName] = "comboBox1";
- var combo = new WinComboBox(comboControl);
- for (int i = 0; i < 3; i++) {
- combo.SelectedIndex = i;
- Playback.Wait(500);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment