Exemple #1
0
        /// <summary>
        /// Glimpse one gui-path and return the result. If the expected value is not found,
        /// an assertion is raised.
        /// </summary>
        /// <param name="ah">Context accessibility helper, taken as the starting place for gpath.</param>
        /// <param name="gpath">The path through the GUI to the control.</param>
        /// <param name="expect">The expected value of the property for the control.</param>
        /// <returns></returns>
        bool GlimpsePath(AccessibilityHelper ah, GuiPath gpath, string expect)
        {
            m_Result = true;
            m_got    = null;
            IPathVisitor visitor = null;

            ah       = gpath.FindInGui(ah, visitor);
            m_Result = GlimpseGUI(ah, expect);
            if (m_Result)
            {
                base.Finished = true;                       // teminates do-once
            }
            if ((m_onPass == "assert" && m_Result == true) ||
                (m_onFail == "assert" && m_Result == false))
            {
                if (m_message != null && m_message.HasContent())
                {
                    fail(m_message.Read());
                }
                else
                {
                    string image = "Property [" + m_prop + "] was [" + m_got + "] expecting [" + m_expect + "] Result = '" + m_Result + "', on-pass='******', on-fail='" + m_onFail + "'";
                    if (gpath != null)
                    {
                        fail(image + " on gPath = " + gpath.toString());
                    }
                    else
                    {
                        fail(image);
                    }
                }
            }
            return(m_Result);
        }
Exemple #2
0
 private string ClickPath(AccessibilityHelper ah, GuiPath gpath)
 {
     //bool forAll = false;
     //bool clickParent = false;
     //AccessibilityHelper child;
     //if (m_for != null && "all" == (string)m_for) forAll = true;
     if (1 == m_logLevel)
     {
         m_log.paragraph(makeNameTag() + "Click starting path from &quot;" + ah.Role + ":" + ah.Name + "&quot;");
     }
     ah = gpath.FindInGui(ah, this);
     if (ah != null)
     {
         if (1 == m_logLevel)
         {
             m_log.paragraph(makeNameTag() + "Clicking last pair in path");
         }
         int j;
         for (j = 0; j < m_repeat; j++)
         {                  // click 10 pixels from the left edge - see below
             if (m_side == "right")
             {
                 ah.SimulateRightClickRelative(m_dx, m_dy);
             }
             else
             {
                 ah.SimulateClickRelative(m_dx, m_dy);
             }
             // when @wait="no" don't wait at all between repeated clicks
             if (m_wait)
             {
                 Thread.Sleep(400);                             // wait a while eg. let menus open, etc.
             }
         }
         m_finished = true;                 // tell do-once it's done
     }
     else
     {
         return(m_message);
     }
     return("");
 }
Exemple #3
0
        public override void Execute()
        {
            base.Execute();
            bool exists = false;

            isNotNull(m_path, "attribute 'path' must be set");
            m_path = Utilities.evalExpr(m_path);
            GuiPath gpath = new GuiPath(m_path);

            isNotNull(gpath, "attribute path='" + m_path + "' not parsed");
            GuiPath lpath = null;

            if (m_loc != null)             // if it's null, get the whole string content
            {
                lpath = new GuiPath(m_loc);
                isNotNull(lpath, "attribute path='" + m_loc + "' not parsed");
            }
            Context con = (Context)Ancestor(typeof(Context));

            isNotNull(con, "Select-text must occur in some context");
            AccessibilityHelper ah = con.Accessibility;

            isNotNull(ah, "Select-text context not accessible");
            // The model names are needed in selectText.
            IPathVisitor visitor = null;

            ah = gpath.FindInGui(ah, visitor);
            isNotNull(ah, "context not accessible from path");
            if (ah != null)
            {
                if (m_loc == null)
                {
                    exists = getStrValue(ah);
                }
                else
                {
                    exists = selectText(lpath, ah);
                }
            }
            Logger.getOnly().result(this);
            Finished = true;             // tell do-once it's done
        }
Exemple #4
0
        public void findInGui()
        {
            Process             m_proc = Process.Start(@"C:\WINDOWS\NOTEPAD.EXE");
            AccessibilityHelper m_ah;

            m_proc.WaitForInputIdle();
            while (Process.GetProcessById(m_proc.Id).MainWindowHandle == IntPtr.Zero)
            {
                Thread.Sleep(100);
            }
            m_proc.WaitForInputIdle();

            SIL.FieldWorks.Common.Utils.

            Win32.SetForegroundWindow(m_proc.MainWindowHandle);
            m_ah = new AccessibilityHelper(m_proc.MainWindowHandle);

            AccessibilityHelper ah    = null;
            GuiPath             gpath = new GuiPath("menu:Help/menu:Help Topics");

            ah = gpath.FindInGui(m_ah, null);
            Assert.IsNotNull(ah, "'menu:Help/menu:Help Topics' Accessibility Helper not found");
            Assert.AreEqual("Help Topics", ah.Name, "'menu:Help/menu:Help Topics' menu item not found");
            Assert.AreEqual(AccessibleRole.MenuItem, ah.Role, "'menu:Help/menu:Help Topics' menu item role not found");
            try
            {
                m_proc.WaitForInputIdle();
                Win32.SetForegroundWindow(m_proc.MainWindowHandle);
                SendKeys.SendWait("%{F4}");
                m_proc.WaitForInputIdle();
                m_proc.WaitForExit();
            }
            catch
            {
            }
        }
Exemple #5
0
 private string ClickPath(AccessibilityHelper ah, GuiPath gpath)
 {
     //bool forAll = false;
     //bool clickParent = false;
     //AccessibilityHelper child;
     //if (m_for != null && "all" == (string)m_for) forAll = true;
     if (1 == m_logLevel)
         m_log.paragraph(makeNameTag() + "Click starting path from &quot;" + ah.Role + ":" + ah.Name + "&quot;");
     ah = gpath.FindInGui(ah, this);
     if (ah != null)
     {
         if (1 == m_logLevel) m_log.paragraph(makeNameTag() + "Clicking last pair in path");
         int j;
         for (j = 0; j < m_repeat; j++)
         {  // click 10 pixels from the left edge - see below
             if (m_side == "right")
                 ah.SimulateRightClickRelative(m_dx, m_dy);
             else
                 ah.SimulateClickRelative(m_dx, m_dy);
             // when @wait="no" don't wait at all between repeated clicks
             if (m_wait) Thread.Sleep(400); // wait a while eg. let menus open, etc.
         }
         m_finished = true; // tell do-once it's done
     }
     else return m_message;
     return "";
 }
Exemple #6
0
 public override void Execute()
 {
     base.Execute();
     bool exists = false;
     m_log.isNotNull(m_path, "attribute 'path' must be set");
     m_path = Utilities.evalExpr(m_path);
     GuiPath gpath = new GuiPath(m_path);
     m_log.isNotNull(gpath, "attribute path='" + m_path + "' not parsed");
     GuiPath lpath = null;
     if (m_loc != null) // if it's null, get the whole string content
     {
         lpath = new GuiPath(m_loc);
         m_log.isNotNull(lpath, "attribute path='" + m_loc + "' not parsed");
     }
     Context con = (Context)Ancestor(typeof(Context));
     m_log.isNotNull(con, "Select-text must occur in some context");
     AccessibilityHelper ah = con.Accessibility;
     m_log.isNotNull(ah, "Select-text context not accessible");
     // The model names are needed in selectText.
     IPathVisitor visitor = null;
     ah = gpath.FindInGui(ah, visitor);
     m_log.isNotNull(ah, "context not accessible from path");
     if (ah != null)
     {
         exists = getStrValue(ah);
         /**
         if (m_loc == null) exists = getStrValue(ah);
         else               exists = selectText(lpath, ah);
         **/
     }
     Logger.getOnly().result(this);
     Finished = true; // tell do-once it's done
 }
Exemple #7
0
		string HoverPath(AccessibilityHelper ah, GuiPath gpath)
		{
			ah = gpath.FindInGui(ah, this);
			visitNode(ah);
			return m_message;
		}
Exemple #8
0
 string HoverPath(AccessibilityHelper ah, GuiPath gpath)
 {
     ah = gpath.FindInGui(ah, this);
     visitNode(ah);
     return(m_message);
 }
Exemple #9
0
        // When used in a do-once instruction, this call is repeated.
        // Note the code that keeps m_select from being prepended to m_path more than once.
        public override void Execute()
        {
            base.Execute();
            if (m_path != null && m_path == "")
            {
                m_path = null;
            }
            if (m_select != null && m_select == "")
            {
                m_select = null;
            }
            if (m_selectPath != null && m_selectPath == "")
            {
                m_selectPath = null;
            }
            if (m_names != null && m_names == "")
            {
                m_names = null;
            }
            // must have:
            // one of select or names to provide a list to check against
            // with names, one of path or selectPath to get the place to check in the GUI
            m_log.isTrue(m_select != null || m_names != null, makeNameTag() + " must have a 'names' or 'select' attribute.");
            if (m_names != null)
            {
                m_log.isTrue(m_path != null || m_selectPath != null, makeNameTag() + " must have a 'path' or 'selectPath' attribute with 'names'.");
            }
            Context con = (Context)Ancestor(typeof(Context));

            m_log.isNotNull(con, makeNameTag() + " must occur in some context");
            m_path       = Utilities.evalExpr(m_path);
            m_selectPath = Utilities.evalExpr(m_selectPath);
            m_select     = Utilities.evalExpr(m_select);
            // set the gui path from path or select
            if (m_select != null && !m_doneOnce)
            {              // set m_names and possibly m_path
                m_log.paragraph(makeNameTag() + " creating selection targets via " + m_select);
                XmlNodeList pathNodes = Instructionator.selectNodes(con, m_select, makeNameTag());
                m_log.isNotNull(pathNodes, makeNameTag() + " select='" + m_select + "' returned no model node");
                // The @select text may have selected a string that is itself xPath!
                // If so, select on that xPath
                if (pathNodes.Count == 1 && pathNodes.Item(0).NodeType == XmlNodeType.Text)
                {                 // this text node should be an xpath statement
                    string xPathImage = pathNodes.Item(0).Value;
                    m_log.paragraph(makeNameTag() + " selected a text node with more XPATH: " + xPathImage);
                    pathNodes = Instructionator.selectNodes(con, xPathImage, makeNameTag() + " selecting " + xPathImage);
                    m_log.isNotNull(pathNodes, makeNameTag() + " selecting " + xPathImage + " from select='" + m_select + "' returned no model node");
                }
                if (pathNodes.Count >= 1)
                {                 // there are some nodes - make a list
                    m_names = null;
                    foreach (XmlNode xname in pathNodes)
                    {
                        if (m_names == null)
                        {
                            if (m_path == null)
                            {
                                XmlPath xPath = new XmlPath(xname.ParentNode);
                                m_path = xPath.Path;
                            }
                        }
                        else
                        {
                            m_names += "/";
                        }
                        string name = XmlFiler.getAttribute(xname, "name");
                        if (name == null || name == "")
                        {
                            m_names += "#NONE";
                        }
                        else
                        {
                            m_names += name;
                        }
                    }
                }
                m_doneOnce = true;                 // avoid adding to m_path again on subsequent do-once iterations
            }
            if (m_selectPath != null && m_selectPath != "")
            {
                XmlPath node = SelectToPath(con, m_selectPath);                 // process m_select
                m_path = node.Path + m_path;
            }

            GuiPath gpath = new GuiPath(m_path);

            m_log.isNotNull(gpath, makeNameTag() + " attribute path='" + m_path + "' not parsed");
            if (m_names != null)
            {
                m_list = Utilities.ParsePath(m_names);
            }
            PassFailInContext(m_onPass, m_onFail, out m_onPass, out m_onFail);
            AccessibilityHelper ah = con.Accessibility;

            m_log.isNotNull(ah, makeNameTag() + " context not accessible");
            //check to see if it is visible
            m_Result = false;

            try { Application.Process.WaitForInputIdle(); }
            catch (Win32Exception e)
            { m_log.paragraph(makeNameTag() + " WaitForInputIdle: " + e.Message);
              m_Result = false; }

            if (m_Result)
            {
                ah = gpath.FindInGui(ah, null);
            }
            if (ah != null)
            {
                m_Result = GlimpseGUI(ah);
            }
            Finished = true;             // tell do-once it's done

            if ((m_onPass == "assert" && m_Result == true) ||
                (m_onFail == "assert" && m_Result == false))
            {
                if (m_message != null)
                {
                    m_log.fail(m_message.Read());
                }
                else
                {
                    m_log.fail(makeNameTag() + " Result = '" + m_Result + "', on-pass='******', on-fail='" + m_onFail + "'");
                }
            }
            Logger.getOnly().result(this);
        }
Exemple #10
0
		public void findInGui()
		{
			Process m_proc = Process.Start(@"C:\WINDOWS\NOTEPAD.EXE");
			AccessibilityHelper m_ah;
			m_proc.WaitForInputIdle();
			while (Process.GetProcessById(m_proc.Id).MainWindowHandle == IntPtr.Zero)
				Thread.Sleep(100);
			m_proc.WaitForInputIdle();

			 SIL.FieldWorks.Common.Utils.

			Win32.SetForegroundWindow(m_proc.MainWindowHandle);
			m_ah = new AccessibilityHelper(m_proc.MainWindowHandle);

			AccessibilityHelper ah = null;
			GuiPath gpath = new GuiPath("menu:Help/menu:Help Topics");
			ah = gpath.FindInGui(m_ah, null);
			Assert.IsNotNull(ah,"'menu:Help/menu:Help Topics' Accessibility Helper not found");
			Assert.AreEqual("Help Topics",ah.Name,"'menu:Help/menu:Help Topics' menu item not found");
			Assert.AreEqual(AccessibleRole.MenuItem,ah.Role,"'menu:Help/menu:Help Topics' menu item role not found");
			try
			{
				m_proc.WaitForInputIdle();
				Win32.SetForegroundWindow(m_proc.MainWindowHandle);
				SendKeys.SendWait("%{F4}");
				m_proc.WaitForInputIdle();
				m_proc.WaitForExit();
			}
			catch
			{
			}
		}
Exemple #11
0
		// When used in a do-once instruction, this call is repeated.
		// Note the code that keeps m_select from being prepended to m_path more than once.
		public override void Execute()
		{
			base.Execute();
			if (m_path   != null && m_path   == "") m_path   = null;
			if (m_select != null && m_select == "") m_select = null;
			if (m_selectPath != null && m_selectPath == "") m_selectPath = null;
			if (m_names != null && m_names == "") m_names = null;
			// must have:
			// one of select or names to provide a list to check against
			// with names, one of path or selectPath to get the place to check in the GUI
			isTrue(m_select != null || m_names != null, makeNameTag() + " must have a 'names' or 'select' attribute.");
			if (m_names != null)
				isTrue(m_path != null || m_selectPath != null, makeNameTag() + " must have a 'path' or 'selectPath' attribute with 'names'.");
			Context con = (Context)Ancestor(typeof(Context));
			isNotNull(con, makeNameTag() + " must occur in some context");
			m_path = Utilities.evalExpr(m_path);
			m_selectPath = Utilities.evalExpr(m_selectPath);
			m_select = Utilities.evalExpr(m_select);
			// set the gui path from path or select
			if (m_select != null && !m_doneOnce)
			{  // set m_names and possibly m_path

				m_log.paragraph(makeNameTag() + " creating selection targets via " + m_select);
				XmlNodeList pathNodes = XmlInstructionBuilder.selectNodes(con, m_select, makeNameTag());
				isNotNull(pathNodes, makeNameTag() + " select='" + m_select + "' returned no model node");
				// The @select text may have selected a string that is itself xPath!
				// If so, select on that xPath
				if (pathNodes.Count == 1 && pathNodes.Item(0).NodeType == XmlNodeType.Text)
				{ // this text node should be an xpath statement
					string xPathImage = pathNodes.Item(0).Value;
					m_log.paragraph(makeNameTag() + " selected a text node with more XPATH: " + xPathImage);
					pathNodes = XmlInstructionBuilder.selectNodes(con, xPathImage, makeNameTag() + " selecting " + xPathImage);
					isNotNull(pathNodes, makeNameTag() + " selecting " + xPathImage + " from select='" + m_select + "' returned no model node");
				}
				if (pathNodes.Count >= 1)
				{ // there are some nodes - make a list
					m_names = null;
					foreach (XmlNode xname in pathNodes)
					{
						if (m_names == null)
						{
							if (m_path == null)
							{
								XmlPath xPath = new XmlPath(xname.ParentNode);
								m_path = xPath.Path;
							}
						}
						else m_names += "/";
						string name = XmlFiler.getAttribute(xname, "name");
						if (name == null || name == "") m_names += "#NONE";
						else m_names += name;
					}
				}
				m_doneOnce = true;
			}
			string sPath = "";
			if (m_selectPath != null && m_selectPath != "")
				sPath = SelectToPath(con, m_selectPath);
			m_path = sPath + m_path;
			GuiPath gpath = new GuiPath(m_path);
			isNotNull(gpath, makeNameTag() + " attribute path='" + m_path + "' not parsed");
			if (m_names != null) m_list = Utilities.ParsePath(m_names);
			PassFailInContext(m_onPass,m_onFail,out m_onPass,out m_onFail);
			AccessibilityHelper ah = con.Accessibility;
			isNotNull(ah, makeNameTag() + " context not accessible");
			//check to see if it is visible
			m_Result = false;
			ah = gpath.FindInGui(ah, null);
			if (ah != null) m_Result = GlimpseGUI(ah);
			Finished = true; // tell do-once it's done

			if ((m_onPass == "assert" && m_Result == true)
				||(m_onFail == "assert" && m_Result == false) )
			{
				if (m_message != null)
					fail(m_message.Read());
				else
					fail(makeNameTag() + " Result = '" + m_Result + "', on-pass='******', on-fail='" + m_onFail + "'");
			}
			Logger.getOnly().result(this);
		}
Exemple #12
0
		/// <summary>
		/// Glimpse one gui-path and return the result. If the expected value is not found,
		/// an assertion is raised.
		/// </summary>
		/// <param name="ah">Context accessibility helper, taken as the starting place for gpath.</param>
		/// <param name="gpath">The path through the GUI to the control.</param>
		/// <param name="expect">The expected value of the property for the control.</param>
		/// <returns></returns>
		bool GlimpsePath(AccessibilityHelper ah, GuiPath gpath, string expect)
		{
			m_Result = true;
			m_got = null;
			IPathVisitor visitor = null;
			ah = gpath.FindInGui(ah, visitor);
			m_Result = GlimpseGUI(ah, expect);
			if (m_Result) base.Finished = true; // teminates do-once
			if ((m_onPass == "assert" && m_Result == true)
				||(m_onFail == "assert" && m_Result == false) )
			{
				if (m_message != null && m_message.HasContent())
					fail(m_message.Read());
				else
				{
					string image = "Property [" + m_prop + "] was [" + m_got + "] expecting [" + m_expect + "] Result = '" + m_Result + "', on-pass='******', on-fail='" + m_onFail + "'";
					if (gpath != null)
						fail(image + " on gPath = " + gpath.toString());
					else
						fail(image);
				}
			}
			return m_Result;
		}