コード例 #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);

            // 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;
            }
        }
コード例 #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
        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);
        }
コード例 #4
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()));
        }
コード例 #5
0
        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());
        }
コード例 #6
0
        // 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());
        }
コード例 #7
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);
            Attributes    = new Dictionary <string, string>()
            {
                [MockLocators.Index] = "0",
                [MockLocators.Null]  = null,
                ["href"]             = "http://m.from-href.io/"
            };
        }
コード例 #8
0
 public static IWebElement GetFocused(MockWebDriver parent) => Positive(parent);
コード例 #9
0
 // 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>())));
 }
コード例 #10
0
 public static IWebElement GetNegative(MockWebDriver parent) => Negative(parent);
コード例 #11
0
 // gets a random element (positive or negative).
 private static IWebElement RandomElement(MockWebDriver parent, int positiveRatio)
 {
     return(RandomElement(parent, positiveRatio, factory: () => Negative(parent)));
 }
コード例 #12
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));
 }
コード例 #13
0
 public static IWebElement GetBody(MockWebDriver parent)
 => new MockWebElement(parent, tagName: "BODY");
コード例 #14
0
 public static IWebElement GetOptions(MockWebDriver parent) => new MockWebElement(parent, tagName: "option");
コード例 #15
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));
 }
コード例 #16
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")
 {
 }
コード例 #17
0
 // gets a positive 'DIV' element
 private static IWebElement Positive(MockWebDriver parent) => new MockWebElement(parent);
コード例 #18
0
 public static IWebElement GetRandomStale(MockWebDriver parent)
 {
     // fetch elements >> return first or null
     return(RandomElement(parent, 95, () => parent.FindElement(MockBy.Stale())));
 }
コード例 #19
0
 public static IWebElement GetRandomNotExists(MockWebDriver parent)
 {
     // fetch elements >> return first or null
     return(RandomElements(parent, 1).FirstOrDefault());
 }
コード例 #20
0
 public static IWebElement GetRandomNegative(MockWebDriver parent) => RandomElement(parent, 10);
コード例 #21
0
 public static IWebElement GetRandomPositive(MockWebDriver parent) => RandomElement(parent, 90);
コード例 #22
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);
コード例 #23
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)
 {
 }
コード例 #24
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)
 {
 }
コード例 #25
0
 public static IWebElement GetSelectElement(MockWebDriver parent) => new MockWebElement(parent, tagName: "select");
コード例 #26
0
 /// <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;
 }
コード例 #27
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")
 {
 }