Exemplo n.º 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;
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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()));
        }
Exemplo n.º 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());
        }
Exemplo n.º 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());
        }
Exemplo n.º 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/"
            };
        }
Exemplo n.º 8
0
 public static IWebElement GetFocused(MockWebDriver parent) => Positive(parent);
Exemplo n.º 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>())));
 }
Exemplo n.º 10
0
 public static IWebElement GetNegative(MockWebDriver parent) => Negative(parent);
Exemplo n.º 11
0
 // gets a random element (positive or negative).
 private static IWebElement RandomElement(MockWebDriver parent, int positiveRatio)
 {
     return(RandomElement(parent, positiveRatio, factory: () => Negative(parent)));
 }
Exemplo n.º 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));
 }
Exemplo n.º 13
0
 public static IWebElement GetBody(MockWebDriver parent)
 => new MockWebElement(parent, tagName: "BODY");
Exemplo n.º 14
0
 public static IWebElement GetOptions(MockWebDriver parent) => new MockWebElement(parent, tagName: "option");
Exemplo n.º 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));
 }
Exemplo n.º 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")
 {
 }
Exemplo n.º 17
0
 // gets a positive 'DIV' element
 private static IWebElement Positive(MockWebDriver parent) => new MockWebElement(parent);
Exemplo n.º 18
0
 public static IWebElement GetRandomStale(MockWebDriver parent)
 {
     // fetch elements >> return first or null
     return(RandomElement(parent, 95, () => parent.FindElement(MockBy.Stale())));
 }
Exemplo n.º 19
0
 public static IWebElement GetRandomNotExists(MockWebDriver parent)
 {
     // fetch elements >> return first or null
     return(RandomElements(parent, 1).FirstOrDefault());
 }
Exemplo n.º 20
0
 public static IWebElement GetRandomNegative(MockWebDriver parent) => RandomElement(parent, 10);
Exemplo n.º 21
0
 public static IWebElement GetRandomPositive(MockWebDriver parent) => RandomElement(parent, 90);
Exemplo n.º 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);
Exemplo n.º 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)
 {
 }
Exemplo n.º 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)
 {
 }
Exemplo n.º 25
0
 public static IWebElement GetSelectElement(MockWebDriver parent) => new MockWebElement(parent, tagName: "select");
Exemplo n.º 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;
 }
Exemplo n.º 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")
 {
 }