// factor a MockWebElement instance private static IWebElement Get(MockWebDriver parent, By by) { // get the 'by' value from this locator var byValue = GetLocatorValue(by); // get factoring method const BindingFlags flags = BindingFlags.Static | BindingFlags.Public; var method = typeof(MockWebElement).GetMethodByDescription(byValue, flags); // setup conditions var isMethod = method != default; var isWhiteList = !isMethod && parent.LocatorsWhiteList.Any(i => Regex.IsMatch(byValue, i)); // default if (isWhiteList) { return(new MockWebElement(parent)); } if (!isMethod) { throw new NoSuchElementException(); } // factor try { return(method?.GetParameters().Length == 1 ? (IWebElement)method.Invoke(null, new object[] { parent }) : (IWebElement)method?.Invoke(null, null)); } catch (Exception e) { throw e.InnerException ?? e; } }
public static IWebElement GetInvalidState(MockWebDriver parent) { // get a positive element var element = Positive(parent); // set element invalid state to true ((MockWebElement)element).IsInvalidState = true; // return invalid state element return(element); }
public static IWebElement GetFile(MockWebDriver parent) { // setup var onElement = new MockWebElement( parent, tagName: "INPUT", text: string.Empty, enabled: true, selected: false, displayed: true); // apply attribute data onElement.Attributes["type"] = "file"; // result return(onElement); }
/// <summary> /// Factor a collection of <see cref="MockWebElement"/> instances based on a given locator. /// </summary> /// <param name="parent">Driver in use.</param> /// <param name="by">The locating mechanism to use.</param> /// <returns>An interface through which the user controls elements on the page.</returns> public static ReadOnlyCollection <IWebElement> GetElements(MockWebDriver parent, By by) { // collect elements var elements = new List <IWebElement> { Get(parent, by), Get(parent, by) }; // return collection return(new ReadOnlyCollection <IWebElement>(elements.Where(i => i != null).ToList())); }
private static IWebElement RandomElement(MockWebDriver parent, int positiveRatio, Func <IWebElement> factory) { // get score var score = 0; lock (random) { score = random.Next(0, 100); } // factoring return((score <= positiveRatio) ? Positive(parent) : factory.Invoke()); }
// gets a random element (positive or negative). private static ReadOnlyCollection <IWebElement> RandomElements( MockWebDriver parent, int existsRatio, Func <ReadOnlyCollection <IWebElement> > factory) { // get score var score = 0; lock (random) { score = random.Next(0, 100); } // factoring return((score <= existsRatio) ? new ReadOnlyCollection <IWebElement>(new List <IWebElement> { Positive(parent) }) : factory.Invoke()); }
/// <summary> /// Initializes a new instance of the <see cref="MockWebElement"/> class. /// </summary> /// <param name="parent"></param> /// <param name="tagName">Sets the <see cref="IWebElement.TagName"/> property of this element.</param> /// <param name="text">Sets the <see cref="IWebElement.Text"/> property of this element.</param> /// <param name="enabled">Sets the <see cref="IWebElement.Enabled"/> property of this element.</param> /// <param name="selected">Sets the <see cref="IWebElement.Selected"/> property of this element.</param> /// <param name="displayed">Sets the <see cref="IWebElement.Displayed"/> property of this element.</param> public MockWebElement(MockWebDriver parent, string tagName, string text, bool enabled, bool selected, bool displayed) { // state value = "default"; // properties WrappedDriver = parent; TagName = tagName; Text = text; Enabled = enabled; Selected = selected; Displayed = displayed; Location = new Point(1, 1); Size = new Size(10, 10); Attributes = new Dictionary <string, string>() { [MockLocators.Index] = "0", [MockLocators.Null] = null, ["href"] = "http://m.from-href.io/" }; }
public static IWebElement GetFocused(MockWebDriver parent) => Positive(parent);
// gets a random element (positive or negative). private static ReadOnlyCollection <IWebElement> RandomElements(MockWebDriver parent, int existsRatio) { return(RandomElements(parent, existsRatio, factory: () => new ReadOnlyCollection <IWebElement>(new List <IWebElement>()))); }
public static IWebElement GetNegative(MockWebDriver parent) => Negative(parent);
// gets a random element (positive or negative). private static IWebElement RandomElement(MockWebDriver parent, int positiveRatio) { return(RandomElement(parent, positiveRatio, factory: () => Negative(parent))); }
/// <summary> /// Gets a random element with a configurable chance of getting a positive element. /// </summary> /// <param name="parent">Driver in use.</param> /// <param name="positiveRatio">The chance % of getting a positive element.</param> /// <returns>An interface through which the user controls elements on the page.</returns> public static IWebElement GetRandom(MockWebDriver parent, int positiveRatio) { return(RandomElement(parent, positiveRatio)); }
public static IWebElement GetBody(MockWebDriver parent) => new MockWebElement(parent, tagName: "BODY");
public static IWebElement GetOptions(MockWebDriver parent) => new MockWebElement(parent, tagName: "option");
/// <summary> /// Factor an <see cref="MockWebElement"/> instance based on a given locator. /// </summary> /// <param name="parent">Driver in use.</param> /// <param name="by">The locating mechanism to use.</param> /// <returns>An interface through which the user controls elements on the page.</returns> public static IWebElement GetElement(MockWebDriver parent, By by) { return(Get(parent, by)); }
/// <summary> /// Initializes a new instance of the <see cref="MockWebElement"/> class. /// </summary> /// <param name="parent">Driver in use.</param> /// <param name="tagName">Sets the <see cref="IWebElement.TagName"/> property of this element.</param> public MockWebElement(MockWebDriver parent, string tagName) : this(parent, tagName, text : "Mock: Positive Element") { }
// gets a positive 'DIV' element private static IWebElement Positive(MockWebDriver parent) => new MockWebElement(parent);
public static IWebElement GetRandomStale(MockWebDriver parent) { // fetch elements >> return first or null return(RandomElement(parent, 95, () => parent.FindElement(MockBy.Stale()))); }
public static IWebElement GetRandomNotExists(MockWebDriver parent) { // fetch elements >> return first or null return(RandomElements(parent, 1).FirstOrDefault()); }
public static IWebElement GetRandomNegative(MockWebDriver parent) => RandomElement(parent, 10);
public static IWebElement GetRandomPositive(MockWebDriver parent) => RandomElement(parent, 90);
// gets a negative 'DIV' element private static IWebElement Negative(MockWebDriver parent) => new MockWebElement(parent, tagName: "div", text: "Mock: Negative Element", enabled: false, selected: false, displayed: false);
/// <summary> /// Initializes a new instance of the <see cref="MockWebElement"/> class. /// </summary> /// <param name="parent">Driver in use.</param> /// <param name="tagName">Sets the <see cref="IWebElement.TagName"/> property of this element.</param> /// <param name="text">Sets the <see cref="IWebElement.Text"/> property of this element.</param> public MockWebElement(MockWebDriver parent, string tagName, string text) : this(parent, tagName, text, enabled : true) { }
/// <summary> /// Initializes a new instance of the <see cref="MockWebElement"/> class. /// </summary> /// <param name="parent">Driver in use.</param> /// <param name="tagName">Sets the <see cref="IWebElement.TagName"/> property of this element.</param> /// <param name="text">Sets the <see cref="IWebElement.Text"/> property of this element.</param> /// <param name="enabled">Sets the <see cref="IWebElement.Enabled"/> property of this element.</param> /// <param name="selected">Sets the <see cref="IWebElement.Selected"/> property of this element.</param> public MockWebElement(MockWebDriver parent, string tagName, string text, bool enabled, bool selected) : this(parent, tagName, text, enabled, selected, displayed : true) { }
public static IWebElement GetSelectElement(MockWebDriver parent) => new MockWebElement(parent, tagName: "select");
/// <summary> /// Creates a new instance of <see cref="MockNavigation"/>. /// </summary> /// <param name="driver"><see cref="MockWebDriver"/> on which this <see cref="MockNavigation"/> based.</param> public MockNavigation(MockWebDriver driver) { this.driver = driver; }
/// <summary> /// Initializes a new instance of the <see cref="MockWebElement"/> class. /// </summary> /// <param name="parent">Driver in use.</param> public MockWebElement(MockWebDriver parent) : this(parent, tagName : "div") { }