/// <summary> /// Creates a list of <see cref="By"/> locators based on the attributes of this member. /// </summary> /// <param name="member">The <see cref="MemberInfo"/> containing information about /// the member of the Page Object class.</param> /// <returns>A list of <see cref="By"/> locators based on the attributes of this member.</returns> protected static ReadOnlyCollection <By> CreateLocatorList(MemberInfo member) { if (member == null) { throw new ArgumentNullException("member", "memeber cannot be null"); } var useSequenceAttributes = Attribute.GetCustomAttributes(member, typeof(FindsBySequenceAttribute), true); bool useSequence = useSequenceAttributes.Length > 0; var useFindAllAttributes = Attribute.GetCustomAttributes(member, typeof(FindsByAllAttribute), true); bool useAll = useFindAllAttributes.Length > 0; if (useSequence && useAll) { throw new ArgumentException("Cannot specify FindsBySequence and FindsByAll on the same member"); } List <By> bys = new List <By>(); var attributes = Attribute.GetCustomAttributes(member, typeof(FindsByAttribute), true); if (attributes.Length > 0) { Array.Sort(attributes); foreach (var attribute in attributes) { var castedAttribute = (FindsByAttribute)attribute; if (castedAttribute.Using == null) { castedAttribute.Using = member.Name; } bys.Add(CreateByInstance(castedAttribute)); } if (useSequence) { ByChained chained = new ByChained(bys.ToArray()); bys.Clear(); bys.Add(chained); } if (useAll) { ByAll all = new ByAll(bys.ToArray()); bys.Clear(); bys.Add(all); } } return(bys.AsReadOnly()); }
// // Static Methods // protected static ReadOnlyCollection <By> CreateLocatorList(MemberInfo member) { if (member == null) { throw new ArgumentNullException("member", "memeber cannot be null"); } Attribute[] customAttributes = Attribute.GetCustomAttributes(member, typeof(FindsBySequenceAttribute), true); bool flag = customAttributes.Length > 0; Attribute[] customAttributes2 = Attribute.GetCustomAttributes(member, typeof(FindsByAllAttribute), true); bool flag2 = customAttributes2.Length > 0; if (flag && flag2) { throw new ArgumentException("Cannot specify FindsBySequence and FindsByAll on the same member"); } List <By> list = new List <By> (); Attribute[] customAttributes3 = Attribute.GetCustomAttributes(member, typeof(FindsByAttribute), true); if (customAttributes3.Length > 0) { Array.Sort <Attribute> (customAttributes3); Attribute[] array = customAttributes3; for (int i = 0; i < array.Length; i++) { Attribute attribute = array [i]; FindsByAttribute findsByAttribute = (FindsByAttribute)attribute; if (findsByAttribute.Using == null) { findsByAttribute.Using = member.Name; } list.Add(findsByAttribute.Finder); } if (flag) { ByChained item = new ByChained(list.ToArray()); list.Clear(); list.Add(item); } if (flag2) { ByAll item2 = new ByAll(list.ToArray()); list.Clear(); list.Add(item2); } } return(list.AsReadOnly()); }
private static List <By> GetListOfComplexBys(bool useSequence, bool useAll, List <By> bys) { if (useSequence) { ByChained chained = new ByChained(bys.ToArray()); bys.Clear(); bys.Add(chained); } if (useAll) { ByAll all = new ByAll(bys.ToArray()); bys.Clear(); bys.Add(all); } return(bys); }
/// <summary> /// 获取下一步处理人员信息 /// </summary> /// <param name="doubleWay"></param> /// <returns></returns> private IEnumerable <WorkflowEngineReceiveUserOutput> GetWorkflowEngineTaskNextReceiveUser(WorkflowEngineNextActivitysDoubleWay doubleWay) { ReceiveUserFactory receiveUserFactory = new ByUser(); switch (doubleWay.ProcessorType) { case EnumActivityProcessorType.岗位: receiveUserFactory = new ByPost(); break; case EnumActivityProcessorType.工作组: receiveUserFactory = new ByGroup(); break; case EnumActivityProcessorType.所有成员: receiveUserFactory = new ByAll(); break; case EnumActivityProcessorType.部门: receiveUserFactory = new ByOrganization(); break; } return(receiveUserFactory.GetWorkflowEngineReceiveUserOutputs(doubleWay)); }
public static object FindElement(IAutomationEngineInstance engine, IWebDriver seleniumInstance, List <string[]> searchParameterRows, string searchOption, int timeout) { var wait = new WebDriverWait(seleniumInstance, new TimeSpan(0, 0, timeout)); object element; List <By> byList = new List <By>(); By by; foreach (var row in searchParameterRows) { string parameter = row[2].ToString().ConvertUserVariableToString(engine); switch (row[1].ToString()) { case string a when a.ToLower().Contains("xpath"): by = By.XPath(parameter); break; case string a when a.ToLower().Contains("id"): by = By.Id(parameter); break; case string a when a.ToLower().Contains("tag name"): by = By.TagName(parameter); break; case string a when a.ToLower().Contains("class name"): by = By.ClassName(parameter); break; case string a when a.ToLower().Contains("name"): by = By.Name(parameter); break; case string a when a.ToLower().Contains("css selector"): by = By.CssSelector(parameter); break; case string a when a.ToLower().Contains("link text"): by = By.LinkText(parameter); break; default: throw new Exception("Element Search Type was not found: " + row[1].ToString()); } byList.Add(by); } var byall = new ByAll(byList.ToArray()); bool elementFound; if (searchOption == "Find Element") { try { elementFound = wait.Until(condition => { try { if (engine.IsCancellationPending) { throw new Exception("Element search cancelled"); } var elementToBeDisplayed = seleniumInstance.FindElement(byall); return(elementToBeDisplayed.Displayed); } catch (StaleElementReferenceException) { return(false); } catch (NoSuchElementException) { return(false); } }); } catch (Exception) { //element not found during wait period return(null); } element = seleniumInstance.FindElement(byall); } else { try { elementFound = wait.Until(condition => { try { var elementsToBeDisplayed = seleniumInstance.FindElements(byall); return(elementsToBeDisplayed.First().Displayed); } catch (StaleElementReferenceException) { return(false); } catch (NoSuchElementException) { return(false); } }); } catch (Exception) { //elements not found during wait period return(null); } element = seleniumInstance.FindElements(byall); } return(element); }