public AutomationElement GetFunctionButton(ITestObject control) { AutomationElement functionButton = UIATestObject.ToAutomationObject(control); //AutomationElement functionButton = _calculatorAutomationElement.FindFirst(TreeScope.Descendants, // new PropertyCondition(AutomationElement.NameProperty, functionName)); if (functionButton == null) { throw new InvalidOperationException("No function button found with descriptor: " + control.ToString()); } return(functionButton); }
//initialize the class using model file path public Calculator(string modelFilePath) { _calculatorProcess = TestUtility.LaunchCalc(); _calcModel = AppModelSerializer.Load(modelFilePath); int ct = 0; do { _calculatorAutomationElement = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Calculator")); ct++; Thread.Sleep(100); }while (_calculatorAutomationElement == null || ct < 50); if (_calculatorAutomationElement == null) { throw new InvalidOperationException("Calculator must be missing"); } _resultAutomationElement = _calculatorAutomationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "") //new AndCondition(new Condition[] { // new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text), // new PropertyCondition(AutomationElement.NameProperty, "")}) ); // new PropertyCondition(AutomationElement.AutomationIdProperty, 150)); //This is used for Windows Calc (< Win 10) if (_resultAutomationElement == null) { throw new InvalidOperationException("Could not find result box"); } //TODO get invoke pattern ITestObject clearButton = _calcModel[Functions.Clear]; GetInvokePattern(UIATestObject.ToAutomationObject(clearButton)).Invoke(); }