예제 #1
0
        //parse string.
        //properties is splitted by ";"
        //eg: "id=btnG;name=google".
        public static TestProperty[] GetProperties(string str)
        {
            if (str != null && !String.IsNullOrEmpty(str.Trim()))
            {
                List <TestProperty> properties = new List <TestProperty>();
                int startIndex = 0;
                int endIndex   = 0;
                for (int i = 0; i < str.Length; i++)
                {
                    char c = str[i];
                    if (c == PropertySeparator || i == str.Length - 1)
                    {
                        if (!IsEscaped(str, i))
                        {
                            endIndex = (c == PropertySeparator ? i : i + 1);
                            string propertyStr   = str.Substring(startIndex, endIndex - startIndex);
                            int    nameEndPos    = 0;
                            int    valueStartPos = 0;
                            for (int j = 0; j < propertyStr.Length; j++)
                            {
                                if (propertyStr[j] == '=' && !IsEscaped(propertyStr, j))
                                {
                                    nameEndPos    = j;
                                    valueStartPos = j + 1;
                                    break;
                                }
                            }

                            string name  = propertyStr.Substring(0, nameEndPos).Trim();
                            string value = propertyStr.Substring(valueStartPos, propertyStr.Length - valueStartPos);
                            bool   isReg = false;
                            if (String.IsNullOrEmpty(name))
                            {
                                name = TestConstants.PROPERTY_VISIBLE;
                            }
                            else
                            {
                                if (name.StartsWith(RegFlag))
                                {
                                    name  = name.Remove(0, 1);
                                    isReg = name.StartsWith(RegFlag);
                                }
                            }

                            TestProperty p = new TestProperty(name, value, isReg);
                            properties.Add(p);

                            startIndex = endIndex + 1;
                        }
                    }
                }

                return(properties.ToArray());
            }

            return(null);
        }
예제 #2
0
        //compare wether the source list match the des condition.
        public static bool IsListMatch(List <TestProperty> source, List <TestProperty> des, bool needSort)
        {
            //test wether the other object's identify properties is the same with this object's identify properties.
            int totalWeight = 0;

            if (source != null && des != null && source.Count == des.Count)
            {
                //sort the list before compare.
                if (needSort)
                {
                    source.Sort();
                    des.Sort();
                }

                for (int i = 0; i < source.Count; i++)
                {
                    try
                    {
                        TestProperty thisPro  = source[i];
                        TestProperty otherPro = des[i];

                        //name not match, break, return false.
                        if (!thisPro.IsNameMatch(otherPro))
                        {
                            totalWeight -= thisPro.Weight;
                        }
                        else if (thisPro.IsValueMatch(otherPro))
                        {
                            totalWeight += thisPro.Weight;
                        }

                        if (thisPro.Weight == 100)
                        {
                            break;
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }
            }

            return(totalWeight > 0);
        }
예제 #3
0
        public int CompareTo(object obj)
        {
            if (obj != null && obj is TestProperty)
            {
                TestProperty other = (TestProperty)obj;
                //compare name
                if (String.Compare(this._name, other._name, true) != 0)
                {
                    return(String.Compare(this._name, other._name, true));
                }
                else
                {
                    String thisValue  = this._value.ToString();
                    String otherValue = other._value.ToString();

                    //compare value
                    if (String.Compare(thisValue, otherValue) != 0)
                    {
                        return(String.Compare(thisValue, otherValue));
                    }
                    else
                    {
                        //compare weight
                        if (this._weight != other._weight)
                        {
                            return(this._weight.CompareTo(other._weight));
                        }
                        else
                        {
                            //compare regex flag.
                            return(this._isRegex.CompareTo(other._isRegex));
                        }
                    }
                }
            }

            return(1);
        }
예제 #4
0
 public virtual IVisible AnyObject(TestProperty[] properties)
 {
     return AnyObjects(properties)[0];
 }
예제 #5
0
        protected virtual TestObject[] GetMapObjects(string type, TestProperty[] properties)
        {
            try
            {
                TestException exception = null;
                if (!TryGetObjectsFromPool(type, properties, out _lastObjects, out exception))
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (TestProperty tp in properties)
                    {
                        sb.Append("{" + tp.ToString() + "},");
                    }

                    throw new ObjectNotFoundException(String.Format("Can not get object {0} with error: {1} ", sb.ToString(), exception.ToString()));
                }
            }
            catch (TestException)
            {
                throw;
            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder();

                if (properties != null && properties.Length > 0)
                {
                    foreach (TestProperty tp in properties)
                    {
                        sb.Append("{" + tp.ToString() + "},");
                    }
                }

                throw new ObjectNotFoundException(String.Format("Can not get object {0} with error: {1} ", sb.ToString(), ex.ToString()));
            }

            return _lastObjects;
        }
예제 #6
0
 public virtual IInputable[] TextBoxs(TestProperty[] properties)
 {
     GetMapObjects(TestObjectType.TextBox, properties);
     IInputable[] tmp = new IInputable[_lastObjects.Length];
     _lastObjects.CopyTo(tmp, 0);
     return tmp;
 }
예제 #7
0
 public virtual ITable[] Tables(TestProperty[] properties)
 {
     GetMapObjects(TestObjectType.Table, properties);
     ITable[] tmp = new ITable[_lastObjects.Length];
     _lastObjects.CopyTo(tmp, 0);
     return tmp;
 }
예제 #8
0
 public virtual ICheckable[] RadioBoxs(TestProperty[] properties)
 {
     GetMapObjects(TestObjectType.RadioBox, properties);
     ICheckable[] tmp = new ICheckable[_lastObjects.Length];
     _lastObjects.CopyTo(tmp, 0);
     return tmp;
 }
예제 #9
0
 public virtual ISelectable[] ListBoxs(TestProperty[] properties)
 {
     GetMapObjects(TestObjectType.ListBox, properties);
     ISelectable[] tmp = new ISelectable[_lastObjects.Length];
     _lastObjects.CopyTo(tmp, 0);
     return tmp;
 }
예제 #10
0
 public bool IsValueMatch(TestProperty other)
 {
     return this._value == other._value && this._isRegex == other._isRegex;
 }
예제 #11
0
 public virtual IClickable Button(TestProperty[] properties)
 {
     return Buttons(properties)[0];
 }
예제 #12
0
 public virtual IVisible[] AnyObjects(string type, TestProperty[] properties)
 {
     GetMapObjects(type, properties);
     IVisible[] tmp = new IVisible[_lastObjects.Length];
     _lastObjects.CopyTo(tmp, 0);
     return tmp;
 }
예제 #13
0
 public bool IsValueMatch(TestProperty other)
 {
     return(this._value == other._value && this._isRegex == other._isRegex);
 }
예제 #14
0
        //parse string.
        //properties is splitted by ";"
        //eg: "id=btnG;name=google".
        public static TestProperty[] GetProperties(string str)
        {
            if (str != null && !String.IsNullOrEmpty(str.Trim()))
            {
                List<TestProperty> properties = new List<TestProperty>();
                int startIndex = 0;
                int endIndex = 0;
                for (int i = 0; i < str.Length; i++)
                {
                    char c = str[i];
                    if (c == PropertySeparator || i == str.Length - 1)
                    {
                        if (!IsEscaped(str, i))
                        {
                            endIndex = (c == PropertySeparator ? i : i + 1);
                            string propertyStr = str.Substring(startIndex, endIndex - startIndex);
                            int nameEndPos = 0;
                            int valueStartPos = 0;
                            for (int j = 0; j < propertyStr.Length; j++)
                            {
                                if (propertyStr[j] == '=' && !IsEscaped(propertyStr, j))
                                {
                                    nameEndPos = j;
                                    valueStartPos = j + 1;
                                    break;
                                }
                            }

                            string name = propertyStr.Substring(0, nameEndPos).Trim();
                            string value = propertyStr.Substring(valueStartPos, propertyStr.Length - valueStartPos);
                            bool isReg = false;
                            if (String.IsNullOrEmpty(name))
                            {
                                name = TestConstants.PROPERTY_VISIBLE;
                            }
                            else
                            {
                                if (name.StartsWith(RegFlag))
                                {
                                    name = name.Remove(0, 1);
                                    isReg = name.StartsWith(RegFlag);
                                }
                            }

                            TestProperty p = new TestProperty(name, value, isReg);
                            properties.Add(p);

                            startIndex = endIndex + 1;
                        }
                    }
                }

                return properties.ToArray();
            }

            return null;
        }
예제 #15
0
 public virtual ICheckable CheckBox(TestProperty[] propertiese)
 {
     return CheckBoxs(propertiese)[0];
 }
예제 #16
0
 public bool IsMatch(TestProperty other)
 {
     return String.Compare(this._name, other._name) == 0 && this._value == other._value &&
            this._isRegex == other._isRegex && this._weight == other._weight;
 }
예제 #17
0
 public virtual ISelectable DropList(TestProperty[] properties)
 {
     return DropLists(properties)[0];
 }
예제 #18
0
 public bool IsNameMatch(TestProperty other)
 {
     return(String.Compare(this._name, other._name, true) == 0);
 }
예제 #19
0
 public virtual IPicture Image(TestProperty[] properties)
 {
     return Images(properties)[0];
 }
예제 #20
0
 public virtual ICheckable RadioBox(TestProperty[] properties)
 {
     return RadioBoxs(properties)[0];
 }
예제 #21
0
 public virtual IPicture[] Images(TestProperty[] properties)
 {
     GetMapObjects(TestObjectType.Image, properties);
     IPicture[] tmp = new IPicture[_lastObjects.Length];
     _lastObjects.CopyTo(tmp, 0);
     return tmp;
 }
예제 #22
0
 public virtual ITable Table(TestProperty[] properties)
 {
     return Tables(properties)[0];
 }
예제 #23
0
 public virtual bool IsExist(TestProperty[] properties)
 {
     TestObject[] tmps;
     return TryGetObjects(null, properties, out tmps);
 }
예제 #24
0
 public virtual IInputable TextBox(TestProperty[] properties)
 {
     return TextBoxs(properties)[0];
 }
예제 #25
0
 public virtual bool IsExist(String type, TestProperty[] properties)
 {
     TestObject[] tmps;
     return TryGetObjects(type, properties, out tmps);
 }
예제 #26
0
 public virtual bool TryGetObjects(String type, TestProperty[] properties, out TestObject[] objects)
 {
     objects = null;
     try
     {
         objects = GetMapObjects(type, properties);
         return objects != null;
     }
     catch
     {
         return false;
     }
 }
예제 #27
0
 public virtual IText Label(TestProperty[] properties)
 {
     return Labels(properties)[0];
 }
예제 #28
0
        private bool TryGetObjectsFromPool(string type, TestProperty[] properties, out TestObject[] obj, out TestException exception)
        {
            obj = null;
            exception = null;

            int currentTimeout = _timeout;
            int oriTimeout = this._objPool.SearchTimeout;
            this._objPool.SearchTimeout = currentTimeout;

            try
            {
                if (String.IsNullOrEmpty(type))
                {
                    if (properties == null || properties.Length == 0)
                    {
                        obj = this._objPool.GetAllObjects();
                    }
                    else
                    {
                        obj = this._objPool.GetObjectsByProperties(properties);
                    }
                }
                else
                {
                    obj = this._objPool.GetObjectsByType(type, properties);
                }

                return obj != null;
            }
            catch (TestException ex)
            {
                exception = ex;
                return false;
            }
            finally
            {
                this._objPool.SearchTimeout = oriTimeout;
            }
        }
예제 #29
0
 public virtual IText[] Labels(TestProperty[] properties)
 {
     GetMapObjects(TestObjectType.Label, properties);
     IText[] tmp = new IText[_lastObjects.Length];
     _lastObjects.CopyTo(tmp, 0);
     return tmp;
 }
예제 #30
0
 public virtual IVisible AnyObject(string type, TestProperty[] properties)
 {
     return AnyObjects(type, properties)[0];
 }
예제 #31
0
 public virtual IClickable Link(TestProperty[] properties)
 {
     return Links(properties)[0];
 }
예제 #32
0
        public static bool TryGetProperties(string str, out TestProperty[] properties)
        {
            bool res = false;
            properties = null;
            if (str != null && !String.IsNullOrEmpty(str.Trim()) && str.IndexOf("=") > 0)
            {
                try
                {
                    properties = GetProperties(str);
                    return properties != null;
                }
                catch
                {
                    res = false;
                }
            }

            return res;
        }
예제 #33
0
 public virtual IClickable[] Links(TestProperty[] properties)
 {
     GetMapObjects(TestObjectType.Link, properties);
     IClickable[] tmp = new IClickable[_lastObjects.Length];
     _lastObjects.CopyTo(tmp, 0);
     return tmp;
 }
예제 #34
0
 public bool IsNameMatch(TestProperty other)
 {
     return String.Compare(this._name, other._name, true) == 0;
 }
예제 #35
0
 public virtual ISelectable ListBox(TestProperty[] properties)
 {
     return ListBoxs(properties)[0];
 }
예제 #36
0
 protected virtual TestObject[] GetMapObjects(string type, String description)
 {
     TestProperty[] properties = TestProperty.GetProperties(description);
     return GetMapObjects(type, properties);
 }
예제 #37
0
 public bool IsMatch(TestProperty other)
 {
     return(String.Compare(this._name, other._name) == 0 && this._value == other._value &&
            this._isRegex == other._isRegex && this._weight == other._weight);
 }