Example #1
0
        public void SelectValue(ElementProxy element, string optionValue)
        {
            this.Act(CommandType.Action, () =>
            {
                var unwrappedElement = element.Element as Element;

                SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
                if (selectElement.IsMultiple)
                {
                    selectElement.DeselectAll();
                }
                selectElement.SelectByValue(optionValue);
            });
        }
Example #2
0
        public void SelectIndex(ElementProxy element, int optionIndex)
        {
            this.Act(CommandType.Action, () =>
            {
                var unwrappedElement = element.Element as Element;

                SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
                if (selectElement.IsMultiple)
                {
                    selectElement.DeselectAll();
                }
                selectElement.SelectByIndex(optionIndex);
            });
        }
        public ElementProxy FindMultiple(string selector)
        {
            var result = new ElementProxy();

            this.RepackExceptions(() => Parallel.ForEach(this.commandProviders, x =>
            {
                foreach (var element in x.FindMultiple(selector).Elements)
                {
                    result.Elements.Add(new Tuple <ICommandProvider, Func <IElement> >(x, element.Item2));
                }
            }));

            return(result);
        }
Example #4
0
        private ElementHasTextResult elementHasText(ElementProxy element, Func <string, bool> textMatcher)
        {
            var hasText          = false;
            var unwrappedElement = element.Element;
            var actualText       = unwrappedElement.Text;

            if (unwrappedElement.IsSelect)
            {
                foreach (var optionText in unwrappedElement.SelectedOptionTextCollection)
                {
                    if (textMatcher(optionText))
                    {
                        hasText = true;
                        break;
                    }
                }

                actualText = string.Join(", ", unwrappedElement.SelectedOptionTextCollection.Select(x => x).ToArray());
            }
            else
            {
                if (textMatcher(unwrappedElement.Text))
                {
                    hasText = true;
                }
            }

            var elementType = "DOM Element";

            if (unwrappedElement.IsText)
            {
                elementType = "TextElement";
            }
            else if (unwrappedElement.IsMultipleSelect)
            {
                elementType = "MultipleSelectElement";
            }
            else if (unwrappedElement.IsSelect)
            {
                elementType = "SelectElement";
            }

            return(new ElementHasTextResult
            {
                HasText = hasText,
                ActualText = actualText,
                ElementType = elementType,
                Selector = element.Element.Selector
            });
        }
Example #5
0
 public void NotAttribute(ElementProxy element, string attributeName, string attributeValue)
 {
     this.commandProvider.Act(commandType, () =>
     {
         var result = element.Element.Attributes.Get(attributeName);
         if (attributeValue == null && result != null)
         {
             this.ReportError("Expected element [{0}] not to have attribute [{1}] but it did.", element.Element.Selector, attributeName);
         }
         else if (result != null && IsTextMatch(result, attributeValue))
         {
             this.ReportError("Expected element [{0}]'s attribute [{1}] not to have a value of [{2}] but it did.", element.Element.Selector, attributeName, attributeValue);
         }
     });
 }
Example #6
0
 public void NotCssProperty(ElementProxy element, string propertyName, string propertyValue)
 {
     this.commandProvider.Act(commandType, () =>
     {
         var result = this.elementHasCssProperty(element, propertyName, propertyValue);
         if (propertyValue == null && result.HasProperty)
         {
             this.ReportError("Expected element [{0}] not to have CSS property [{1}] but it did.", element.Element.Selector, propertyName);
         }
         else if (result.PropertyMatches)
         {
             this.ReportError("Expected element [{0}]'s CSS property [{1}] not to have a value of [{2}] but it did.", element.Element.Selector, propertyName, propertyValue);
         }
     });
 }
Example #7
0
 public void DragAndDrop(ElementProxy source, int sourceOffsetX, int sourceOffsetY, ElementProxy target, int targetOffsetX, int targetOffsetY)
 {
     this.Act(CommandType.Action, () =>
     {
         var element       = source.Element as Element;
         var targetElement = target.Element as Element;
         new Actions(this.webDriver)
         .MoveToElement(element.WebElement, sourceOffsetX, sourceOffsetY)
         .ClickAndHold()
         .MoveToElement(targetElement.WebElement, targetOffsetX, targetOffsetY)
         .Release()
         .Build()
         .Perform();
     });
 }
Example #8
0
 public void CssPropertyValue(ElementProxy element, string propertyName, Action <bool, string> action)
 {
     this.Act(CommandType.Action, () =>
     {
         var propertyValue = ((IJavaScriptExecutor)this.webDriver).ExecuteScript(string.Format("return fluentjQuery(\"{0}\").css(\"{1}\")", element.Element.Selector, propertyName));
         if (propertyValue == null)
         {
             action(false, string.Empty);
         }
         else
         {
             action(true, propertyValue.ToString());
         }
     });
 }
Example #9
0
        private int CountElementsInProxy(ElementProxy elements)
        {
            int count = 0;

            foreach (var element in elements.Elements)
            {
                try
                {
                    element.Item2();
                    count++;
                }
                catch (Exception) { }
            }

            return(count);
        }
Example #10
0
        private ElementHasValueResult elementHasValue(ElementProxy element, Func <string, bool> valueMatcher)
        {
            var hasValue         = false;
            var unwrappedElement = element.Element;

            if (unwrappedElement.IsMultipleSelect)
            {
                foreach (var optionValue in unwrappedElement.SelectedOptionValues)
                {
                    if (valueMatcher(optionValue))
                    {
                        hasValue = true;
                        break;
                    }
                }
            }
            else
            {
                if (valueMatcher(unwrappedElement.Value))
                {
                    hasValue = true;
                }
            }

            var elementType = "DOM Element";

            if (unwrappedElement.IsText)
            {
                elementType = "TextElement";
            }
            else if (unwrappedElement.IsMultipleSelect)
            {
                elementType = "MultipleSelectElement";
            }
            else if (unwrappedElement.IsSelect)
            {
                elementType = "SelectElement";
            }

            return(new ElementHasValueResult
            {
                HasValue = hasValue,
                ElementType = elementType,
                ActualValue = unwrappedElement.Value,
                Selector = element.Element.Selector
            });
        }
Example #11
0
        public ElementProxy Find(string selector)
        {
            var proxy = new ElementProxy(this, () =>
            {
                try
                {
                    var webElement = this.webDriver.FindElement(Sizzle.Find(selector));
                    return(new Element(webElement, selector));
                }
                catch (NoSuchElementException)
                {
                    throw new FluentElementNotFoundException("Unable to find element with selector [{0}]", selector);
                }
            });

            return(proxy);
        }
Example #12
0
        public void MultiSelectIndex(ElementProxy element, int[] optionIndices)
        {
            this.Act(CommandType.Action, () =>
            {
                var unwrappedElement = element.Element as Element;

                SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
                if (selectElement.IsMultiple)
                {
                    selectElement.DeselectAll();
                }

                foreach (var optionIndex in optionIndices)
                {
                    selectElement.SelectByIndex(optionIndex);
                }
            });
        }
Example #13
0
        public void MultiSelectText(ElementProxy element, string[] optionTextCollection)
        {
            this.Act(CommandType.Action, () =>
            {
                var unwrappedElement = element.Element as Element;

                SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
                if (selectElement.IsMultiple)
                {
                    selectElement.DeselectAll();
                }

                foreach (var optionText in optionTextCollection)
                {
                    selectElement.SelectByText(optionText);
                }
            });
        }
            /// <summary>
            /// Enter text into specified <paramref name="element"/>.
            /// </summary>
            /// <param name="element">IElement factory function.</param>
            public IActionSyntaxProvider In(ElementProxy element)
            {
                if (!element.Element.IsText)
                {
                    throw new FluentException("Enter().In() is only supported on text elements (input, textarea, etc).");
                }

                if (this.eventsEnabled)
                {
                    this.syntaxProvider.commandProvider.EnterText(element, text);
                }
                else
                {
                    this.syntaxProvider.commandProvider.EnterTextWithoutEvents(element, text);
                }

                return(this.syntaxProvider);
            }
Example #15
0
        public void Focus(ElementProxy element)
        {
            this.Act(CommandType.Action, () =>
            {
                var unwrappedElement = element.Element as Element;

                switch (unwrappedElement.WebElement.TagName)
                {
                case "input":
                case "select":
                case "textarea":
                case "a":
                case "iframe":
                case "button":
                    var executor = (IJavaScriptExecutor)this.webDriver;
                    executor.ExecuteScript("arguments[0].focus();", unwrappedElement.WebElement);
                    break;
                }
            });
        }
Example #16
0
 public void NotValue(ElementProxy element, string value)
 {
     this.commandProvider.Act(commandType, () =>
     {
         var result = elementHasValue(element, (elValue) => IsTextMatch(elValue, value));
         if (result.HasValue)
         {
             if (element.Element.IsMultipleSelect)
             {
                 this.ReportError("Expected SelectElement [{0}] selected options to have no options with value of [{1}]. Selected option values include [{2}]", result.Selector, value, string.Join(",", element.Element.SelectedOptionValues));
             }
             else if (element.Element.IsSelect)
             {
                 this.ReportError("Expected SelectElement [{0}] selected option value not to be [{1}] but it was.", result.Selector, value);
             }
             else
             {
                 this.ReportError("Expected {0} [{1}] value not to be [{2}] but it was.", result.ElementType, result.Selector, value);
             }
         }
     });
 }
Example #17
0
        private ElementHasCssPropertyResult elementHasCssProperty(ElementProxy element, string propertyName, string propertyValue)
        {
            var result = new ElementHasCssPropertyResult();

            this.commandProvider.CssPropertyValue(element, propertyName, (hasProperty, actualPropertyValue) =>
            {
                if (!hasProperty)
                {
                    return;
                }

                result.HasProperty   = true;
                result.PropertyValue = actualPropertyValue;

                if (propertyValue != null && IsTextMatch(actualPropertyValue, propertyValue))
                {
                    result.PropertyMatches = true;
                }
            });

            return(result);
        }
Example #18
0
 public void NotText(ElementProxy element, string text)
 {
     this.commandProvider.Act(commandType, () =>
     {
         var result = elementHasText(element, (elText) => IsTextMatch(elText, text));
         if (result.HasText)
         {
             if (element.Element.IsMultipleSelect)
             {
                 this.ReportError("Expected SelectElement [{0}] selected options to have no options with text of [{1}]. Selected option text values include [{2}]", result.Selector, text, string.Join(",", element.Element.SelectedOptionTextCollection));
             }
             else if (element.Element.IsSelect)
             {
                 this.ReportError("Expected SelectElement [{0}] selected option text not to be [{1}] but it was.", result.Selector, text);
             }
             else
             {
                 this.ReportError("Expected {0} [{1}] text not to be [{2}] but it was.", result.ElementType, result.Selector, text);
             }
         }
     });
 }
Example #19
0
 public void NotValue(ElementProxy element, Expression <Func <string, bool> > matchFunc)
 {
     this.commandProvider.Act(commandType, () =>
     {
         var compiledFunc = matchFunc.Compile();
         var result       = elementHasValue(element, (elValue) => compiledFunc(elValue));
         if (result.HasValue)
         {
             if (element.Element.IsMultipleSelect)
             {
                 this.ReportError("Expected SelectElement [{0}] selected options to have no options with value matching expression [{1}]. Selected option values include [{2}]", result.Selector, matchFunc.ToExpressionString(), string.Join(",", element.Element.SelectedOptionValues));
             }
             else if (element.Element.IsSelect)
             {
                 this.ReportError("Expected SelectElement [{0}] selected option value not to match expression [{1}] but it did.", result.Selector, matchFunc.ToExpressionString());
             }
             else
             {
                 this.ReportError("Expected {0} [{1}] value not to match expression [{2}] but it did.", result.ElementType, result.Selector, matchFunc.ToExpressionString());
             }
         }
     });
 }
Example #20
0
 public void Text(ElementProxy element, Expression <Func <string, bool> > matchFunc)
 {
     this.commandProvider.Act(commandType, () =>
     {
         var compiledFunc = matchFunc.Compile();
         var result       = elementHasText(element, (elText) => compiledFunc(elText));
         if (!result.HasText)
         {
             if (element.Element.IsMultipleSelect)
             {
                 this.ReportError("Expected SelectElement [{0}] selected options to have at least one option with text matching expression [{1}]. Selected option text values include [{2}]", result.Selector, matchFunc.ToExpressionString(), string.Join(",", element.Element.SelectedOptionTextCollection));
             }
             else if (element.Element.IsSelect)
             {
                 this.ReportError("Expected SelectElement [{0}] selected option text to match expression [{1}] but it was actually [{2}].", result.Selector, matchFunc.ToExpressionString(), result.ActualText);
             }
             else
             {
                 this.ReportError("Expected {0} [{1}] text to match expression [{2}] but it was actually [{3}].", result.ElementType, result.Selector, matchFunc.ToExpressionString(), result.ActualText);
             }
         }
     });
 }
Example #21
0
        public ElementProxy FindMultiple(string selector)
        {
            var finalResult = new ElementProxy();

            finalResult.Children.Add(new Func <ElementProxy>(() =>
            {
                var result      = new ElementProxy();
                var webElements = this.webDriver.FindElements(Sizzle.Find(selector));
                if (webElements.Count == 0)
                {
                    throw new FluentElementNotFoundException("Unable to find element with selector [{0}].", selector);
                }

                foreach (var element in webElements)
                {
                    result.Elements.Add(new Tuple <ICommandProvider, Func <IElement> >(this, () => new Element(element, selector)));
                }

                return(result);
            }));

            return(finalResult);
        }
 public void Visible(ElementProxy element, Action <bool> action)
 {
     this.RepackExceptions(() => Parallel.ForEach(this.commandProviders, x => x.Visible(element, action)));
 }
 public void Focus(ElementProxy element)
 {
     this.RepackExceptions(() => Parallel.ForEach(element.Elements, e => e.Item1.Focus(new ElementProxy(e.Item1, e.Item2))));
 }
Example #24
0
 public void Exists(ElementProxy element)
 {
     Parallel.ForEach(providers, x => BuildAssertProvider(x.Key).Exists(element));
 }
Example #25
0
 public void NotVisible(ElementProxy element)
 {
     Parallel.ForEach(providers, x => BuildAssertProvider(x.Key).NotVisible(element));
 }
Example #26
0
 public void NotCssProperty(ElementProxy element, string propertyName, string propertyValue)
 {
     Parallel.ForEach(providers, x => BuildAssertProvider(x.Key).NotCssProperty(element, propertyName, propertyValue));
 }
Example #27
0
 public void NotAttribute(ElementProxy element, string attributeName, string attributeValue)
 {
     Parallel.ForEach(providers, x => BuildAssertProvider(x.Key).NotAttribute(element, attributeName, attributeValue));
 }
 /// <summary>
 /// Assert the element specified exists.
 /// </summary>
 /// <param name="element">Reference to element</param>
 /// <returns></returns>
 public AssertSyntaxProvider Exists(ElementProxy element)
 {
     this.assertProvider.Exists(element);
     return(this.assertSyntaxProvider);
 }
 /// <summary>
 /// Assert that the element is visible and can be interacted with.
 /// </summary>
 /// <param name="selector"></param>
 public AssertSyntaxProvider Visible(ElementProxy element)
 {
     this.assertProvider.Visible(element);
     return(this);
 }
 public void CssPropertyValue(ElementProxy element, string propertyName, Action <bool, string> action)
 {
     this.RepackExceptions(() => Parallel.ForEach(this.commandProviders, x => x.CssPropertyValue(element, propertyName, action)));
 }