internal void Add (string propertyName, AppResult propertyValue, PropertyInfo propertyInfo) { if (!propertyMap.ContainsKey (propertyName)) propertyMap.Add (propertyName, propertyValue); if (!propertyMetaData.ContainsKey (propertyName)) propertyMetaData.Add (propertyName, new PropertyMetadata (propertyInfo)); }
void AddChildrenToList (List<AppResult> children, AppResult child, bool recursive = true) { AppResult node = child.FirstChild; children.Add (child); while (node != null) { if (recursive) AddChildrenToList (children, node); node = node.NextSibling; } }
public bool Select (AppResult result) { bool success = false; try { ExecuteOnIdle (() => { success = result.Select (); }); } catch (TimeoutException e) { ThrowOperationTimeoutException ("Select", result.SourceQuery, result, e); } return success; }
public AppResult[] Execute () { List<AppResult> resultSet = ResultSetFromWindows (); foreach (var subquery in operations) { // Some subqueries can select different results resultSet = subquery.Execute (resultSet); if (resultSet == null || resultSet.Count == 0) { return new AppResult[0]; } } AppResult[] results = new AppResult[resultSet.Count]; resultSet.CopyTo (results); return results; }
public void Dispose() { rootNode?.Dispose(); rootNode = null; }
void AddChildrenToDocument (XmlDocument document, XmlElement parentElement, AppResult children, bool withSiblings = true) { while (children != null) { XmlElement childElement = document.CreateElement ("result"); children.ToXml (childElement); parentElement.AppendChild (childElement); if (children.FirstChild != null) { AddChildrenToDocument (document, childElement, children.FirstChild); } children = withSiblings ? children.NextSibling : null; } }
public void Flash (AppResult result) { try { ExecuteOnIdle (() => result.Flash (() => AutoTestService.NotifyEvent ("FlashCompleted"))); } catch (TimeoutException e) { ThrowOperationTimeoutException ("Flash", result.SourceQuery, result, e); } }
public bool TypeKey (AppResult result, string keyString, string modifiers) { try { ExecuteOnIdle (() => result.TypeKey (keyString, modifiers)); } catch (TimeoutException e) { ThrowOperationTimeoutException ("TypeKey", result.SourceQuery, result, e); } return true; }
void ProcessNSWindow(NSWindow window, AppResult rootNode, ref AppResult lastChild) { // Don't process hidden windows. if (!includeHidden && !window.IsVisible) { return; } AppResult node = new NSObjectResult(window) { SourceQuery = sourceQuery }; AddToResultSet(node); AddChild(rootNode, node, ref lastChild); AppResult nsWindowLastNode = null; foreach (var child in window.ContentView.Subviews) { AppResult childNode = AddNSObjectResult(child); if (childNode == null) { continue; } AddChild(node, childNode, ref nsWindowLastNode); GenerateChildrenForNSView(childNode, child); } NSToolbar toolbar = window.Toolbar; if (toolbar == null) { return; } AppResult toolbarNode = new NSObjectResult(toolbar) { SourceQuery = sourceQuery }; // Was missing before too, maybe should be added to fullResultSet? AddChild(node, toolbarNode, ref nsWindowLastNode); if (toolbar == null) { return; } AppResult lastItemNode = null; foreach (var item in toolbar.Items) { AppResult itemNode = AddNSObjectResult(item.View); if (itemNode == null) { continue; } AddChild(toolbarNode, itemNode, ref lastItemNode); GenerateChildrenForNSView(itemNode, item.View); } }
List <AppResult> ResultSetFromWindows() { Gtk.Window[] windows = Gtk.Window.ListToplevels(); // null for AppResult signifies root node rootNode = new GtkWidgetResult(null) { SourceQuery = ToString() }; List <AppResult> fullResultSet = new List <AppResult> (); // Build the tree and full result set recursively AppResult lastChild = null; foreach (var window in windows) { AppResult node = new GtkWidgetResult(window) { SourceQuery = ToString() }; fullResultSet.Add(node); if (rootNode.FirstChild == null) { rootNode.FirstChild = node; lastChild = node; } else { // Add the new node into the chain lastChild.NextSibling = node; node.PreviousSibling = lastChild; lastChild = node; } // Create the children list and link them onto the node AppResult children = GenerateChildrenForContainer((Gtk.Container)window, fullResultSet); node.FirstChild = children; } #if MAC NSWindow[] nswindows = NSApplication.SharedApplication.Windows; if (nswindows != null) { foreach (var window in nswindows) { AppResult node = new NSObjectResult(window) { SourceQuery = ToString() }; AppResult nsWindowLastNode = null; fullResultSet.Add(node); if (rootNode.FirstChild == null) { rootNode.FirstChild = node; lastChild = node; } else { lastChild.NextSibling = node; node.PreviousSibling = lastChild; lastChild = node; } foreach (var child in window.ContentView.Subviews) { AppResult childNode = new NSObjectResult(child) { SourceQuery = ToString() }; fullResultSet.Add(childNode); if (node.FirstChild == null) { node.FirstChild = childNode; nsWindowLastNode = childNode; } else { nsWindowLastNode.NextSibling = childNode; childNode.PreviousSibling = nsWindowLastNode; nsWindowLastNode = childNode; } if (child.Subviews != null) { AppResult children = GenerateChildrenForNSView(child, fullResultSet); childNode.FirstChild = children; } } NSToolbar toolbar = window.Toolbar; AppResult toolbarNode = new NSObjectResult(toolbar) { SourceQuery = ToString() }; if (node.FirstChild == null) { node.FirstChild = toolbarNode; nsWindowLastNode = toolbarNode; } else { nsWindowLastNode.NextSibling = toolbarNode; toolbarNode.PreviousSibling = nsWindowLastNode; nsWindowLastNode = toolbarNode; } if (toolbar != null) { AppResult lastItemNode = null; foreach (var item in toolbar.Items) { if (item.View != null) { AppResult itemNode = new NSObjectResult(item.View) { SourceQuery = ToString() }; fullResultSet.Add(itemNode); if (toolbarNode.FirstChild == null) { toolbarNode.FirstChild = itemNode; lastItemNode = itemNode; } else { lastItemNode.NextSibling = itemNode; itemNode.PreviousSibling = lastItemNode; lastItemNode = itemNode; } if (item.View.Subviews != null) { AppResult children = GenerateChildrenForNSView(item.View, fullResultSet); itemNode.FirstChild = children; } } } } } } #endif return(fullResultSet); }
public bool SetActiveRuntime (AppResult result, string runtime) { bool success = false; try { ExecuteOnIdle (() => { success = result.SetActiveRuntime (runtime); }); } catch (TimeoutException e) { ThrowOperationTimeoutException ("SetActiveRuntime", result.SourceQuery, result, e); } return success; }
public void SetProperty (AppResult result, string name, object o) { try { ExecuteOnIdle (() => result.SetProperty (name, o)); } catch (TimeoutException e) { ThrowOperationTimeoutException ("SetProperty", result.SourceQuery, result, e); } }
internal void Add(string propertyName, AppResult propertyValue, PropertyInfo propertyInfo) { propertyMap.Add(propertyName, propertyValue); propertyMetaData.Add(propertyName, new PropertyMetadata(propertyInfo)); }
internal void Add (string propertyName, AppResult propertyValue, PropertyInfo propertyInfo) { propertyMap.Add (propertyName, propertyValue); propertyMetaData.Add (propertyName, new PropertyMetadata (propertyInfo)); }
public bool Click (AppResult result, bool wait = true) { bool success = false; try { ExecuteOnIdle (() => { success = result.Click (); }, wait); } catch (TimeoutException e) { ThrowOperationTimeoutException ("Click", result.SourceQuery, result, e); } return success; }
public bool EnterText (AppResult result, string text) { try { ExecuteOnIdle (() => result.EnterText (text)); } catch (TimeoutException e) { ThrowOperationTimeoutException ("EnterText", result.SourceQuery, result, e); } return true; }
public bool Select(AppResult result) { return(result.Select()); }
public bool Toggle (AppResult result, bool active) { bool success = false; try { ExecuteOnIdle (() => { success = result.Toggle (active); }); } catch (TimeoutException e) { ThrowOperationTimeoutException ("Toggle", result.SourceQuery, result, e); } return success; }
public bool Click(AppResult result) { return(result.Click()); }
void ThrowOperationTimeoutException (string operation, string query, AppResult result, Exception innerException) { throw new TimeoutException (string.Format ("Timeout while executing {0}: {1}\n\ton Element: {2}", operation, query, result), innerException); }
public bool Toggle(AppResult result, bool active) { return(result.Toggle(active)); }
// // The XML result structure // <AutoTest> // <query>c => c.Window()</query> // <results> // <result type="Gtk.Window" fulltype="Gtk.Window" name="Main Window" visible="true" sensitive="true" allocation="1,1 1024x1024"> // ... contains result elements for all children widgets ... // </result> // ... and more result element trees for each of the AppResult in results ... // </results> // </AutoTest> // public string ResultsAsXml (AppResult[] results) { XmlDocument document = new XmlDocument (); XmlElement rootElement = document.CreateElement ("AutoTest"); document.AppendChild (rootElement); if (results [0].SourceQuery != null) { XmlElement queryElement = document.CreateElement ("query"); queryElement.AppendChild (document.CreateTextNode (results [0].SourceQuery)); rootElement.AppendChild (queryElement); } XmlElement resultsElement = document.CreateElement ("results"); rootElement.AppendChild (resultsElement); try { ExecuteOnIdle (() => { foreach (var result in results) { AddChildrenToDocument (document, resultsElement, result, false); } }); } catch (TimeoutException e) { ThrowOperationTimeoutException ("ResultsAsXml", null, null, e); } string output; using (var sw = new UTF8StringWriter ()) { using (var xw = XmlWriter.Create (sw, new XmlWriterSettings { Indent = true })) { document.WriteTo (xw); } output = sw.ToString (); } return output; }
public void Flash (AppResult result) { try { ExecuteOnIdle (() => result.Flash ()); } catch (TimeoutException e) { ThrowOperationTimeoutException ("Flash", result.SourceQuery, result, e); } }
void ThrowOperationTimeoutException(string operation, string query, AppResult result, Exception innerException) { throw new TimeoutException(string.Format("Timeout while executing {0}: {1}\n\ton Element: {2}", operation, query, result), innerException); }
List<AppResult> ResultSetFromWindows () { Gtk.Window[] windows = Gtk.Window.ListToplevels (); // null for AppResult signifies root node rootNode = new GtkWidgetResult (null) { SourceQuery = ToString () }; List<AppResult> fullResultSet = new List<AppResult> (); // Build the tree and full result set recursively AppResult lastChild = null; foreach (var window in windows) { AppResult node = new GtkWidgetResult (window) { SourceQuery = ToString () }; fullResultSet.Add (node); if (rootNode.FirstChild == null) { rootNode.FirstChild = node; lastChild = node; } else { // Add the new node into the chain lastChild.NextSibling = node; node.PreviousSibling = lastChild; lastChild = node; } // Create the children list and link them onto the node AppResult children = GenerateChildrenForContainer ((Gtk.Container) window, fullResultSet); node.FirstChild = children; } #if MAC NSWindow[] nswindows = NSApplication.SharedApplication.Windows; if (nswindows != null) { foreach (var window in nswindows) { AppResult node = new NSObjectResult (window) { SourceQuery = ToString () }; AppResult nsWindowLastNode = null; fullResultSet.Add (node); if (rootNode.FirstChild == null) { rootNode.FirstChild = node; lastChild = node; } else { lastChild.NextSibling = node; node.PreviousSibling = lastChild; lastChild = node; } foreach (var child in window.ContentView.Subviews) { AppResult childNode = new NSObjectResult (child) { SourceQuery = ToString () }; fullResultSet.Add (childNode); if (node.FirstChild == null) { node.FirstChild = childNode; nsWindowLastNode = childNode; } else { nsWindowLastNode.NextSibling = childNode; childNode.PreviousSibling = nsWindowLastNode; nsWindowLastNode = childNode; } if (child.Subviews != null) { AppResult children = GenerateChildrenForNSView (child, fullResultSet); childNode.FirstChild = children; } } NSToolbar toolbar = window.Toolbar; AppResult toolbarNode = new NSObjectResult (toolbar) { SourceQuery = ToString () }; if (node.FirstChild == null) { node.FirstChild = toolbarNode; nsWindowLastNode = toolbarNode; } else { nsWindowLastNode.NextSibling = toolbarNode; toolbarNode.PreviousSibling = nsWindowLastNode; nsWindowLastNode = toolbarNode; } if (toolbar != null) { AppResult lastItemNode = null; foreach (var item in toolbar.Items) { if (item.View != null) { AppResult itemNode = new NSObjectResult (item.View) { SourceQuery = ToString () }; fullResultSet.Add (itemNode); if (toolbarNode.FirstChild == null) { toolbarNode.FirstChild = itemNode; lastItemNode = itemNode; } else { lastItemNode.NextSibling = itemNode; itemNode.PreviousSibling = lastItemNode; lastItemNode = itemNode; } if (item.View.Subviews != null) { AppResult children = GenerateChildrenForNSView (item.View, fullResultSet); itemNode.FirstChild = children; } } } } } } #endif return fullResultSet; }