/// <summary> /// Finds the first <see cref="IWebElement"/> within the current context using the given mechanism. /// </summary> /// <param name="e">This <see cref="IWebElement"/> under which to find the elements.</param> /// <param name="byFactory"><see cref="ByFactory"/> instance by which to create locator from <see cref="ActionRule"/></param> /// <param name="actionRule">Action rule by which to perform search and build conditions.</param> /// <returns>An <see cref="IWebElement"/> interface through which the user controls elements on the page.</returns> public static IWebElement GetElementByActionRule(this IWebElement e, ByFactory byFactory, ActionRule actionRule, TimeSpan timeout) { // on-element conditions var isOnElement = e != default && string.IsNullOrEmpty(actionRule.ElementToActOn); if (isOnElement) { return(e); } // get locator var by = byFactory.Get(actionRule.Locator, actionRule.ElementToActOn); // setup conditions var isAbsolutePath = actionRule.Locator == LocatorType.Xpath && actionRule.ElementToActOn.StartsWith("/"); // find on page level if (isAbsolutePath) { return(((IWrapsDriver)e).WrappedDriver.GetElement(by, timeout)); } // on element level return(e.FindElement(by)); }
// executes a child process with elements listener private void DoListener(ActionRule actionRule) { // get arguments ProcessArguments(actionRule.Argument); // setup var interval = (int)GetTimeSapnFromArgument(Interval).TotalMilliseconds; var expiration = (int)GetTimeSapnFromArgument(ListenerTimout).TotalMilliseconds; var by = ByFactory.Get(actionRule.Locator, actionRule.ElementToActOn); // publish action rule to execute on the found elements var childActionRule = new ActionRule { ActionType = arguments[ActionToPerform], Argument = childActionArgument, Actions = actionRule.Actions }; // execute listener var expire = 0; while (WebDriver != null && expire <= expiration) { // execute heartbeat DoListenerHeartbeat(childActionRule, by, interval); // set expiration time expire += interval; } }
private By CreateElementLocator(MemberInfo memberInfo) { var attributes = memberInfo.GetCustomAttributes(typeof(FindsByAttribute), true); if (attributes.Length == 0) { return(ByFactory.Create(How.Id, memberInfo.Name)); } if (attributes.Length > 1) { var errorBuilder = new StringBuilder(); errorBuilder.AppendFormat( "Multiple attributes [{0}] found on [{1}] which is member of [{2}] class.", typeof(FindsByAttribute), memberInfo.Name, memberInfo.DeclaringType); errorBuilder.AppendFormat( "Having multiple attribute for a single class member is not supported by [{0}].", this); throw new ArgumentException(errorBuilder.ToString(), "memberInfo"); } return(ByFactory.Create(attributes[0] as FindsByAttribute)); }
/// <summary> /// Finds the first <see cref="IWebElement"/> within the current context using the given mechanism. /// </summary> /// <param name="d">This <see cref="IWebDriver"/> under which to find the elements.</param> /// <param name="byFactory"><see cref="ByFactory"/> instance by which to create locator from <see cref="ActionRule"/></param> /// <param name="actionRule">Action rule by which to perform search and build conditions.</param> /// <param name="timeout">The timeout value indicating how long to wait for the condition (element exists).</param> /// <returns>An <see cref="IWebElement"/> interface through which the user controls elements on the page.</returns> /// <remarks>This method waits until the elements exists in the DOM.</remarks> public static IWebElement GetElementByActionRule(this IWebDriver d, ByFactory byFactory, ActionRule actionRule, TimeSpan timeout) { // get locator var by = byFactory.Get(actionRule.Locator, actionRule.ElementToActOn); // get elements return(d.GetElement(by, timeout)); }
/// <summary> /// Finds the first <see cref="IWebElement"/> within the current context using the given mechanism. /// </summary> /// <param name="d">This <see cref="IWebDriver"/> under which to find the elements.</param> /// <param name="byFactory"><see cref="ByFactory"/> instance by which to create locator from <see cref="ActionRule"/></param> /// <param name="actionRule">Action rule by which to perform search and build conditions.</param> /// <returns>An <see cref="IWebElement"/> interface through which the user controls elements on the page.</returns> public static IWebElement FindElementByActionRule(this IWebDriver d, ByFactory byFactory, ActionRule actionRule) { // get locator var by = byFactory.Get(actionRule.Locator, actionRule.ElementToActOn); // get elements return(d.FindElement(by)); }
public void ShouldCreateLocatorFromTypeAttribute() { Assert.That( ByFactory.Create(new ElementLocatorAttribute { How = How.Id, Using = "username" }), Is.EqualTo(By.Id("username")) ); }
public void ShouldCreateLocatorFromMemberAttribute() { Assert.That( ByFactory.Create(new FindsByAttribute { How = How.Id, Using = "username" }), Is.EqualTo(By.Id("username")) ); }
public static By GetByFor <T>(string element) { var propertyName = element; var type = typeof(T); var property = type.GetProperty(propertyName); var findsByAttributes = property.GetCustomAttributes(typeof(FindsByAttribute), inherit: false).Single() as FindsByAttribute; return(ByFactory.From(findsByAttributes)); }
public IdentityAttribute(params string[] identityStrings) { byIdentities = new By[identityStrings.Length]; for (int i = 0; i < identityStrings.Length; i++) { string identity = identityStrings[i]; int delimiterPos = identity.IndexOf(_IdentityDelimeter); String howStr = identity.Substring(0, delimiterPos); String usingStr = identity.Substring(delimiterPos + 1).TrimStart(); How how; if (Enum.TryParse(howStr, true, out how)) { byIdentities[i] = ByFactory.From(how, usingStr); } } }
public void ShouldThrowArgumentErrorWhenLocatorTypeIsNowKnown() { Assert.That(() => ByFactory.Create((How)13, "username"), Throws.ArgumentException); }
public By ShouldCreateLocator(How how, string locator) { return(ByFactory.Create(how, locator)); }
public OpenQA.Selenium.By GetBy(params string[] placeholders) { return(ByFactory.Get(byType, expression, placeholders)); }
/// <summary> /// Finds all <see cref="IWebElement"/> within the current context using the given mechanism. /// </summary> /// <param name="e">This <see cref="IWebElement"/> under which to find the elements.</param> /// <param name="byFactory"><see cref="ByFactory"/> instance by which to create locator from <see cref="ActionRule"/></param> /// <param name="actionRule">Action rule by which to perform search and build conditions.</param> /// <returns>A collection of all <see cref="IWebElement"/> matching the current criteria, or an empty list if nothing matches.</returns> public static ReadOnlyCollection <IWebElement> FindElementsByActionRule(this IWebElement e, ByFactory byFactory, ActionRule actionRule) { // on-element conditions var isOnElement = e != default && !string.IsNullOrEmpty(actionRule.ElementToActOn); if (isOnElement) { return(new ReadOnlyCollection <IWebElement>(new List <IWebElement> { e })); } // get locator var by = byFactory.Get(actionRule.Locator, actionRule.ElementToActOn); // setup conditions var isAbsolutePath = actionRule.Locator == LocatorType.Xpath && actionRule.ElementToActOn.StartsWith("/"); // find on page level if (isAbsolutePath) { return(((IWrapsDriver)e).WrappedDriver.FindElements(by)); } // on element level return(e.FindElements(by)); }