Example #1
0
        public void TestSearch_SearchQueries_ScreenshotsCreated()
        {
            // Get titles.
            string[] titles = GetTitlesFromResponseDump();

            // Get random titles or range of titles from collection.
            List <string> searchQueries = (RandomRegimeOn) ? GetRandomTitles(titles) : GetRangeOfTitles(titles);

            // Click on the Search button and wait until it expands.
            vcPageObj.SearchButton.Click();
            Thread.Sleep(WaitSearchMenuExpandingMs);

            action = new ActionsExtension(Driver);

            // Regular expression to remove invalid filename characters of screenshots.
            string invalidFileNameChars = new string(Path.GetInvalidFileNameChars());
            Regex  regex = new Regex(string.Format("[{0}]", Regex.Escape(invalidFileNameChars)));

            // For alert handling.
            IAlert alert         = null;
            bool   alertIsActive = false;

            // Enter search queries and click on them.
            foreach (string query in searchQueries)
            {
                alertIsActive = false;

                vcPageObj.EnterSearchQuery(query);
                Thread.Sleep(WaitResultsMs);

                // Move mouse arrow to result and click on it.
                WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromMilliseconds(WaitTimeOutMs));

                try
                {
                    IWebElement result = wait.Until <IWebElement>((d) =>
                    {
                        // Return dynamically created search result.
                        return(Driver.FindElement(By.XPath(SearchResultXPath)));
                    });

                    action.Click(result).Perform();
                    vcPageObj.WaitAnimation();
                }
                catch (TimeoutException)
                {
                    Console.WriteLine("NOT FOUND: " + query);
                }

                // Handling of alert messages.
                try
                {
                    alert         = Driver.SwitchTo().Alert();
                    alertIsActive = true;
                    alert.Accept();
                    Console.WriteLine("ALERT: " + query);
                }
                catch (NoAlertPresentException)
                {
                    Console.WriteLine("OK: " + query);
                }

                // Save screenshot of search result. If alert had appeared, then add special string to filename of screenshot.
                // NOTE: Uses user environment variable SELENIUM_SCR.
                if (alertIsActive)
                {
                    WebDriverScreenshotMaker.SaveScreenshot(Driver, "TestSearch", alertString + regex.Replace(query, ""), ImageFormat.Png, true);
                }
                else
                {
                    WebDriverScreenshotMaker.SaveScreenshot(Driver, "TestSearch", regex.Replace(query, ""), ImageFormat.Png, true);
                }

                action.SetDefault();
                vcPageObj.ClearSearchTextBox();
            }
        }
Example #2
0
        public void SearchLengthTest1()
        {
            //maximum length of the inbox string
            int max_length = 700;
            //offset number of literals for test
            int    offset = 10;
            string short_string = "";
            string big_string = "";
            string large_string = "";
            bool   b1, b2, b3;

            //click on searchbox and get ready to type in it
            action = new ActionsExtension(Driver);
            var element = Driver.FindElement(By.Id("search_button"));

            action.MoveToElement(element, 0, 0);
            action.Click();
            action.Perform();
            var searchTextBox = Driver.FindElement(By.Id("searchTextBox"));

            //define random strings
            short_string = RussianSymbolString(10);
            big_string   = RandomString(max_length);
            large_string = RandomString(max_length + offset);
            //Test1.regular size random english symbol string
            searchTextBox.SendKeys(short_string);
            // var searchbox_string = (Driver as IJavaScriptExecutor).ExecuteScript("return  $('#searchTextBox').val();");
            var searchbox_string = (Driver as IJavaScriptExecutor).ExecuteScript("return searchString;");

            b1 = searchbox_string.Equals(short_string);
            vcPageObj.ClearSearchTextBox();
            Trace.Write(b1);        //must be true
            //Test2.boundary maxsize size english random symbol string
            char[] c = new char[1];
            for (int i = 0; i <= max_length - 1; i++)
            {
                c[0] = big_string[i];
                string s = new string(c);
                searchTextBox.SendKeys(s);
            }
            //searchbox_string = (Driver as IJavaScriptExecutor).ExecuteScript("return  $('#searchTextBox').val();");
            searchbox_string = (Driver as IJavaScriptExecutor).ExecuteScript("return searchString;");
            b2 = searchbox_string.Equals(big_string);
            vcPageObj.ClearSearchTextBox();
            Trace.Write(b2);        //must be true
            //Test3.large maxsize+offset size english random symbol string(doesn't fit in searchbox)

            for (int i = 0; i <= max_length + offset - 1; i++)
            {
                c[0] = large_string[i];
                string s = new string(c);
                searchTextBox.SendKeys(s);
            }
            searchbox_string = (Driver as IJavaScriptExecutor).ExecuteScript("return searchString;");
            bool   b31        = searchbox_string.Equals(large_string); //false
            string cut_string = large_string.Remove(max_length);
            bool   b32        = searchbox_string.Equals(cut_string);   //true

            vcPageObj.ClearSearchTextBox();
            b3 = (!b31) && b32;
            Trace.Write(b31);
            Trace.Write(b32);
            Trace.Write(b3);        //must be true
            //Test4.large maxsize+offset size random symbol string(doesn't fit in searchbox)
            bool b = b1 & b2 & b3;

            Assert.IsTrue(b);
            return;
        }