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));
		}
Example #2
0
		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;
			}
		}
Example #3
0
		public bool Select (AppResult result)
		{
			bool success = false;

			try {
				ExecuteOnIdle (() => {
					success = result.Select ();
				});
			} catch (TimeoutException e) {
				ThrowOperationTimeoutException ("Select", result.SourceQuery, result, e);
			}

			return success;
		}
Example #4
0
		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;
		}
Example #5
0
 public void Dispose()
 {
     rootNode?.Dispose();
     rootNode = null;
 }
Example #6
0
		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;
			}
		}
Example #7
0
		public void Flash (AppResult result)
		{
			try {
				ExecuteOnIdle (() => result.Flash (() => AutoTestService.NotifyEvent ("FlashCompleted")));
			} catch (TimeoutException e) {
				ThrowOperationTimeoutException ("Flash", result.SourceQuery, result, e);
			}
		}
Example #8
0
		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;
		}
Example #9
0
        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);
            }
        }
Example #10
0
        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));
 }
Example #14
0
		internal void Add (string propertyName, AppResult propertyValue, PropertyInfo propertyInfo)
		{
			propertyMap.Add (propertyName, propertyValue);
			propertyMetaData.Add (propertyName, new PropertyMetadata (propertyInfo));
		}
Example #15
0
		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;
		}
Example #16
0
		public bool EnterText (AppResult result, string text)
		{
			try {
				ExecuteOnIdle (() => result.EnterText (text));
			} catch (TimeoutException e) {
				ThrowOperationTimeoutException ("EnterText", result.SourceQuery, result, e);
			}

			return true;
		}
Example #17
0
 public bool Select(AppResult result)
 {
     return(result.Select());
 }
Example #18
0
		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;
		}
Example #19
0
 public bool Click(AppResult result)
 {
     return(result.Click());
 }
Example #20
0
		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);
		}
Example #21
0
 public bool Toggle(AppResult result, bool active)
 {
     return(result.Toggle(active));
 }
Example #22
0
		//
		// The XML result structure
		// <AutoTest>
		//   <query>c =&gt; 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;
		}
Example #23
0
		public void Flash (AppResult result)
		{
			try {
				ExecuteOnIdle (() => result.Flash ());
			} catch (TimeoutException e) {
				ThrowOperationTimeoutException ("Flash", result.SourceQuery, result, e);
			}
		}
Example #24
0
 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);
 }
Example #25
0
		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;
		}