// 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); // default if (method == default) { 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); }
/// <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())); }
// gets a random element (positive or negative). private static IWebElement RandomElement(MockWebDriver parent, int positiveRatio) { // get score var score = 0; lock (random) { score = random.Next(0, 100); } // factoring return((score <= positiveRatio) ? Positive(parent) : Negative(parent)); }
/// <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); }
// gets a random element (positive or negative). private static ReadOnlyCollection <IWebElement> RandomElements(MockWebDriver parent, int existsRatio) { // get score var score = 0; lock (random) { score = random.Next(0, 100); } // factoring return((score <= existsRatio) ? new ReadOnlyCollection <IWebElement>(new List <IWebElement> { Positive(parent) }) : new ReadOnlyCollection <IWebElement>(new List <IWebElement>())); }
/// <summary> /// Creates new instance of this MockAlert object. /// </summary> /// <param name="driver">Parent driver under which this alert exists.</param> public MockAlert(MockWebDriver driver) { this.driver = driver; }
/// <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) { }
/// <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> public MockWebElement(MockWebDriver parent) : this(parent, tagName : "div") { }
// 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);
// gets a positive 'DIV' element private static IWebElement Positive(MockWebDriver parent) => new MockWebElement(parent);
public static IWebElement GetNegative(MockWebDriver parent) => Negative(parent);
/// <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> /// 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 GetFocused(MockWebDriver parent) => Positive(parent);
public static IWebElement GetRandomNotExists(MockWebDriver parent) { // fetch elements >> return first or null return(RandomElements(parent, 1).FirstOrDefault()); }
/// <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") { }
public static IWebElement GetRandomNegative(MockWebDriver parent) => RandomElement(parent, 10);
public static IWebElement GetRandomPositive(MockWebDriver parent) => RandomElement(parent, 90);