Example #1
0
        ///// <summary>
        ///// Update the css to the FieldCss type for the string this method is called on
        ///// </summary>
        ///// <param name="value">The value this method is called on</param>
        ///// <param name="getFor">The css class to add</param>
        ///// <returns></returns>
        //public static string UpdateCssTo(this IMaterializeGroup value, string css, FieldCss getFor)
        //{
        //    switch (getFor)
        //    {
        //        // TODO: we need to switch the css here based on
        //        // 1 - the state of the input - getFor
        //        // 2 - the type of tag in the input group
        //        // this entire function could also change
        //        case FieldCss.Initial:
        //            return css;
        //        case FieldCss.Active:
        //            return css.Contains(Active) ? css : $"{css} {Active}";
        //        case FieldCss.Valid:
        //            // We need to remove the orange-text class
        //            css = css.Contains(RequiredText) ? css.RemoveCss(RequiredText) : css;
        //            css = $"{css} {ValidText}";
        //            return css;
        //        case FieldCss.Invalid:
        //            // We need to remove the orange-text class
        //            css = css.Contains(RequiredText) ? $"{css.RemoveCss(RequiredText)}" : css;
        //            css = css.Contains(ValidText) ? $"{css.RemoveCss(ValidText)}" : css;
        //            css = $"{css} {InvalidText}";
        //            return css;
        //        default:
        //            return css;
        //    }
        //}

        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <param name="css"></param>
        /// <param name="getFor"></param>
        /// <param name="cssClasses"></param>
        /// <returns></returns>
        public static string UpdateCssTo(this IMaterializeGroup value, string css, FieldCss getFor, Dictionary <FieldCss, string> cssClasses)
        {
            switch (getFor)
            {
            // TODO: we need to switch the css here based on
            // 1 - the state of the input - getFor
            // 2 - the type of tag in the input group
            // this entire function could also change
            case FieldCss.Initial:
                return(cssClasses[FieldCss.Initial]);

            case FieldCss.Touched:
                return(cssClasses[FieldCss.Touched]);

            case FieldCss.Valid:
                return(cssClasses[FieldCss.Valid]);

            case FieldCss.Invalid:
                return(cssClasses[FieldCss.Invalid]);

            case FieldCss.Optional:
                return(cssClasses[FieldCss.Optional]);

            case FieldCss.Active:
                return(cssClasses[FieldCss.Active]);

            default:
                return(css);
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <param name="css"></param>
        /// <param name="getFor"></param>
        /// <returns></returns>
        public static string UpdateCssForCollapse(this IMaterializeGroup value, string css, FieldCss getFor)
        {
            var cssClasses = new Dictionary <FieldCss, string>
            {
                { FieldCss.Initial, MaterializeCssStyles.MaterializeCollapseHeaderCssInitial },
                { FieldCss.Touched, null },
                { FieldCss.Valid, null },
                { FieldCss.Invalid, null },
                { FieldCss.Optional, null },
                { FieldCss.Active, MaterializeCssStyles.MaterializeCollapseHeaderCssActive }
            };

            return(UpdateCssTo(value, css, getFor, cssClasses));
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <param name="css"></param>
        /// <param name="getFor"></param>
        /// <returns></returns>
        public static string UpdateCssForSelectList(this IMaterializeGroup value, string css, FieldCss getFor)
        {
            var cssClasses = new Dictionary <FieldCss, string>();

            cssClasses.Add(FieldCss.Initial, MaterializeCssStyles.MaterializeSelectGroupSelectListClassesInitial);
            cssClasses.Add(FieldCss.Touched, null);
            cssClasses.Add(FieldCss.Valid, null);
            cssClasses.Add(FieldCss.Invalid, null);
            cssClasses.Add(FieldCss.Optional, null);
            cssClasses.Add(FieldCss.Active, null);

            return(UpdateCssTo(value, css, getFor, cssClasses));
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="value"></param>
        /// <param name="css"></param>
        /// <param name="getFor"></param>
        /// <returns></returns>
        /// <remarks>
        /// Automatically addes the materialize-textarea class
        /// </remarks>
        public static string UpdateCssForTextarea(this IMaterializeGroup value, string css, FieldCss getFor)
        {
            var cssClasses = new Dictionary <FieldCss, string>();

            cssClasses.Add(FieldCss.Initial, MaterializeCssStyles.MaterializeInputGroupInputClassesInitial + MaterializeCssStyles.MaterializeTextarea);
            cssClasses.Add(FieldCss.Touched, MaterializeCssStyles.MaterializeInputGroupInputClassesTouched + MaterializeCssStyles.MaterializeTextarea);
            cssClasses.Add(FieldCss.Valid, MaterializeCssStyles.MaterializeInputGroupInputClassesValid + MaterializeCssStyles.MaterializeTextarea);
            cssClasses.Add(FieldCss.Invalid, MaterializeCssStyles.MaterializeInputGroupInputClassesInValid + MaterializeCssStyles.MaterializeTextarea);
            cssClasses.Add(FieldCss.Optional, MaterializeCssStyles.MaterializeInputGroupInputClassesOptional + MaterializeCssStyles.MaterializeTextarea);
            cssClasses.Add(FieldCss.Active, MaterializeCssStyles.MaterializeInputGroupInputClassesActive + MaterializeCssStyles.MaterializeTextarea);

            return(UpdateCssTo(value, css, getFor, cssClasses));
        }
Example #5
0
        /// <summary>
        /// Verfiy the materialize fields state when the page is loaded
        /// </summary>
        /// <param name="inputGroupContainer">The materialize input group container that is used to get the elements that need to be checked</param>
        /// <param name="testData">The test data to be used for the comparision</param>
        /// <param name="updateCssTo">The css style required, the field will have it's css updated to this type</param>
        public static void VerifyMaterializeSelectField(IWebElement inputGroupContainer, MaterializeSelectGroup testData, FieldCss updateCssTo)
        {
            IWebElement iconElement            = null;
            IWebElement inputElement           = null;
            IWebElement labelElement           = null;
            IWebElement validationLabelElement = null;

            IWebElement spanElement = null;

            IWebElement ulElement = null;
            IWebElement liElement = null;

            IWebElement selectElement = null;
            IWebElement optionElement = null;

            string fieldName = null;

            GetMaterializeWebElements(inputGroupContainer, ref iconElement, ref inputElement, ref labelElement, ref validationLabelElement, ref spanElement, ref ulElement, ref selectElement, ref fieldName, testData.FieldInputType);

            liElement     = updateCssTo.HasFlag(FieldCss.Initial) ? ulElement.FindElement(By.CssSelector("li:first-child")) : ulElement.FindElement(By.CssSelector("li[actve]"));
            optionElement = selectElement.FindElement(By.CssSelector("option[selected='selected']"));

            testData.UpdateCssForIcon(testData.IconClasses, updateCssTo).MatchesActualCss(iconElement.GetAttribute("class"), $"{fieldName} Icon Classes");
            testData.IconText.MatchesActual(iconElement.Text, $"{fieldName} Icon Text");

            if (testData.InputClasses != null)
            {
                testData.UpdateCssForInput(testData.InputClasses, updateCssTo).MatchesActualCss(inputElement.GetAttribute("class"), $"{fieldName} Input Classes");
            }

            if (testData.InputText != null)
            {
                testData.InputText.MatchesActual(inputElement.Text, $"{fieldName} Input Text");
            }

            if (testData.LabelClasses != null)
            {
                testData.UpdateCssForLabel(testData.LabelClasses, updateCssTo).MatchesActualCss(labelElement.GetAttribute("class"), $"{fieldName} Label Classes");
            }

            if (testData.LabelText != null)
            {
                testData.LabelText.MatchesActual(labelElement.Text, $"{fieldName} Label Text");
            }

            if (testData.SpanClasses != null)
            {
                testData.UpdateCssForSpan(testData.SpanClasses, updateCssTo).MatchesActualCss(spanElement.GetAttribute("class"), $"{fieldName} Span Classes");
            }

            if (testData.SpanText != null)
            {
                testData.SpanText.MatchesActual(spanElement.Text, $"{fieldName} Span Text");
            }

            if (testData.UnOrderedClasses != null)
            {
                testData.UpdateCssForUnOrderedList(testData.UnOrderedClasses, updateCssTo).MatchesActualCss(ulElement.GetAttribute("class"), $"{fieldName} UnOrderList Classes");
            }

            if (testData.UnOrderedSelectItemClasses != null)
            {
                testData.UpdateCssForUnOrderedListSelectedItem(testData.UnOrderedSelectItemClasses, updateCssTo).MatchesActualCss(liElement.GetAttribute("class"), $"{fieldName} UnOrderList Selected Item Classes");
            }

            if (testData.UnOrderedSelectedItemText != null)
            {
                testData.UnOrderedSelectedItemText.MatchesActual(liElement.GetAttribute("innerText"), $"{fieldName} UnOrderList Selected Item Text");
            }

            if (testData.SelectListClasses != null)
            {
                testData.UpdateCssForSelectList(testData.SelectListClasses, updateCssTo).MatchesActualCss(selectElement.GetAttribute("class"), $"{fieldName} SelectList Classes");
            }

            if (testData.SelectListSelectedItemText != null)
            {
                testData.SelectListSelectedItemText.MatchesActual(optionElement.GetAttribute("innerText"), $"{fieldName} SelectList Selected Item Text");
            }

            // Return here is there's no validation label associated with the control
            if (null == validationLabelElement)
            {
                return;
            }

            testData.UpdateCssForValidationLabel(testData.ValidationLabelClasses, updateCssTo).MatchesActualCss(validationLabelElement.GetAttribute("class"), $"{fieldName} Validation Label Classes");

            // We only check the validation if it's displayed
            if (validationLabelElement.Displayed)
            {
                testData.ValidationLabelText.MatchesActual(validationLabelElement.Text, $"{fieldName} Validation Label Text");
            }
        }
Example #6
0
        /// <summary>
        /// Verfiy the materialize fields state when the page is loaded
        /// </summary>
        /// <param name="headerContainer">The materialize header container that is used to get the elements that need to be checked</param>
        /// <param name="bodyContainer">The materialize body container that is used to get the elements that need to be checked</param>
        /// <param name="testData">The test data to be used for the comparision</param>
        /// <param name="updateCssTo">The css style required, the field will have it's css updated to this type</param>
        /// <param name="wait">A wait used to wait for the collapse animation to complete</param>
        public static void VerifyMaterializeCollapse(IWebElement headerContainer, IWebElement bodyContainer, MaterializeCollapse testData, FieldCss updateCssTo, WebDriverWait wait)
        {
            IWebElement iconElement   = null;
            IWebElement headerText    = null;
            IWebElement imageElement  = null;
            IWebElement bodyTitleText = null;
            IWebElement bodyText      = null;

            GetHeaderElements(headerContainer, ref iconElement, ref headerText);
            GetBodyElements(bodyContainer, ref imageElement, ref bodyTitleText, ref bodyText);

            testData.UpdateCssForCollapse(testData.HeaderCss, updateCssTo).MatchesActual(headerContainer.GetAttribute("class"), "Header Classes");

            testData.HeaderIconClasses.MatchesActual(iconElement.GetAttribute("class"), "Header Icon Classes");
            testData.HeaderIconText.MatchesActual(iconElement.Text, "Header Icon Text");
            testData.HeaderTitleText.MatchesActual(headerText.Text, "Header Title Text");

            testData.BodyCss.MatchesActual(bodyContainer.GetAttribute("class"), "Body Css Classes");

            if (updateCssTo == FieldCss.Active)
            {
                // Wait for the animation to finish
                wait.Until(ExpectedConditions.TextToBePresentInElement(bodyTitleText, testData.InformationTitleText));

                testData.InformationTitleText.MatchesActual(bodyTitleText.Text, "Body Title Text");
                testData.InformationImage.MatchesActual(imageElement.GetAttribute("src"), "Body Image Src");
                testData.InformationBodyText.MatchesActual(bodyText.Text, "Body Text");
            }
            else if (updateCssTo == FieldCss.Initial)
            {
                // Wait for the animation to finish
                wait.Until(ExpectedConditions.InvisibilityOfElementLocated(By.Id(testData.CollapseWaitForId)));

                Assert.IsFalse(bodyTitleText.Displayed, $"The Body Title for {testData.InformationTitleText} should be hidden");
                Assert.IsFalse(imageElement.Displayed, $"The Body Image for {testData.InformationImage} should be hidden");
                Assert.IsFalse(bodyText.Displayed, $"The Body Text for {testData.InformationBodyText} should be hidden");
            }
        }
        /// <summary>
        /// Verfiy the materialize fields state when the page is loaded
        /// </summary>
        /// <param name="inputGroupContainer">The materialize input group container that is used to get the elements that need to be checked</param>
        /// <param name="testData">The test data to be used for the comparision</param>
        /// <param name="updateCssTo">The css style required, the field will have it's css updated to this type</param>
        public static void VerifyMaterializeInputField(IWebElement inputGroupContainer, MaterializeInputGroup testData, FieldCss updateCssTo, string validationType = null)
        {
            IWebElement iconElement            = null;
            IWebElement inputElement           = null;
            IWebElement labelElement           = null;
            IWebElement validationLabelElement = null;
            string      fieldName = null;

            GetMaterializeWebElements(inputGroupContainer, ref iconElement, ref inputElement, ref labelElement, ref validationLabelElement, ref fieldName, testData.FieldInputType);

            testData.UpdateCssForIcon(testData.IconClasses, updateCssTo).MatchesActualCss(iconElement.GetAttribute("class"), $"{fieldName} Icon Classes");
            testData.IconText.MatchesActual(iconElement.Text, $"{fieldName} Icon Text");

            if (testData.InputClasses != null)
            {
                testData.UpdateCssForInput(testData.InputClasses, updateCssTo).MatchesActualCss(inputElement.GetAttribute("class"), $"{fieldName} Input Classes");
            }

            if (testData.InputText != null)
            {
                testData.InputText.MatchesActual(testData.FieldInputType.Equals("textarea", StringComparison.OrdinalIgnoreCase) ? inputElement.GetAttribute("value") : inputElement.GetAttribute("value"), $"{fieldName} Input Text");
            }

            if (testData.LabelClasses != null)
            {
                testData.UpdateCssForLabel(testData.LabelClasses, updateCssTo).MatchesActualCss(labelElement.GetAttribute("class"), $"{fieldName} Label Classes");
            }

            if (testData.LabelText != null)
            {
                testData.LabelText.MatchesActual(labelElement.Text, $"{fieldName} Label Text");
            }

            // Return here is there's no validation label associated with the control
            if (null == validationLabelElement)
            {
                return;
            }

            testData.UpdateCssForValidationLabel(testData.ValidationLabelClasses, updateCssTo).MatchesActualCss(validationLabelElement.GetAttribute("class"), $"{fieldName} Validation Label Classes");

            // We only check the validation if it's displayed
            var validationElement = validationLabelElement.FindElement(By.TagName("span"));

            if (validationElement != null && validationType != null)
            {
                testData.ValidationLabelText[validationType].MatchesActual(validationElement.GetAttribute("textContent"), $"{fieldName} Validation Label Text");
            }
        }