コード例 #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);
            });
        }
コード例 #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);
            });
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: AssertProvider.cs プロジェクト: goblinfactory/Draki
        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
            });
        }
コード例 #5
0
ファイル: AssertProvider.cs プロジェクト: goblinfactory/Draki
 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);
         }
     });
 }
コード例 #6
0
ファイル: AssertProvider.cs プロジェクト: goblinfactory/Draki
 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);
         }
     });
 }
コード例 #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();
     });
 }
コード例 #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());
         }
     });
 }
コード例 #9
0
ファイル: AssertProvider.cs プロジェクト: goblinfactory/Draki
        private int CountElementsInProxy(ElementProxy elements)
        {
            int count = 0;

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

            return(count);
        }
コード例 #10
0
ファイル: AssertProvider.cs プロジェクト: goblinfactory/Draki
        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
            });
        }
コード例 #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);
        }
コード例 #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);
                }
            });
        }
コード例 #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);
                }
            });
        }
コード例 #14
0
            /// <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);
            }
コード例 #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;
                }
            });
        }
コード例 #16
0
ファイル: AssertProvider.cs プロジェクト: goblinfactory/Draki
 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);
             }
         }
     });
 }
コード例 #17
0
ファイル: AssertProvider.cs プロジェクト: goblinfactory/Draki
        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);
        }
コード例 #18
0
ファイル: AssertProvider.cs プロジェクト: goblinfactory/Draki
 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);
             }
         }
     });
 }
コード例 #19
0
ファイル: AssertProvider.cs プロジェクト: goblinfactory/Draki
 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());
             }
         }
     });
 }
コード例 #20
0
ファイル: AssertProvider.cs プロジェクト: goblinfactory/Draki
 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);
             }
         }
     });
 }
コード例 #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);
        }
コード例 #22
0
 public void Visible(ElementProxy element, Action <bool> action)
 {
     this.RepackExceptions(() => Parallel.ForEach(this.commandProviders, x => x.Visible(element, action)));
 }
コード例 #23
0
 public void Focus(ElementProxy element)
 {
     this.RepackExceptions(() => Parallel.ForEach(element.Elements, e => e.Item1.Focus(new ElementProxy(e.Item1, e.Item2))));
 }
コード例 #24
0
 public void Exists(ElementProxy element)
 {
     Parallel.ForEach(providers, x => BuildAssertProvider(x.Key).Exists(element));
 }
コード例 #25
0
 public void NotVisible(ElementProxy element)
 {
     Parallel.ForEach(providers, x => BuildAssertProvider(x.Key).NotVisible(element));
 }
コード例 #26
0
 public void NotCssProperty(ElementProxy element, string propertyName, string propertyValue)
 {
     Parallel.ForEach(providers, x => BuildAssertProvider(x.Key).NotCssProperty(element, propertyName, propertyValue));
 }
コード例 #27
0
 public void NotAttribute(ElementProxy element, string attributeName, string attributeValue)
 {
     Parallel.ForEach(providers, x => BuildAssertProvider(x.Key).NotAttribute(element, attributeName, attributeValue));
 }
コード例 #28
0
 /// <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);
 }
コード例 #29
0
 /// <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);
 }
コード例 #30
0
 public void CssPropertyValue(ElementProxy element, string propertyName, Action <bool, string> action)
 {
     this.RepackExceptions(() => Parallel.ForEach(this.commandProviders, x => x.CssPropertyValue(element, propertyName, action)));
 }