//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); }
//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); }
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); }
public virtual IVisible AnyObject(TestProperty[] properties) { return AnyObjects(properties)[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; }
public virtual IInputable[] TextBoxs(TestProperty[] properties) { GetMapObjects(TestObjectType.TextBox, properties); IInputable[] tmp = new IInputable[_lastObjects.Length]; _lastObjects.CopyTo(tmp, 0); return tmp; }
public virtual ITable[] Tables(TestProperty[] properties) { GetMapObjects(TestObjectType.Table, properties); ITable[] tmp = new ITable[_lastObjects.Length]; _lastObjects.CopyTo(tmp, 0); return tmp; }
public virtual ICheckable[] RadioBoxs(TestProperty[] properties) { GetMapObjects(TestObjectType.RadioBox, properties); ICheckable[] tmp = new ICheckable[_lastObjects.Length]; _lastObjects.CopyTo(tmp, 0); return tmp; }
public virtual ISelectable[] ListBoxs(TestProperty[] properties) { GetMapObjects(TestObjectType.ListBox, properties); ISelectable[] tmp = new ISelectable[_lastObjects.Length]; _lastObjects.CopyTo(tmp, 0); return tmp; }
public bool IsValueMatch(TestProperty other) { return this._value == other._value && this._isRegex == other._isRegex; }
public virtual IClickable Button(TestProperty[] properties) { return Buttons(properties)[0]; }
public virtual IVisible[] AnyObjects(string type, TestProperty[] properties) { GetMapObjects(type, properties); IVisible[] tmp = new IVisible[_lastObjects.Length]; _lastObjects.CopyTo(tmp, 0); return tmp; }
public bool IsValueMatch(TestProperty other) { return(this._value == other._value && this._isRegex == other._isRegex); }
//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; }
public virtual ICheckable CheckBox(TestProperty[] propertiese) { return CheckBoxs(propertiese)[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; }
public virtual ISelectable DropList(TestProperty[] properties) { return DropLists(properties)[0]; }
public bool IsNameMatch(TestProperty other) { return(String.Compare(this._name, other._name, true) == 0); }
public virtual IPicture Image(TestProperty[] properties) { return Images(properties)[0]; }
public virtual ICheckable RadioBox(TestProperty[] properties) { return RadioBoxs(properties)[0]; }
public virtual IPicture[] Images(TestProperty[] properties) { GetMapObjects(TestObjectType.Image, properties); IPicture[] tmp = new IPicture[_lastObjects.Length]; _lastObjects.CopyTo(tmp, 0); return tmp; }
public virtual ITable Table(TestProperty[] properties) { return Tables(properties)[0]; }
public virtual bool IsExist(TestProperty[] properties) { TestObject[] tmps; return TryGetObjects(null, properties, out tmps); }
public virtual IInputable TextBox(TestProperty[] properties) { return TextBoxs(properties)[0]; }
public virtual bool IsExist(String type, TestProperty[] properties) { TestObject[] tmps; return TryGetObjects(type, properties, out tmps); }
public virtual bool TryGetObjects(String type, TestProperty[] properties, out TestObject[] objects) { objects = null; try { objects = GetMapObjects(type, properties); return objects != null; } catch { return false; } }
public virtual IText Label(TestProperty[] properties) { return Labels(properties)[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; } }
public virtual IText[] Labels(TestProperty[] properties) { GetMapObjects(TestObjectType.Label, properties); IText[] tmp = new IText[_lastObjects.Length]; _lastObjects.CopyTo(tmp, 0); return tmp; }
public virtual IVisible AnyObject(string type, TestProperty[] properties) { return AnyObjects(type, properties)[0]; }
public virtual IClickable Link(TestProperty[] properties) { return Links(properties)[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; }
public virtual IClickable[] Links(TestProperty[] properties) { GetMapObjects(TestObjectType.Link, properties); IClickable[] tmp = new IClickable[_lastObjects.Length]; _lastObjects.CopyTo(tmp, 0); return tmp; }
public bool IsNameMatch(TestProperty other) { return String.Compare(this._name, other._name, true) == 0; }
public virtual ISelectable ListBox(TestProperty[] properties) { return ListBoxs(properties)[0]; }
protected virtual TestObject[] GetMapObjects(string type, String description) { TestProperty[] properties = TestProperty.GetProperties(description); return GetMapObjects(type, properties); }
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); }