public IReadOnlyList <OptionDefinition> GetOptionDefinitions()
 {
     return(RetryUntilTimeout.Run(
                () => _controlObject.Scope.FindAllCss("input[type='radio']")
                .Select((radioScope, i) => CreateOptionDefinitionFromRadioScope(radioScope, i + 1))
                .ToList()));
 }
        /// <summary>
        /// Returns the list's rows.
        /// Warning: this method does not wait until "the element" is available but detects all available rows at the moment of calling.
        /// </summary>
        public IReadOnlyList <TRowControlObject> GetDisplayedRows()
        {
            var cssSelector = string.Format(".bocListTable .bocListTableBody .bocListDataRow");

            return(RetryUntilTimeout.Run(
                       () => Scope.FindAllCss(cssSelector).Select(rowScope => CreateRowControlObject(GetHtmlID(), rowScope, _accessor)).ToList()));
        }
        /// <summary>
        /// Selects an option of a &lt;select&gt; element by <see cref="DiagnosticMetadataAttributes"/> given by
        /// <paramref name="diagnosticMetadataAttributeName"/> and <paramref name="diagnosticMetadataAttributeValue"/>.
        /// </summary>
        /// <param name="scope">The <see cref="ElementScope"/> on which the action is performed.</param>
        /// <param name="diagnosticMetadataAttributeName">The diagnostic metadata attribute name.</param>
        /// <param name="diagnosticMetadataAttributeValue">The diagnostic metadata attribute value.</param>
        public static void SelectOptionByDMA(
            [NotNull] this ElementScope scope,
            [NotNull] string diagnosticMetadataAttributeName,
            [NotNull] string diagnosticMetadataAttributeValue)
        {
            ArgumentUtility.CheckNotNull("scope", scope);
            ArgumentUtility.CheckNotNullOrEmpty("diagnosticMetadataAttributeName", diagnosticMetadataAttributeName);
            ArgumentUtility.CheckNotNullOrEmpty("diagnosticMetadataAttributeValue", diagnosticMetadataAttributeValue);

            // Hack: Coypu does not yet support SelectElement, use Selenium directly.
            RetryUntilTimeout.Run(
                () =>
            {
                var webElement = (IWebElement)scope.Native;

                var select = new SelectElement(webElement);
                foreach (var option in select.Options)
                {
                    if (option.GetAttribute(diagnosticMetadataAttributeName) != diagnosticMetadataAttributeValue)
                    {
                        continue;
                    }

                    select.SelectByValue(option.GetAttribute("value"));
                    return;
                }

                throw new MissingHtmlException(
                    string.Format(
                        "No option matches the diagnostic metadata '{0}'='{1}'.",
                        diagnosticMetadataAttributeName,
                        diagnosticMetadataAttributeValue));
            });
        }
 public IReadOnlyList <OptionDefinition> GetOptionDefinitions()
 {
     return(RetryUntilTimeout.Run(
                () => _controlObject.Scope.FindChild("Value").FindAllCss("option")
                .Select((optionScope, i) => new OptionDefinition(optionScope.Value, i + 1, optionScope.Text))
                .ToList()));
 }
        private void EnsureBocListHasBeenFullyInitialized()
        {
            var bocListIsInitialized = RetryUntilTimeout.Run(() => Scope[DiagnosticMetadataAttributesForObjectBinding.BocListIsInitialized] == "true");

            if (!bocListIsInitialized)
            {
                _log.WarnFormat("Client side initialization of BocList '{0}' never finished.", GetHtmlID());
            }
        }
        /// <summary>
        /// Returns whether the given <paramref name="scope"/> is currently displayed (visible). The given <paramref name="scope"/> must exist, otherwise
        /// this method will throw an <see cref="MissingHtmlException"/>.
        /// </summary>
        /// <returns>True if the given <paramref name="scope"/> is visible, otherwise false.</returns>
        public static bool IsVisible([NotNull] this ElementScope scope)
        {
            ArgumentUtility.CheckNotNull("scope", scope);

            return(RetryUntilTimeout.Run(
                       () =>
            {
                var webElement = (IWebElement)scope.Native;
                return webElement.Displayed;
            }));
        }
        /// <inheritdoc/>
        public IReadOnlyList <OptionDefinition> GetOptionDefinitions()
        {
            if (IsReadOnly())
            {
                throw new InvalidOperationException("Cannot obtain option definitions on read-only control.");
            }

            return(RetryUntilTimeout.Run(
                       () => Scope.FindChild("Value").FindAllCss("option")
                       .Select((optionScope, i) => new OptionDefinition(optionScope.Value, i + 1, optionScope.Text))
                       .ToList()));
        }
        /// <summary>
        /// Selects an option of a &lt;select&gt; element by <paramref name="index"/>.
        /// </summary>
        /// <param name="scope">The <see cref="ElementScope"/> on which the action is performed.</param>
        /// <param name="index">The index of the option to select.</param>
        public static void SelectOptionByIndex([NotNull] this ElementScope scope, int index)
        {
            ArgumentUtility.CheckNotNull("scope", scope);

            // Hack: Coypu does not yet support SelectElement, use Selenium directly.
            RetryUntilTimeout.Run(
                () =>
            {
                var webElement = (IWebElement)scope.Native;

                var select = new SelectElement(webElement);
                select.SelectByIndex(index - 1);
            });
        }
        /// <summary>
        /// Returns the text of the currently selected option. If more than one option is selected, this method returns the first selected item's text.
        /// </summary>
        /// <param name="scope">The <see cref="ElementScope"/> on which the action is performed.</param>
        /// <returns>The text of the currently selected option.</returns>
        public static OptionDefinition GetSelectedOption([NotNull] this ElementScope scope)
        {
            ArgumentUtility.CheckNotNull("scope", scope);

            // Hack: Coypu does not yet support SelectElement, use Selenium directly.
            return(RetryUntilTimeout.Run(
                       () =>
            {
                var webElement = (IWebElement)scope.Native;

                var select = new SelectElement(webElement);
                return new OptionDefinition(select.SelectedOption.GetAttribute("value"), -1, select.SelectedOption.Text);
            }));
        }
 private static IReadOnlyList <ItemDefinition> GetMenuItemOrSubMenuItemDefinitions(ElementScope scope)
 {
     return
         (RetryUntilTimeout.Run(
              () =>
              scope.FindAllXPath(".//li/span/span[2]")
              .Select(
                  (itemScope, i) =>
                  new ItemDefinition(
                      itemScope[DiagnosticMetadataAttributes.ItemID],
                      i + 1,
                      itemScope.Text.Trim(),
                      true /* currently we have no way to determine if a menu item is enabled or not */))
              .ToList()));
 }
예제 #11
0
        /// <inheritdoc/>
        public IReadOnlyList <ItemDefinition> GetItemDefinitions()
        {
            var dropDownMenuScope = GetDropDownMenuScope();

            return(RetryUntilTimeout.Run(
                       () => dropDownMenuScope.FindAllCss("li.DropDownMenuItem, li.DropDownMenuItemDisabled")
                       .Select(
                           (itemScope, i) =>
                           new ItemDefinition(
                               itemScope[DiagnosticMetadataAttributes.ItemID],
                               i + 1,
                               itemScope.Text.Trim(),
                               !itemScope["class"].Contains("DropDownMenuItemDisabled")))
                       .ToList()));
        }
예제 #12
0
        /// <inheritdoc/>
        public IReadOnlyList <WebTabStripTabDefinition> GetTabDefinitions()
        {
            const string cssSelector = "span.tabStripTab, span.tabStripTabSelected";

            return(RetryUntilTimeout.Run(
                       () =>
                       Scope.FindAllCss(cssSelector)
                       .Select(
                           (tabScope, i) =>
                           new WebTabStripTabDefinition(
                               tabScope[DiagnosticMetadataAttributes.ItemID],
                               i + 1,
                               tabScope[DiagnosticMetadataAttributes.Content]))
                       .ToList()));
        }
예제 #13
0
        /// <summary>
        /// Performs a context click (right click).
        /// </summary>
        /// <param name="scope">The <see cref="ElementScope"/> on which the action is performed.</param>
        /// <param name="context">The corresponding control object's context.</param>
        public static void ContextClick([NotNull] this ElementScope scope, [NotNull] WebTestObjectContext context)
        {
            ArgumentUtility.CheckNotNull("scope", scope);
            ArgumentUtility.CheckNotNull("context", context);

            // Hack: Coypu does not directly support the Actions interface, therefore we need to fall back to using Selenium.
            RetryUntilTimeout.Run(
                () =>
            {
                var webDriver   = (IWebDriver)context.Browser.Native;
                var nativeScope = (IWebElement)scope.Native;

                var actions = new Actions(webDriver);
                actions.ContextClick(nativeScope);
                actions.Perform();
            });
        }
        /// <summary>
        /// Returns the computed text color of the control. This method ignores transparencies - the first non-transparent color set in the node's
        /// DOM hierarchy is returned. The returned color's alpha value is always 255 (opaque).
        /// </summary>
        /// <returns>The text color or <see cref="WebColor.Transparent"/> if no text color is set (not even on any parent node).</returns>
        public static WebColor GetComputedTextColor([NotNull] this ElementScope scope, [NotNull] ControlObjectContext context)
        {
            ArgumentUtility.CheckNotNull("scope", scope);
            ArgumentUtility.CheckNotNull("context", context);

            // Todo RM-6337: Coypu does not support JavaScript executions with arguments by now, simplify as soon as https://github.com/featurist/coypu/issues/128 has been implemented.
            var javaScriptExecutor = (IJavaScriptExecutor)context.Browser.Driver.Native;
            var computedTextColor  =
                RetryUntilTimeout.Run(() => (string)javaScriptExecutor.ExecuteScript(CommonJavaScripts.GetComputedTextColor, scope.Native));

            if (IsTransparent(computedTextColor))
            {
                return(WebColor.Transparent);
            }

            return(ParseColorFromBrowserReturnedString(computedTextColor));
        }
        protected BocListControlObjectBase([NotNull] ControlObjectContext context)
            : base(context)
        {
            _log      = LogManager.GetLogger(GetType());
            _accessor = new BocListRowControlObjectHostAccessor(this);

            EnsureBocListHasBeenFullyInitialized();

            _hasFakeTableHead = Scope.FindCss("div.bocListTableContainer")[DiagnosticMetadataAttributesForObjectBinding.BocListHasFakeTableHead] != null;
            _columns          = RetryUntilTimeout.Run(
                () => Scope.FindAllCss(_hasFakeTableHead ? ".bocListFakeTableHead th" : ".bocListTableContainer th")
                .Select(
                    (s, i) =>
                    new BocListColumnDefinition <TRowControlObject, TCellControlObject> (
                        s[DiagnosticMetadataAttributes.ItemID],
                        i + 1,
                        s[DiagnosticMetadataAttributes.Content],
                        ColumnHasDiagnosticMetadata(s)))
                .ToList());
        }
예제 #16
0
 /// <summary>
 /// Returns the number of child nodes.
 /// </summary>
 public int GetNumberOfChildren()
 {
     return(RetryUntilTimeout.Run(() => GetChildrenScope().FindAllXPath("./table").Count()));
 }
 /// <summary>
 /// Returns the number of rows in the list (on the current page).
 /// </summary>
 public int GetNumberOfRows()
 {
     return(RetryUntilTimeout.Run(() => Scope.FindAllCss(".bocListTable .bocListTableBody > tr.bocListDataRow").Count()));
 }