コード例 #1
0
        /// <summary>
        /// Create a comma delimited string from a list of IWebElement objects
        /// </summary>
        /// <param name="searchContext">Web driver or element</param>
        /// <param name="by">By selector for the elements</param>
        /// <param name="sort">True to create an alphabetically sorted comma delimited string</param>
        /// <returns>Returns a comma delimited string</returns>
        /// <example>
        /// <code source = "../SeleniumUnitTesting/ElementHandlerUnitTests.cs" region="SortFromWebElements" lang="C#" />
        /// </example>
        public static string CreateCommaDelimitedString(this ISearchContext searchContext, By by, bool sort = false)
        {
            List <string> unsortedList = new List <string>();

            foreach (IWebElement element in searchContext.FindElements(by))
            {
                unsortedList.Add(element.Text.Trim());
            }

            return(ListProcessor.CreateCommaDelimitedString(unsortedList, sort));
        }
コード例 #2
0
        public void CreateSortedCommaDelimitedStringTest()
        {
            List <string> stringList = new List <string>();

            stringList.Add("Maine");
            stringList.Add("Massachusetts");
            stringList.Add("New Hampshire");
            stringList.Add("Connecticut");
            stringList.Add("Rhode Island");
            stringList.Add("Vermont");
            string expectedText = "Connecticut, Maine, Massachusetts, New Hampshire, Rhode Island, Vermont";

            string actualText = ListProcessor.CreateCommaDelimitedString(stringList, true);

            if (!expectedText.Equals(actualText))
            {
                Assert.Fail(StringProcessor.SafeFormatter("Expected string [{0}] does not match Actual string [{1}]", expectedText, actualText));
            }
        }