Esempio n. 1
0
        internal static T Get <T>(AppModel model, string conditionString) where T : UIAControlBase, new()
        {
            UIACondition condition = UIACondition.GetCondition(model, conditionString);
            T            control   = new T();

            ((UIAControlBase)control).SetCondition(condition);
            return(control);
        }
Esempio n. 2
0
        //use this to create the condition by Repository
        public UIACondition(ITestObject testObject, UIACondition parentCondition)
        {
            //testObject.Parent = parentCondition.TestObject;
//            _parentCondition = parentCondition;

            if (parentCondition != null)
            {
                testObject.Parent = parentCondition.TestObject;
            }
            testObject.SetContext(this);
            Init(testObject);
        }
Esempio n. 3
0
        public static UIACondition GetCondition(UIACondition parentCondition, ControlType controlType, params string[] conditionStrings)
        {
            UIATestObject testObject = GetTO(parentCondition.TestObject, controlType, conditionStrings);

            //UIACondition currentCondition = parentCondition.CheckUIAConditionExists(testObject, controlType);

            //TODO, handle more conditionStrings
            return(UIACondition.GetCondition(testObject));

            //if (currentCondition != null)
            //    return currentCondition;

            //return GetCondition(parentCondition, testObject, controlType);
        }
 public static UIAControlBase ObjectCreator(UIACondition condition)
 {
     if (condition.UIAObject == null)
     {
         string typeString = "LPUIAObjects.UIA" + condition.ControlType.ControlTypeToString();
         Type   type       = Type.GetType(typeString);
         if (type == null)
         {
             throw new InvalidOperationException(string.Format("type {0} cannot be created", typeString));
         }
         condition.UIAObject = (UIAControlBase)Activator.CreateInstance(type, condition);
     }
     return((UIAControlBase)condition.UIAObject);
 }
Esempio n. 5
0
        public static bool CheckObjectExist(UIACondition condition)
        {
            _Logger.WriteLog("Check if the objest is exist in the Object list.");

            bool found = false;

            for (int i = 0; i <= 3; i++)
            {
                if (found == true)
                {
                    return(found);
                }
                else
                {
                    try
                    {
                        if (condition.AutomationElement == null)
                        {
                            found = false;
                        }
                        Rect value = condition.AutomationElement.Current.BoundingRectangle;
                        if (value.Right == 0 && value.Left == 0 && value.Top == 0 && value.Bottom == 0)
                        {
                            found = false;
                        }
                        else
                        {
                            found = true;
                        }
                    }
                    catch
                    {
                        found = false;
                    }
                }
                if (!found)
                {
                    Console.WriteLine("This object is not exist and find it again: " + condition.TestObject);
                    //search it again
                    UIACondition c = GetCondition(condition.ParentCondition, condition.TestObject, condition.ControlType);
                    if (c.AutomationElement != null)
                    {
                        condition = c;
                        found     = true;
                    }
                }
            }
            return(found);
        }
Esempio n. 6
0
        public void ControlSearcher_GetCondition()
        {
            AppModel.Initialize("UnitTestObjectModel1.json");
            UIATestObject parentObject = (UIATestObject)AppModel.Current.GetTestObject("LAP (Running) - Microsoft Visual Studio");

            //UIATestObject testObject = (UIATestObject)parentObject.FindRecursive(DescriptorKeys.NodeName, "Search");

            Assert.IsNotNull(parentObject, "Should find the parent test object in the model");

            UIACondition parentCondition = UIACondition.GetCondition(parentObject);

            UIACondition childCondition = ControlSearcher.GetCondition(parentCondition, ControlType.Edit, "Search");

            Assert.IsNotNull(childCondition, "Should not be able to find the child condition");
        }
Esempio n. 7
0
        public static UIACondition GetCondition(ITestObject testObject)
        {
            if (testObject == null)
            {
                return(null);
            }

            UIACondition condition = testObject.GetContext <UIACondition>();

            if (condition == null)
            {
                condition = new UIACondition(testObject);
            }
            return(condition);
        }
Esempio n. 8
0
        public static UIACondition GetCondition(UIACondition parentCondition, ITestObject testObject, ControlType controlType)
        {
            string        controlName             = "";
            UIATestObject beforeAnalyzeConditions = (UIATestObject)testObject;

            //TODO find the xmlname

            /*
             * string[] splitcondtion = conditions.Split(new string[] { DescriptionString.PropertySplitString }, StringSplitOptions.None);
             *
             * foreach (string c in splitcondtion)
             * {
             *  if (!c.Contains(DescriptionString.AssignOperator))
             *  {
             *      xmlname = c;
             *      break;
             *  }
             * }*/

            if (controlName != "")
            {
                throw new NotImplementedException();
                //testObject = UIAJsonPersister.LoadData(controlName, parentCondition.TestObject);
            }

            UIACondition selfCondition = new UIACondition(beforeAnalyzeConditions, parentCondition);

            AutomationElement element = null;

            element = FindAutomationElement(selfCondition);

            if (element != null)
            {
                selfCondition.AutomationElement = element;
                selfCondition.ParentCondition.AddChild(selfCondition);
            }
            else
            {
                _Logger.WriteWarning("Object no found:" + controlType.ToString() + " ,Condition:" + testObject);
            }
            return(selfCondition);
        }
Esempio n. 9
0
        private static AutomationElement LeftRightCheck(UIACondition selfCondition, AutomationElement leftExpected,
                                                        AutomationElement rightExpected, ref int sameCount, AutomationElement element)
        {
            // if the same count is big than 0, will return the object.
            sameCount = 0;
            if (rightExpected != null)
            {
                AutomationElement rightElement = UIAUtility.GetNextElement(element);
                if (UIAUtility.AreEqual2(rightExpected, rightElement))
                {
                    sameCount++;
                }
            }
            if (leftExpected != null)
            {
                AutomationElement leftElement = UIAUtility.GetPreviousElement(element);
                if (UIAUtility.AreEqual2(leftExpected, leftElement))
                {
                    sameCount++;
                }
            }

            return(null);
        }
Esempio n. 10
0
 public UIATree(UIACondition condition)
     : base(condition)
 {
 }
Esempio n. 11
0
        public static AutomationElement FindAutomationElement(UIACondition selfCondition)
        {
            // no longer used

            /*
             * AutomationElement leftElement = null, rightElement = null;
             * //check if the left or right condtion exist
             * //get the left and right element
             * if (selfCondition.Right != "")
             * {
             *  ITestObject rightTO;
             *
             *  if (selfCondition.Right.IndexOf(DescriptionString.LeftRightQtpString) >= 0)
             *  {
             *      //format Right==something
             *      rightTO = UIAHelper.ConvertStringToTestObject(selfCondition.Right);
             *  }
             *  else
             *  {
             *      //selfCondition.Right is the name, then use the name to extract descriptor
             *      rightTO = UIAJsonPersister.LoadData(selfCondition.Right, selfCondition.ParentCondition.TestObject);
             *  }
             *
             *  UIACondition rightCondition = new UIACondition(rightTO);
             *
             *  rightCondition.ParentCondition = selfCondition.ParentCondition;
             *  rightElement = FindAutomationElement(rightCondition);
             * }
             *
             * if (selfCondition.Left != "")
             * {
             *  ITestObject leftDescriptor = null;
             *  if (selfCondition.Left.IndexOf(DescriptionString.LeftRightQtpString) >= 0)
             *  {
             *      leftDescriptor = UIAHelper.ConvertStringToTestObject(selfCondition.Left);
             *  }
             *  else
             *  {
             *      leftDescriptor = UIAJsonPersister.LoadData(selfCondition.Left, selfCondition.ParentCondition.TestObject);
             *  }
             *  UIACondition leftCondition = new UIACondition(leftDescriptor);
             *  leftCondition.ParentCondition = selfCondition.ParentCondition;
             *  leftElement = FindAutomationElement(leftCondition);
             * }
             *
             *
             * AutomationElementCollection matchedElements = null;
             * Logger.WriteLog("Start to find the UIAObject by condition");
             *
             * if (selfCondition.Condition != null)
             * {
             *  Retry3Times(() => {
             *      matchedElements = UIAUtility.FindDescendantElements(selfCondition.ParentCondition.AutomationElement, selfCondition.Condition);
             *      return matchedElements.Count > 0;
             *  });
             * }
             * else
             * {
             *  Retry3Times(() =>
             *  {
             *      matchedElements = UIAUtility.FindDescendantElements(selfCondition.ParentCondition.AutomationElement, TreeWalker.ControlViewWalker.Condition);
             *      return matchedElements.Count > 0;
             *  });
             * }
             *
             * if (matchedElements.Count == 0)
             * {
             *  Logger.WriteWarning("Can not find child in the parent container:" + selfCondition.ControlName);
             *  return null;
             * }
             * else
             * {
             *  Logger.WriteDebug("Objects Count:" + matchedElements.Count);
             * }
             *
             * //if using index only, return the object
             * if (selfCondition.IsIndexOnly)
             * {
             *  if (matchedElements.Count - 1 < selfCondition.Index)
             *  {
             *      return null;
             *  }
             *  else
             *  {
             *      Highlight.HighlightThread(matchedElements[selfCondition.Index]);
             *      selfCondition.AutomationElement = matchedElements[selfCondition.Index];
             *      return selfCondition.AutomationElement;
             *  }
             * }
             *
             * int matchIndex = 0;
             *
             * //check all of the element which match the type condition and attached text
             * foreach (AutomationElement element in matchedElements)
             * {
             *  // if window, just check the caption, 60% match will be recognized.
             *  if (selfCondition.IsWindow)
             *  {
             *      string caption = element.Current.Name;
             *      if (Utility.StringSimiliarityCompare(selfCondition.Text, caption, 50))
             *      {
             *          if (selfCondition.Index == matchIndex)
             *          {
             *              Highlight.HighlightThread(element);
             *              selfCondition.AutomationElement = element;
             *              return selfCondition.AutomationElement;
             *          }
             *          else
             *          {
             *              matchIndex++;
             *          }
             *      }
             *  }
             *  // if object, will check the left and right element.
             *  else
             *  {
             *      int sameCount = 0;
             *      LeftRightCheck(selfCondition, leftElement, rightElement, ref sameCount, element);
             *
             *
             *      // object match 80% will be return.
             *      if (selfCondition.Text != "")
             *      {
             *          string aName = "";
             *          try
             *          {
             *              aName = ((TextPattern)element.GetCurrentPattern(TextPattern.Pattern)).DocumentRange.GetText(-1);
             *          }
             *          catch { }
             *
             *          try
             *          {
             *              aName = ((ValuePattern)element.GetCurrentPattern(ValuePattern.Pattern)).Current.Value;
             *          }
             *          catch { }
             *
             *          try
             *          {
             *
             *              aName = (string)element.GetCurrentPropertyValue(LegacyIAccessiblePattern.ValueProperty);
             *          }
             *          catch { }
             *
             *          if (aName == null || aName == "")
             *          {
             *              aName = element.Current.Name;
             *          }
             *          if (aName != "")
             *          {
             *              if (Utility.StringSimiliarityCompare(selfCondition.Text, aName, 80))
             *              {
             *                  sameCount++;
             *              }
             *          }
             *      }
             *
             *      //find object by attached text;
             *      if (selfCondition.AttachedText != "")
             *      {
             *          AutomationElement attachedElement = (AutomationElement)element.Current.LabeledBy;
             *          if (attachedElement != null)
             *          {
             *              string labelName = attachedElement.Current.Name;
             *              if (selfCondition.AttachedText == labelName)
             *              {
             *                  sameCount++;
             *              }
             *          }
             *      }
             *
             *      // if count number bigger than 2, will return the object
             *      if ((sameCount / selfCondition.ConditionCount) >= 0.5)
             *      {
             *          if (selfCondition.Index == matchIndex)
             *          {
             *              Highlight.HighlightThread(element);
             *              selfCondition.AutomationElement = element;
             *              return selfCondition.AutomationElement;
             *          }
             *          else
             *          {
             *              matchIndex++;
             *          }
             *      }
             *  }
             * }
             */
            return(null);
        }
Esempio n. 12
0
 public UIAScrollBar(UIACondition condition)
     : base(condition)
 {
 }
Esempio n. 13
0
 public UIACheckbox(UIACondition condition)
     : base(condition)
 {
 }
Esempio n. 14
0
 public UIAEdit(UIACondition condition)
     : base(condition)
 {
 }
Esempio n. 15
0
 public UIAText(UIACondition condition)
     : base(condition)
 {
 }
Esempio n. 16
0
 public void AddChild(UIACondition childCondition)
 {
     //_childConditions.Add(childCondition);
     this.TestObject.AddChild(childCondition.TestObject);
 }
Esempio n. 17
0
 public UIAList(UIACondition condition)
     : base(condition)
 {
 }
Esempio n. 18
0
        static ILogger _Logger = LogFactory.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);//"LPReplayCore.UIA.UIAFinder");


        public UIAControlBase(string conditionString)
        {
            _condition = new UIACondition(conditionString);
        }
Esempio n. 19
0
 public UIAToolBar(UIACondition condition)
     : base(condition)
 {
 }
Esempio n. 20
0
 public UIARadioButton(UIACondition condition)
     : base(condition)
 {
 }
Esempio n. 21
0
 public UIAComboBox(UIACondition condition)
     : base(condition)
 {
 }
Esempio n. 22
0
 public UIASlider(UIACondition condition)
     : base(condition)
 {
 }
Esempio n. 23
0
 public UIAControlBase(UIACondition condition)
 {
     _condition = condition;
 }
Esempio n. 24
0
 internal void SetCondition(UIACondition condition)
 {
     _condition = condition;
 }
Esempio n. 25
0
        public IUIAScrollBar UIAScrollbar(string conditions, string conditions1 = "", string conditions2 = "", string conditions3 = "", string conditions4 = "", string conditions5 = "", string conditions6 = "", string conditions7 = "", string conditions8 = "", string conditions9 = "")
        {
            UIACondition cdition = ControlSearcher.GetCondition(this._condition, ControlType.ScrollBar, conditions, conditions1, conditions2, conditions3, conditions4, conditions5, conditions6, conditions7, conditions8, conditions9);

            return((UIAScrollBar)UIACommonMethods.ObjectCreator(cdition));
        }
Esempio n. 26
0
 public UIAWindow(UIACondition condition)
     : base(condition)
 {
 }
Esempio n. 27
0
 public UIAMenu(UIACondition condition)
     : base(condition)
 {
 }
Esempio n. 28
0
 public UIAContainerBase(UIACondition condition)
     : base(condition)
 {
 }
Esempio n. 29
0
        public IUIALink UIALink(string conditions, string conditions1 = "", string conditions2 = "", string conditions3 = "", string conditions4 = "", string conditions5 = "", string conditions6 = "", string conditions7 = "", string conditions8 = "", string conditions9 = "")
        {
            UIACondition cdition = ControlSearcher.GetCondition(_condition, ControlType.Hyperlink, conditions, conditions1, conditions2, conditions3, conditions4, conditions5, conditions6, conditions7, conditions8, conditions9);

            return((UIALink)UIACommonMethods.ObjectCreator(cdition));
        }
Esempio n. 30
0
        public IUIARadioButton UIARadiobutton(string conditions, string conditions1 = "", string conditions2 = "", string conditions3 = "", string conditions4 = "", string conditions5 = "", string conditions6 = "", string conditions7 = "", string conditions8 = "", string conditions9 = "")
        {
            UIACondition cdition = ControlSearcher.GetCondition(this._condition, ControlType.RadioButton, conditions, conditions1, conditions2, conditions3, conditions4, conditions5, conditions6, conditions7, conditions8, conditions9);

            return((UIARadioButton)UIACommonMethods.ObjectCreator(cdition));
        }