public Task <ISubscriptionClient> CreateSubscriptionReceiver(string topicPath, string subscriptionName, IFilterCondition filterCondition) { const string ruleName = "$Default"; return(Task.Run(() => { EnsureSubscriptionExists(topicPath, subscriptionName); var myOwnSubscriptionFilterCondition = new OrCondition(new MatchCondition(MessagePropertyKeys.RedeliveryToSubscriptionName, subscriptionName), new IsNullCondition(MessagePropertyKeys.RedeliveryToSubscriptionName)); var combinedCondition = new AndCondition(filterCondition, myOwnSubscriptionFilterCondition); var filterSql = _sqlFilterExpressionGenerator.GenerateFor(combinedCondition); return _retry.Do(async() => { var subscriptionClient = _connectionManager .CreateSubscriptionClient(topicPath, subscriptionName, ReceiveMode.ReceiveAndDelete); var rules = await subscriptionClient.GetRulesAsync(); if (rules.Any(r => r.Name == ruleName)) { await subscriptionClient.RemoveRuleAsync(ruleName); } await subscriptionClient.AddRuleAsync(ruleName, new SqlFilter(filterSql)); return subscriptionClient; }, "Creating subscription receiver for topic " + topicPath + " and subscription " + subscriptionName + " with filter expression " + filterCondition); }).ConfigureAwaitFalse()); }
public static string GetFirefoxUrl() { try { AutomationElement root = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "MozillaWindowClass")); Condition toolBar = new AndCondition( new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit), new PropertyCondition(AutomationElement.NameProperty, "Wprowadź adres lub szukaj")); var tool = root.FindFirst(TreeScope.Descendants, toolBar); var tmp = tool.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern; if (tmp != null) { return(tmp.Current.Value); } } catch { return("(EXCEPTION 1)"); } return(""); }
private bool DismissUACPrompts() { logger.Info("Trying to find the (focused) UAC elevation prompt."); AutomationElement dialog = this.uiAutomation.GetFocusedWindowOrRoot(); { var conditions = new AndCondition( Automation.ContentViewCondition, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane), new PropertyCondition(AutomationElement.ClassNameProperty, "CtrlNotifySink")); var elements = dialog.FindAll(TreeScope.Descendants, conditions); if (elements.Count > 0) { logger.Info("The UAC elevation prompt found."); // sending keystrokes (Alt + Y / N) is more reliable. this.keyboard.ReleaseAllModifierKeys(); this.keyboard.KeyUpOrDown(Key.LeftAlt); this.keyboard.KeyPress(this.allowed ? Key.Y : Key.N); this.keyboard.KeyUpOrDown(Key.LeftAlt); return(true); } } return(false); }
internal static IEnumerable <PsComplianceRulePredicateBase> ConvertEngineConditionToTaskConditions(Microsoft.Office.CompliancePolicy.PolicyEvaluation.Condition condition) { List <PsComplianceRulePredicateBase> list = new List <PsComplianceRulePredicateBase>(); QueryPredicate queryPredicate = condition as QueryPredicate; if (queryPredicate != null) { AndCondition andCondition = queryPredicate.SubCondition as AndCondition; if (andCondition == null) { return(list); } using (List <Microsoft.Office.CompliancePolicy.PolicyEvaluation.Condition> .Enumerator enumerator = andCondition.SubConditions.GetEnumerator()) { while (enumerator.MoveNext()) { Microsoft.Office.CompliancePolicy.PolicyEvaluation.Condition condition2 = enumerator.Current; list.AddRange(PsHoldRule.ConvertEngineConditionToTaskConditions(condition2)); } return(list); } } if (condition is PredicateCondition) { PredicateCondition predicate = condition as PredicateCondition; list.Add(PsComplianceRulePredicateBase.FromEnginePredicate(predicate)); } else if (!(condition is TrueCondition)) { throw new UnexpectedConditionOrActionDetectedException(); } return(list); }
/// <summary> /// Performs the search of the element by adding conditions based on the parsed conditions then calling FindWithTimeout /// </summary> /// <param name="selector">user input selector string to parse in format property1:value1,property2:value2..</param> /// <param name="child">Allows the user to select which control to use if there are several matching input conditions</param> /// <param name="timeout">time to search for the element before throwing an error</param> /// <returns>AutomationElement if succesfull </returns> private static AutomationElement Search(string selector, int child = 0, double timeout = timeout) { List <Condition> conditionList = new List <Condition>(); //contains the list of conditions that we will search with Dictionary <string, string> valueParameter = new Dictionary <string, string>(); //used if the user does a search based on value //if user chooses to search by value then we search by value only. This is to keep code simple if (selector.Contains("value")) { Debug.WriteLine("Doing a search by value. Ignoring other conditions in input selector"); return(FindByValue(selector, timeout)); } Dictionary <AutomationProperty, string> searchParameters = ParseSelector(selector); //parse users input //Add all the parameters returned from the parsing into our list of conditions foreach (KeyValuePair <AutomationProperty, string> entry in searchParameters) { conditionList.Add(new PropertyCondition(entry.Key, entry.Value)); } Debug.WriteLine("Condition List contains: " + conditionList.ToString()); conditionList.Add(Automation.ControlViewCondition); //only view control elements Condition[] conditionsArray = conditionList.ToArray(); //needs to be converted to array to be fed to AutomationElement.FindAll() Condition searchConditions = new AndCondition(conditionsArray); return(FindWithTimeout(selector, searchConditions, child, timeout)); }
private Condition GetCondition() { var info = this.infoList[0]; Condition result = new PropertyCondition(info.Property, info.Value); for (var i = 1; i < this.infoList.Count; ++i) { info = this.infoList[i]; var condition = new PropertyCondition(info.Property, info.Value); switch (info.ConditionType) { case ConditionType.And: result = new AndCondition(result, condition); break; case ConditionType.Or: result = new OrCondition(result, condition); break; default: throw new CruciatusException("ConditionType ERROR"); } } return(result); }
private static void SelectItemInComboBox(AutomationElement element, String selectedItemName) { // Get the mapped item name. String itemName = TestDataInfrastructure.GetControlId(selectedItemName); // Set focus to ensure that the object is selected. element.SetFocus(); // Expand the ComboBox using ExpandCollapsePattern. ExpandCollapsePattern expandPattern = element.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; expandPattern.Expand(); // get the desired automation element PropertyCondition itemNameCondition = new PropertyCondition(AutomationElement.NameProperty, itemName); PropertyCondition itemTypeCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem); AndCondition itemCondition = new AndCondition(itemNameCondition, itemTypeCondition); AutomationElement item = element.FindFirst(TreeScope.Descendants, itemCondition); if (item != null) { // select combo box item ((SelectionItemPattern)item.GetCurrentPattern(SelectionItemPattern.Pattern)).Select(); } }
public static AutomationElement GetAutoElemFromXML(XmlDocument XML) { AutomationElement _ReturnElement = AutomationElement.RootElement; //As programmed, each XMLDoc contains multiple nodes with attributes //containing the element specific details. //Lets start with getting all the nodes. XmlNode xmlChildNode = XML.ChildNodes[0]; while (xmlChildNode != null) { XmlAttributeCollection NodeAttrs = xmlChildNode.Attributes; try { AndCondition AllConditions = new AndCondition(new PropertyCondition(AutomationElement.NameProperty, NodeAttrs["Name"].Value), new PropertyCondition(AutomationElement.AutomationIdProperty, NodeAttrs["AutoID"].Value), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.LookupById(int.Parse(NodeAttrs["CtrlID"].Value))), new PropertyCondition(AutomationElement.ClassNameProperty, NodeAttrs["Class"].Value)); AutomationElement _FoundElem = _ReturnElement.FindFirst(TreeScope.Descendants, AllConditions); _ReturnElement = _FoundElem; try { xmlChildNode = xmlChildNode.ChildNodes[0]; } catch { xmlChildNode = null; } } catch { MessageBox.Show("Probably invalid XML format. Check that all attributes exist.", "NullReferenceException"); _ReturnElement = null; break; } } return(_ReturnElement); }
/// <summary> /// Discard check out a document on opening word /// </summary> /// <param name="name">Document name</param> public static void DiscardCheckOutOnOpeningWord(string name) { AutomationElement docOnline = GetWordOnlineWindow(name); Condition File_Tab = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "File Tab")); AutomationElement item_File = docOnline.FindFirst(TreeScope.Descendants, File_Tab); InvokePattern Pattern_File = (InvokePattern)item_File.GetCurrentPattern(InvokePattern.Pattern); Pattern_File.Invoke(); Condition Group_Info = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Group), new PropertyCondition(AutomationElement.NameProperty, "Info")); AutomationElement item_Info = docOnline.FindFirst(TreeScope.Descendants, Group_Info); Condition Con_AlertCheckOut = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Group), new PropertyCondition(AutomationElement.NameProperty, "Alert - Checked Out Document")); AutomationElement item_AlertCheckOut = item_Info.FindFirst(TreeScope.Descendants, Con_AlertCheckOut); Condition Con_DiscardCheckOut = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Discard Check Out")); AutomationElement item_DiscardCheckOut = item_AlertCheckOut.FindFirst(TreeScope.Descendants, Con_DiscardCheckOut); InvokePattern Pattern_CheckOut = (InvokePattern)item_DiscardCheckOut.GetCurrentPattern(InvokePattern.Pattern); Pattern_CheckOut.Invoke(); CloseMicrosoftWordDialog(name, "Yes"); Condition File_Save = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Save")); AutomationElement item_Save = docOnline.FindFirst(TreeScope.Descendants, File_Save); InvokePattern Pattern_Save = (InvokePattern)item_Save.GetCurrentPattern(InvokePattern.Pattern); Pattern_Save.Invoke(); Thread.Sleep(2000); }
/// <summary> /// Merge document with conflict /// </summary> /// <param name="filename">file name</param> public static void WordConflictMerge(string filename) { var desktop = AutomationElement.RootElement; //Microsoft.Office.Interop.Word.Application wordToOpen = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application"); //Microsoft.Office.Interop.Word.Document oDocument = (Microsoft.Office.Interop.Word.Document)wordToOpen.ActiveDocument; Condition Con_Document = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window), new OrCondition(new PropertyCondition(AutomationElement.NameProperty, filename + ".docx - Word"), new PropertyCondition(AutomationElement.NameProperty, filename + " - Word"))); AutomationElement item_Document = desktop.FindFirst(TreeScope.Children, Con_Document); Condition Con_Resolve = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Resolve")); AutomationElement item_Resolve = WaitForElement(item_Document, Con_Resolve, TreeScope.Descendants, false); item_Resolve = item_Document.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Resolve")); InvokePattern Pattern_Resolve = (InvokePattern)item_Resolve.GetCurrentPattern(InvokePattern.Pattern); Pattern_Resolve.Invoke(); Condition Con_AcceptMyChange = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.SplitButton), new PropertyCondition(AutomationElement.NameProperty, "Accept My Change")); AutomationElement item_AcceptMyChange = WaitForElement(item_Document, Con_AcceptMyChange, TreeScope.Descendants, false); ExpandCollapsePattern Pattern_AcceptMyChange = (ExpandCollapsePattern)item_AcceptMyChange.GetCurrentPattern(ExpandCollapsePatternIdentifiers.Pattern); Pattern_AcceptMyChange.Expand(); Condition Con_AcceptAll = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem), new PropertyCondition(AutomationElement.NameProperty, "Accept All Conflicting Changes in Document")); AutomationElement item_AcceptAll = WaitForElement(item_Document, Con_AcceptAll, TreeScope.Descendants, false); InvokePattern Pattern_AcceptAll = (InvokePattern)item_AcceptAll.GetCurrentPattern(InvokePattern.Pattern); Pattern_AcceptAll.Invoke(); Thread.Sleep(4000); Condition Con_SaveCloseView = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Save and Close View")); AutomationElement item_SaveCloseView = WaitForElement(item_Document, Con_SaveCloseView, TreeScope.Descendants, false); InvokePattern Pattern_SaveCloseView = (InvokePattern)item_SaveCloseView.GetCurrentPattern(InvokePattern.Pattern); Pattern_SaveCloseView.Invoke(); }
private static AutomationElement GetChromiumElement(Process process) { AutomationElement element = null; if (process != null && process.MainWindowHandle != IntPtr.Zero) { AutomationElement rootElement = AutomationElement.FromHandle(process.MainWindowHandle); if (rootElement == null) { return(null); } Condition conditions = new AndCondition(new PropertyCondition(AutomationElement.ClassNameProperty, "Chrome_RenderWidgetHostHWND"), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document) ); element = rootElement .FindFirst(TreeScope.Descendants, conditions); } return(element); }
public void Test_4() { var condition1 = new SqlCondition("Name=@Name"); var condition = new AndCondition(condition1, null); Assert.Equal("Name=@Name", condition.GetCondition()); }
public void TestAndCondition() { var condition = new AndCondition() { Relations = new List <Relation>() { new IsRelation() { Expr = new Expr() { Operand = Operand.n }, Value = 4 }, new InRelation() { Expr = new Expr() { Operand = Operand.n }, Ranges = new List <Range <int> >() { new Range <int>(3, 7) } } } }; condition.Match("4").Should().BeTrue(); condition.Match("5").Should().BeFalse(); }
// <Snippet100> ///-------------------------------------------------------------------- /// <summary> /// Finds all automation elements that satisfy /// the specified condition(s). /// </summary> /// <param name="targetApp"> /// The automation element from which to start searching. /// </param> /// <returns> /// A collection of automation elements satisfying /// the specified condition(s). /// </returns> ///-------------------------------------------------------------------- private AutomationElementCollection FindAutomationElement( AutomationElement targetApp) { if (targetApp == null) { throw new ArgumentException("Root element cannot be null."); } PropertyCondition conditionSupportsGridPattern = new PropertyCondition( AutomationElement.IsGridPatternAvailableProperty, true); PropertyCondition conditionOneColumn = new PropertyCondition( GridPattern.ColumnCountProperty, 1); PropertyCondition conditionOneRow = new PropertyCondition( GridPattern.RowCountProperty, 1); AndCondition conditionSingleItemGrid = new AndCondition( conditionSupportsGridPattern, conditionOneColumn, conditionOneRow); return targetApp.FindAll( TreeScope.Descendants, conditionSingleItemGrid); }
public void GetNextSiblingTest() { Condition buttonCondition = new PropertyCondition(AEIds.ControlTypeProperty, ControlType.Button); TreeWalker buttonWalker = new TreeWalker(buttonCondition); AssertRaises <ArgumentNullException> ( () => buttonWalker.GetNextSibling(null), "passing null to TreeWalker.GetNextSibling"); VerifyGetNextSibling(buttonWalker, button7Element, button6Element); VerifyGetNextSibling(buttonWalker, button6Element, button5Element); VerifyGetNextSibling(buttonWalker, button5Element, button4Element); VerifyGetNextSibling(buttonWalker, button4Element, button3Element); VerifyGetNextSibling(buttonWalker, button3Element, button2Element); // Check that there are still more siblings (just without groupBox1Element as parent) VerifyGetNextSibling(buttonWalker, button2Element, button1Element); // TODO: Test how for buttonWalker, GetNextSibling // eventually gets all buttons on the entire // desktop? // Elements whose parents (not the desktop) are also in // the tree run out of siblings as expected. Condition groupCondition = new AndCondition( new PropertyCondition(AEIds.ControlTypeProperty, ControlType.Group), new PropertyCondition(AEIds.ProcessIdProperty, p.Id)); TreeWalker groupWalker = new TreeWalker(groupCondition); VerifyGetNextSibling(groupWalker, groupBox3Element, groupBox2Element); VerifyGetNextSibling(groupWalker, groupBox2Element, null); // When only other matching thing in tree is child (TODO: Hangs) //VerifyGetNextSibling (groupWalker, groupBox1Element, groupBox2Element); }
public static List <string> GetMozillaActiveUrl() { var stringList = new List <string>(); Process[] procsChrome = Process.GetProcessesByName("firefox"); foreach (Process chrome in procsChrome) { if (chrome.MainWindowHandle == IntPtr.Zero) { continue; } AutomationElement element = AutomationElement.FromHandle(chrome.MainWindowHandle); if (element != null) { Condition conditions = new AndCondition( new PropertyCondition(AutomationElement.ProcessIdProperty, chrome.Id), new PropertyCondition(AutomationElement.IsControlElementProperty, true), new PropertyCondition(AutomationElement.IsContentElementProperty, true), new PropertyCondition(AutomationElement.NameProperty, "Найдите в Google или введите адрес", PropertyConditionFlags.IgnoreCase), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)); AutomationElement elementx = element.FindFirst(TreeScope.Descendants, conditions); if (elementx != null) { var value = ((ValuePattern)elementx.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string; stringList.Add(value); } } } return(stringList); }
private void OpenTemporaryFile(FileInfo xmlFIle) { var openFileDialog = MainWindow.FindDescendant(new PropertyCondition(AutomationElement.NameProperty, "Open File")); var directoryPickerCondition = new PropertyCondition(AutomationElement.NameProperty, "All locations", PropertyConditionFlags.IgnoreCase); var directoryPicker = openFileDialog.FindDescendant(directoryPickerCondition); directoryPicker.LeftClick(); SendKeys.SendWait(xmlFIle.DirectoryName); SendKeys.SendWait("{ENTER}"); var filePickerCondition = new AndCondition( new PropertyCondition(AutomationElement.AutomationIdProperty, "1148"), new PropertyCondition(AutomationElement.ClassNameProperty, "Edit")); var filePicker = openFileDialog.FindDescendant(filePickerCondition); filePicker.LeftClick(); SendKeys.SendWait(xmlFIle.Name); var openButtonCondition = new AndCondition( new PropertyCondition(AutomationElement.NameProperty, "Open"), new PropertyCondition(AutomationElement.ClassNameProperty, "Button")); var openButton = openFileDialog.FindDescendant(openButtonCondition); openButton.LeftClick(); }
public static string GetChromeUrl(Process proc) { if (proc.MainWindowHandle == IntPtr.Zero) { return(null); } AutomationElement element = AutomationElement.FromHandle(proc.MainWindowHandle); if (element == null) { return(null); } Condition conditions = new AndCondition( new PropertyCondition(AutomationElement.ProcessIdProperty, proc.Id), new PropertyCondition(AutomationElement.IsControlElementProperty, true), new PropertyCondition(AutomationElement.IsContentElementProperty, true), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)); AutomationElement elementx = element.FindFirst(TreeScope.Descendants, conditions); var url = ((ValuePattern)elementx.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string; return(url); }
public void NullBoostIsIgnored() { var condition = new AndCondition(new[] { new TestCondition("TEST") }); Assert.That(condition.Boost, Is.Null); Assert.That(!condition.Options.Any()); }
/// <summary> /// 在root下通过UI元素名,类名搜素,返回一个AutomationElement对象 /// </summary> /// <param name="_name">UI元素名</param> /// <param name="_className">类名</param> /// <returns></returns> public AutomationElement SearchWindowsByName(string _name, string _className) { try { var exeUiElement = root.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NativeWindowHandleProperty, exeHandle)); //var exeUiElement = root.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "大智慧")); if (exeUiElement != null) { var conditions = new AndCondition(new PropertyCondition(AutomationElement.NameProperty, _name), new PropertyCondition(AutomationElement.ClassNameProperty, _className)); var chridUiElement = exeUiElement.FindFirst(TreeScope.Subtree, conditions); if (chridUiElement != null) { return(chridUiElement); } else { return(null); } } else { return(null); } } catch { return(null); } }
/// <summary> /// Find dialog by dialog title and dialog message. /// </summary> /// <param name="processID">The ProcessId</param> /// <param name="dialogTitle">The dialog title</param> /// <param name="dialogMessage">The dialog message</param> /// <param name="timeout">Time out.</param> /// <returns>If find the target dialog, return this dialog, or return the null instance</returns> public static AutomationElement FindDialog(int processID, string dialogTitle, string dialogMessage, int timeout) { AndCondition condition = new AndCondition(new Condition[] { new PropertyCondition(AutomationElement.NameProperty, dialogMessage), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text) }); DateTime time = DateTime.Now.AddMilliseconds((double)timeout); bool flag = false; while (!flag || (DateTime.Now <= time)) { if (DateTime.Now > time) { flag = true; } Thread.Sleep(200); foreach (AutomationElement element in FindWindows(AutomationElement.RootElement, processID, dialogTitle) ) { if (element.FindFirst(TreeScope.Children, condition) != null) { return(element); } } } return(null); }
public void FieldIsAddedToDefinition() { var condition = new AndCondition(new[] { new TestCondition("TEST") }, "testfield"); var definition = condition.Definition; Assert.That(definition, Is.EqualTo("(and field=testfield TEST)")); }
// </SnippetGetTableElement> // <Snippet100> ///-------------------------------------------------------------------- /// <summary> /// Finds all automation elements that satisfy /// the specified condition(s). /// </summary> /// <param name="targetApp"> /// The automation element from which to start searching. /// </param> /// <returns> /// A collection of automation elements satisfying /// the specified condition(s). /// </returns> ///-------------------------------------------------------------------- private AutomationElementCollection FindAutomationElement( AutomationElement targetApp) { if (targetApp == null) { throw new ArgumentException("Root element cannot be null."); } PropertyCondition conditionSupportsTablePattern = new PropertyCondition( AutomationElement.IsTablePatternAvailableProperty, true); PropertyCondition conditionIndeterminateTraversal = new PropertyCondition( TablePattern.RowOrColumnMajorProperty, RowOrColumnMajor.Indeterminate); PropertyCondition conditionRowColumnTraversal = new PropertyCondition( TablePattern.RowOrColumnMajorProperty, RowOrColumnMajor.ColumnMajor); AndCondition conditionTable = new AndCondition( conditionSupportsTablePattern, new OrCondition( conditionIndeterminateTraversal, conditionRowColumnTraversal)); return(targetApp.FindAll( TreeScope.Descendants, conditionTable)); }
}//AppFormHandle() private void ExcuteButtonInvoke(string automationId) { Condition conditions = new AndCondition( new PropertyCondition(AutomationElement.NameProperty, automationId), new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button)); if (calWindow == null) { return; } PropertyCondition Condition = new PropertyCondition(AutomationElement.NameProperty, automationId); AutomationElement btn = calWindow.FindFirst(TreeScope.Descendants, Condition); if (btn == null) { return; } MouseLeftClick(btn, 1); //if (btn != null) //{ // InvokePattern invokeptn = (InvokePattern)btn.GetCurrentPattern(InvokePattern.Pattern); // invokeptn.Invoke(); //} Thread.Sleep(1000); }
/// <summary> /// Sign in office with right account /// </summary> /// <param name="userName">username used to sign in</param> /// <param name="Password">Password for the relative username</param> public static void OfficeSignIn(string userName, string Password) { var desktop = AutomationElement.RootElement; AutomationElement documentFormat = WaitForElement(desktop, new PropertyCondition(AutomationElement.NameProperty, "Word"), TreeScope.Children, true); Thread.Sleep(1000); AutomationElement windowsSecurityDialog = documentFormat.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Windows Security")); PropertyCondition username_edit = new PropertyCondition(AutomationElement.NameProperty, "User name"); AutomationElement item_username = windowsSecurityDialog.FindFirst(TreeScope.Descendants, username_edit); ValuePattern Pattern_username = (ValuePattern)item_username.GetCurrentPattern(ValuePattern.Pattern); item_username.SetFocus(); Pattern_username.SetValue(userName); Condition password_edit = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit), new PropertyCondition(AutomationElement.NameProperty, "Password")); AutomationElement item_password = windowsSecurityDialog.FindFirst(TreeScope.Descendants, password_edit); ValuePattern Pattern_password = (ValuePattern)item_password.GetCurrentPattern(ValuePattern.Pattern); item_password.SetFocus(); Pattern_password.SetValue(Password); Condition OK_button = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "OK")); AutomationElement item_OK = windowsSecurityDialog.FindFirst(TreeScope.Descendants, OK_button); InvokePattern Pattern_OK = (InvokePattern)item_OK.GetCurrentPattern(InvokePattern.Pattern); Pattern_OK.Invoke(); }
public void Test_3() { var condition2 = new SqlCondition("Age>@Age"); var condition = new AndCondition(null, condition2); Assert.Equal("Age>@Age", condition.GetCondition()); }
public static bool MeetCondition(string softwareName, string applicationName, SpecificConfig entity) { bool Apply(Condition condition, Func <bool> isMeet) => condition.Excluding ? !isMeet() : isMeet(); bool CheckConditions(IEnumerable <Condition> conditions, bool isOr) { bool Predicate(Condition c) => c switch { AppCondition app => Apply(c, () => softwareName == app.AppName), InstalledAppCondition installedApp => Apply(c, () => applicationName == installedApp.AppName), AndCondition andCondition => Apply(c, () => CheckConditions(andCondition.Conditions, false)), OrCondition orCondition => Apply(c, () => CheckConditions(orCondition.Conditions, true)), _ => false }; return(isOr ? conditions.OrderBy(c => c.Order).Any(Predicate) : conditions.OrderBy(c => c.Order).All(Predicate)); } return(entity.Conditions.IsEmpty || CheckConditions(entity.Conditions, false)); } }
/// <summary> /// Check out a document on opening word /// </summary> /// <param name="name">Document name</param> public static void CheckOutOnOpeningWord(string name) { AutomationElement docOnline = GetWordOnlineWindow(name); Condition File_Tab = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "File Tab")); WaitForElement(docOnline, File_Tab, TreeScope.Descendants); AutomationElement item_File = docOnline.FindFirst(TreeScope.Descendants, File_Tab); InvokePattern Pattern_File = (InvokePattern)item_File.GetCurrentPattern(InvokePattern.Pattern); Pattern_File.Invoke(); Condition Group_Info = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Group), new PropertyCondition(AutomationElement.NameProperty, "Info")); AutomationElement item_Info = docOnline.FindFirst(TreeScope.Descendants, Group_Info); Condition Con_ManageVersions = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem), new PropertyCondition(AutomationElement.NameProperty, "Manage Document")); AutomationElement item_ManageVersions = item_Info.FindFirst(TreeScope.Descendants, Con_ManageVersions); ExpandCollapsePattern Pattern_ManageVersions = (ExpandCollapsePattern)item_ManageVersions.GetCurrentPattern(ExpandCollapsePatternIdentifiers.Pattern); Pattern_ManageVersions.Expand(); Condition Con_CheckOut = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem), new PropertyCondition(AutomationElement.NameProperty, "Check Out")); AutomationElement item_CheckOut = item_Info.FindFirst(TreeScope.Descendants, Con_CheckOut); InvokePattern Pattern_CheckOut = (InvokePattern)item_CheckOut.GetCurrentPattern(InvokePattern.Pattern); Pattern_CheckOut.Invoke(); Thread.Sleep(8000); Condition File_Save = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Save")); AutomationElement item_Save = docOnline.FindFirst(TreeScope.Descendants, File_Save); InvokePattern Pattern_Save = (InvokePattern)item_Save.GetCurrentPattern(InvokePattern.Pattern); Pattern_Save.Invoke(); Thread.Sleep(2000); }
public void NegateAndCondition(bool?first, bool?other, bool?third, bool?expected) { var fake1 = new Fake { IsTrueOrNull = first }; using (var condition1 = new Condition(fake1.ObservePropertyChanged(x => x.IsTrueOrNull), () => fake1.IsTrueOrNull)) { var fake2 = new Fake { IsTrueOrNull = other }; using (var condition2 = new Condition(fake2.ObservePropertyChanged(x => x.IsTrueOrNull), () => fake2.IsTrueOrNull)) { var fake3 = new Fake { IsTrueOrNull = third }; using (var condition3 = new Condition(fake3.ObservePropertyChanged(x => x.IsTrueOrNull), () => fake3.IsTrueOrNull)) { using (var andCondition = new AndCondition(condition1, condition2, condition3)) { using (var negated = new Negated <Condition>(andCondition)) { Assert.AreEqual(expected, negated.IsSatisfied); } } } } } }
/// <summary> /// Close microsoft word dialog /// </summary> /// <param name="filename">file name</param> /// <param name="Accept">A string value specifies the value of accept button in dialog</param> public static void CloseMicrosoftWordDialog(string filename, string Accept) { var desktop = AutomationElement.RootElement; Condition orCondition = new OrCondition(new PropertyCondition(AutomationElement.NameProperty, filename + " - Word"), new PropertyCondition(AutomationElement.NameProperty, filename + ".docx - Word")); Condition Con_Document = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window), orCondition); //AutomationElement item_Document = WaitForWindow(desktop, Con_Document, TreeScope.Children); AutomationElement item_Document = desktop.FindFirst(TreeScope.Children, Con_Document); Condition Con_Acc = null; AutomationElement item_Acc = null; if (Accept == "OK") { Thread.Sleep(2000); Condition Con_Word = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane), new PropertyCondition(AutomationElement.NameProperty, "Microsoft Word")); AutomationElement item_Word = WaitForElement(item_Document, Con_Word, TreeScope.Children, false); if (item_Word != null) { Con_Acc = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "OK")); item_Acc = item_Word.FindFirst(TreeScope.Descendants, Con_Acc); } } else if (Accept == "Yes") { Condition Con_Word = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window), new PropertyCondition(AutomationElement.NameProperty, "Microsoft Word")); AutomationElement item_Word = WaitForElement(item_Document, Con_Word, TreeScope.Children, true); Con_Acc = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Yes")); item_Acc = item_Word.FindFirst(TreeScope.Descendants, Con_Acc); } if (item_Acc != null) { InvokePattern Pattern_Yes = (InvokePattern)item_Acc.GetCurrentPattern(InvokePattern.Pattern); Pattern_Yes.Invoke(); } }
public void UIAutoEnterValueIntoOpenDialog(string value) { ICapabilities capabilities = ((RemoteWebDriver)WebContext.WebDriver).Capabilities; AutomationElement window = null; if (capabilities.BrowserName.ToLower().Contains("chrome")) { window = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "SIMS - Google Chrome")); } else { window = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "SIMS - Internet Explorer")); } if (window != null) { // Find Open dialog Condition condition = new AndCondition( new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "edit"), new PropertyCondition(AutomationElement.NameProperty, "File name:")); var FileFieldName = window.FindFirst(TreeScope.Descendants, condition); FileFieldName.SetFocus(); ValuePattern valuePatternA = FileFieldName.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern; valuePatternA.SetValue(value); SendKeys.SendWait("{Enter}"); } }
// <Snippet100> ///-------------------------------------------------------------------- /// <summary> /// Finds all automation elements that satisfy /// the specified condition(s). /// </summary> /// <param name="rootElement"> /// The automation element from which to start searching. /// </param> /// <returns> /// A collection of automation elements satisfying /// the specified condition(s). /// </returns> ///-------------------------------------------------------------------- private AutomationElementCollection FindAutomationElement( AutomationElement rootElement) { if (rootElement == null) { throw new ArgumentException("Root element cannot be null."); } PropertyCondition conditionCanMove = new PropertyCondition(TransformPattern.CanMoveProperty, false); PropertyCondition conditionCanResize = new PropertyCondition(TransformPattern.CanResizeProperty, true); PropertyCondition conditionCanRotate = new PropertyCondition(TransformPattern.CanRotateProperty, true); // Use any combination of the preceding condtions to // find the control(s) of interest Condition condition = new AndCondition( conditionCanRotate, conditionCanMove, conditionCanResize); return(rootElement.FindAll(TreeScope.Descendants, condition)); }
public void BoostIsAddedToDefinition() { var condition = new AndCondition(new[] { new TestCondition("TEST") }, boost: 8); var definition = condition.Definition; Assert.That(definition, Is.EqualTo("(and boost=8 TEST)")); }
public void BoostIsAddedToOptions() { var condition = new AndCondition(new[] { new TestCondition("TEST") }, boost: 984); var option = condition.Options.Single(); Assert.That(option, Is.Not.Null); Assert.That(option.Name, Is.EqualTo("boost")); Assert.That(option.Value, Is.EqualTo("984")); }
public void FieldIsAddedToOptions() { var condition = new AndCondition(new[] { new TestCondition("TEST") }, "testfield"); var option = condition.Options.Single(); Assert.That(option, Is.Not.Null); Assert.That(option.Name, Is.EqualTo("field")); Assert.That(option.Value, Is.EqualTo("testfield")); }
public void ManyTermsAreWrapped() { var condition = new AndCondition(new[] { new TestCondition("(omg)"), new TestCondition("(its (a) (test))"), new TestCondition("ZUBB") }); var definition = condition.Definition; Assert.That(definition, Is.EqualTo("(and (omg) (its (a) (test)) ZUBB)")); }
public static AutomationElement FindDesantantsBy(this AutomationElement e, string automationId, ControlType type) { Condition c = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, type), new PropertyCondition(AutomationElement.AutomationIdProperty, automationId)); return e.FindDescendantsBy(c); }
public static AutomationElement FindChildByName(this AutomationElement e, string name, ControlType type) { Condition c = new AndCondition(new PropertyCondition(AutomationElement.NameProperty, name), new PropertyCondition(AutomationElement.ControlTypeProperty, type)); return e.FindChildBy(c); }
/// <summary> /// Gets the children of this control in this technology matching the given condition. /// </summary> /// <param name="condition">The condition to match.</param> /// <returns>The enumerator for children.</returns> internal override System.Collections.IEnumerator GetChildren(AndCondition condition) { int row = 0, column = 0; string rowString = condition.GetPropertyValue(PropertyNames.RowIndex) as string; string columnString = condition.GetPropertyValue(PropertyNames.ColumnIndex) as string; if (int.TryParse(rowString, out row) && int.TryParse(columnString, out column)) { UITechnologyElement cellElement = this.technologyManager.GetExcelElement(this.WindowHandle, new ExcelCellInfo(row, column, this.WorksheetInfo)); return new UITechnologyElement[] { cellElement }.GetEnumerator(); } return null; }
/// <summary> /// Gets the children of this control in this technology matching the given condition. /// </summary> /// <param name="condition">The condition to match.</param> /// <returns>The enumerator for children.</returns> internal override System.Collections.IEnumerator GetChildren(AndCondition condition) { // Cell has no child. return null; }
/// <summary> /// Gets the children of this control in this technology matching the given condition. /// </summary> /// <param name="condition">The condition to match.</param> /// <returns>The enumerator for children.</returns> internal virtual System.Collections.IEnumerator GetChildren(AndCondition condition) { string sheetName = condition.GetPropertyValue(PropertyNames.Name) as string; if (!string.IsNullOrEmpty(sheetName)) { UITechnologyElement sheetElement = this.technologyManager.GetExcelElement(this.WindowHandle, new ExcelWorksheetInfo(sheetName)); return new UITechnologyElement[] { sheetElement }.GetEnumerator(); } return null; }
public void OneTermIsNotWrapped() { var condition = new AndCondition(new[] { new TestCondition("TEST") }); var definition = condition.Definition; Assert.That(definition, Is.EqualTo("TEST")); }
void Operation(out ConditionalExpression expression) { expression = null; if (la.kind == 13) { Get(); expression = new AndCondition(); } else if (la.kind == 14) { Get(); expression = new OrCondition(); } else SynErr(55); }
public void OneTermWithOptionIsWrapped() { var condition = new AndCondition(new[] { new TestCondition("TEST") }, "somefield"); var definition = condition.Definition; Assert.That(definition, Is.EqualTo("(and field=somefield TEST)")); }