예제 #1
0
        // 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;
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        /// <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()));
        }
예제 #4
0
        // 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));
        }
예제 #5
0
        /// <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);
        }
예제 #6
0
        // 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>()));
        }
예제 #7
0
 /// <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;
 }
예제 #8
0
 /// <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)
 {
 }
예제 #9
0
 /// <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)
 {
 }
예제 #10
0
 /// <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")
 {
 }
예제 #11
0
 // 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);
예제 #12
0
 // gets a positive 'DIV' element
 private static IWebElement Positive(MockWebDriver parent) => new MockWebElement(parent);
예제 #13
0
 public static IWebElement GetNegative(MockWebDriver parent) => Negative(parent);
예제 #14
0
 /// <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));
 }
예제 #15
0
 /// <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));
 }
예제 #16
0
 public static IWebElement GetFocused(MockWebDriver parent) => Positive(parent);
예제 #17
0
 public static IWebElement GetRandomNotExists(MockWebDriver parent)
 {
     // fetch elements >> return first or null
     return(RandomElements(parent, 1).FirstOrDefault());
 }
예제 #18
0
 /// <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")
 {
 }
예제 #19
0
 public static IWebElement GetRandomNegative(MockWebDriver parent) => RandomElement(parent, 10);
예제 #20
0
 public static IWebElement GetRandomPositive(MockWebDriver parent) => RandomElement(parent, 90);