Ejemplo n.º 1
0
 internal PageElementSteps(WebBrowser webBrowser, PageElement pageElement, string stepNamePrefix, bool click = false)
 {
     this.pageElement    = pageElement;
     this.webBrowser     = webBrowser;
     this.stepNamePrefix = stepNamePrefix;
     this.click          = click;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends keys (enters text) to the provided page element
        /// using the text you provide.
        /// </summary>
        /// <param name="element">The element you want to send the keys to.</param>
        /// <param name="text">The text you want to send.</param>
        public void SendKeys(PageElement element, string text)
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            IWebElement webElement = driver.FindElement(OpenQA.Selenium.By.CssSelector(element.Selector));

            webElement.SendKeys(text);
            sw.Stop();
            System.Diagnostics.Trace.WriteLine($"        SendKeys '{text}' ({sw.ElapsedMilliseconds.ToString()}ms): {element.Selector}");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Clicks the page element you provide.
        /// </summary>
        /// <param name="element">Page element to click.</param>
        public void Click(PageElement element)
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            IWebElement webElement = driver.FindElement(OpenQA.Selenium.By.CssSelector(element.Selector));

            webElement.Click();
            sw.Stop();
            System.Diagnostics.Trace.WriteLine("        Click (" + sw.ElapsedMilliseconds.ToString() + "ms): " + element.Selector);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Waits until the provided element is visible.
        /// </summary>
        /// <param name="element">The element to check</param>
        /// <param name="waitMilliseconds">The amount of time to wait.  If not provided the system will wait the default value (2 seconds).</param>
        /// <remarks>The default wait time could be overridden.</remarks>
        /// <returns>Task for executing the operation.</returns>
        public Task WaitTillVisible(PageElement element, int waitMilliseconds = -1)
        {
            return(Task.Run(() =>
            {
                var sw = new System.Diagnostics.Stopwatch();
                sw.Start();
                if (waitMilliseconds == -1)
                {
                    waitMilliseconds = DefaultWait;
                }

                IWebElement webElement = null;
                try {
                    webElement = driver.FindElement(OpenQA.Selenium.By.CssSelector(element.Selector));
                } catch (NoSuchElementException) {
                }

                var visible = false;
                Stopwatch sw2 = new Stopwatch();
                sw2.Start();
                int passCount = 0;
                while (sw2.ElapsedMilliseconds < waitMilliseconds && visible == false)
                {
                    ++passCount;
                    if (webElement == null)
                    {
                        try {
                            webElement = driver.FindElement(OpenQA.Selenium.By.CssSelector(element.Selector));
                        } catch (NoSuchElementException) {
                        }
                    }
                    if (webElement != null)
                    {
                        if (webElement.Displayed)
                        {
                            visible = true;
                        }
                    }
                }

                if (webElement == null)
                {
                    throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") was not found.");
                }

                if (!visible)
                {
                    throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") was not visible");
                }
                sw.Stop();
                System.Diagnostics.Trace.WriteLine("        WaitTillVisible (" + sw.ElapsedMilliseconds.ToString() + "ms): " + element.Selector);
            }));
        }
Ejemplo n.º 5
0
 public void ElementHasTitle(PageElement element, string title)
 {
     IWebElement webElement = driver.FindElement(By.CssSelector(element.Selector));
     if (webElement == null)
         throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") was not found.");
     else
     {
         string titleFound = webElement.GetAttribute("title"); 
         if(titleFound != title)
            throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") did not have text '" + title + "' it was '" + titleFound + "'.");
     }
 }
Ejemplo n.º 6
0
 public void ElementStyleMatches(PageElement element, string styleRegEx)
 {
     IWebElement webElement = driver.FindElement(By.CssSelector(element.Selector));
     if (webElement == null)
         throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") was not found.");
     else
     {
         string styleFound = webElement.GetAttribute("style"); 
         if(!System.Text.RegularExpressions.Regex.Match(styleFound, styleRegEx).Success)
            throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") did not have a style that matched '" + styleRegEx + "' it was '" + styleFound + "'.");
     }
 }
Ejemplo n.º 7
0
 public void ElementHasText(PageElement element, string text)
 {
     IWebElement webElement = driver.FindElement(By.CssSelector(element.Selector));
     if (webElement == null)
         throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") was not found.");
     else
     {
         var foundText = webElement.Text;
         if(foundText.CompareTo(text) != 0)
            throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") did not have text '" + text + "' it was '" + foundText + "'.");
         
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Validates no page element exists for the selector provided.
        /// </summary>
        /// <param name="element">The element to check</param>
        public void ValidateNotExist(PageElement element)
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            var webElement = driver.FindElements(OpenQA.Selenium.By.CssSelector(element.Selector));

            if (webElement.Count != 0)
            {
                throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") was found.");
            }
            sw.Stop();
            System.Diagnostics.Trace.WriteLine("        ValidateNotExist (" + sw.ElapsedMilliseconds.ToString() + "ms): " + element.Selector);
        }
Ejemplo n.º 9
0
 public Task WaitTillNotVisible(PageElement element, int waitMilliseconds = -1)
 {
     return Task.Run(() =>
     {
         if (waitMilliseconds == -1)
             waitMilliseconds = DefaultWait;
         IWebElement webElement = driver.FindElement(By.CssSelector(element.Selector));
         if (webElement == null)
             throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") was not found.");
         var hidden = false;
         Stopwatch sw = new Stopwatch();
         sw.Start();
         while (sw.ElapsedMilliseconds < waitMilliseconds && hidden == false)
         {
             if (!webElement.Displayed)
                 hidden = true;
         }
         if (!hidden)
             throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") was not hidden.");
     });
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Returns a step that enters text into the specified page element.
 /// </summary>
 /// <param name="pageElement">The page element with the description and selector to use to find the element and set the step name.</param>
 /// <param name="waitTillVisibleMilliseconds">Overrides the default 2 second wait time to a value you set in milliseconds.</param>
 /// <param name="captureOutput">Tells the system to capture the page in the step output after the action.
 /// The system will do this by default if the step fails.</param>
 /// <returns>The step you can add to your scenario.</returns>
 public Step In(PageElement pageElement, int waitTillVisibleMilliseconds = -1, bool captureOutput = false)
 {
     return(xB.CreateAsyncStep(
                $"you enter the text '{this.text[0]}' into the {pageElement.Description} input",
                async(s) => {
         try {
             await this.browser.WaitTillVisible(pageElement, waitTillVisibleMilliseconds);
             text.ForEach(entry => {
                 this.browser.SendKeys(pageElement, entry);
             });
             if (s.Outcome == Outcome.Failed || captureOutput)
             {
                 s.Output = this.browser.GetPageSource();
                 s.OutputFormat = TextFormat.htmlpreview;
             }
         } catch (System.Exception) {
             s.Output = this.browser.GetPageSource();
             s.OutputFormat = TextFormat.htmlpreview;
             throw;
         }
     }));
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Verifies whether the provided element has the specified text.
        /// </summary>
        /// <param name="element">Element to check.</param>
        /// <param name="text">Text the element should contain.</param>
        public void ElementHasText(PageElement element, string text)
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            IWebElement webElement = driver.FindElement(OpenQA.Selenium.By.CssSelector(element.Selector));

            if (webElement == null)
            {
                throw new Exception($"The web element ({element.Description} - {element.Selector}) was not found.");
            }
            else
            {
                var foundText = webElement.Text;
                if (foundText.CompareTo(text) != 0)
                {
                    throw new Exception($"The web element ({element.Description} - {element.Selector}) did not have text '{text}' it was '{foundText}'.");
                }
            }
            sw.Stop();
            System.Diagnostics.Trace.WriteLine($"        ElementHasText ({sw.ElapsedMilliseconds.ToString()}ms): {text}");
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Verifies the provided page element has a titla attribute
        /// matching the value provided.
        /// </summary>
        /// <param name="element">The element to check.</param>
        /// <param name="title">The value the element should have for the title attribute.</param>
        public void ElementHasTitle(PageElement element, string title)
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            IWebElement webElement = driver.FindElement(OpenQA.Selenium.By.CssSelector(element.Selector));

            if (webElement == null)
            {
                throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") was not found.");
            }
            else
            {
                string titleFound = webElement.GetAttribute("title");
                if (titleFound != title)
                {
                    throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") did not have text '" + title + "' it was '" + titleFound + "'.");
                }
            }
            sw.Stop();
            System.Diagnostics.Trace.WriteLine("        ElementHasTitle (" + sw.ElapsedMilliseconds.ToString() + "ms): " + title);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Verifies the style attribute of the provided element
        /// matches the regular expression provided.
        /// </summary>
        /// <param name="element">The element to check.</param>
        /// <param name="styleRegEx">The regular expression to use.</param>
        public void ElementStyleMatches(PageElement element, string styleRegEx)
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();
            IWebElement webElement = driver.FindElement(OpenQA.Selenium.By.CssSelector(element.Selector));

            if (webElement == null)
            {
                throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") was not found.");
            }
            else
            {
                string styleFound = webElement.GetAttribute("style");
                if (!System.Text.RegularExpressions.Regex.Match(styleFound, styleRegEx).Success)
                {
                    throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") did not have a style that matched '" + styleRegEx + "' it was '" + styleFound + "'.");
                }
            }
            sw.Stop();
            System.Diagnostics.Trace.WriteLine("        ElementStyleMatches (" + sw.ElapsedMilliseconds.ToString() + "ms): " + styleRegEx);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Returns a step that enters text into the specified page element.
        /// </summary>
        /// <param name="description">The description of the page element to add to the step name.</param>
        /// <param name="selector">The select to use to find the page element.  xBDD will try for up to 2 seconds to find the visible element.</param>
        /// <param name="waitTillVisibleMilliseconds">Overrides the default 2 second wait time to a value you set in milliseconds.</param>
        /// <param name="captureOutput">Tells the system to capture the page in the step output after the action.
        /// The system will do this by default if the step fails.</param>
        /// <returns>The step you can add to your scenario.</returns>
        public Step In(string description, string selector, int waitTillVisibleMilliseconds = -1, bool captureOutput = false)
        {
            var pageElement = new PageElement(description, selector);

            return(this.In(pageElement, waitTillVisibleMilliseconds, captureOutput));
        }
Ejemplo n.º 15
0
 public void ValidateNotExist(PageElement element)
 {
     var webElement = driver.FindElements(By.CssSelector(element.Selector));
     if (webElement.Count != 0)
         throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") was found.");
 }
Ejemplo n.º 16
0
     public Task ClickWhenVisible(PageElement element, bool throwException = true, int waitMilliseconds = -1)
     {
         return Task.Run(() =>
         {
             if (waitMilliseconds == -1)
                 waitMilliseconds = DefaultWait;
             IWebElement webElement = driver.FindElement(By.CssSelector(element.Selector));
             var clicked = false;
             Stopwatch sw = new Stopwatch();
             sw.Start();
             while (sw.ElapsedMilliseconds < waitMilliseconds && clicked == false)
             {
                 if (webElement == null)
                 {
                     webElement = driver.FindElement(By.CssSelector(element.Selector));
                 }
                 if(webElement != null)
                 {
                     if (webElement.Displayed)
                     {
                         webElement.Click();
                         clicked = true;
                     }
                 }
             }
             if(throwException)
             {
                 if (webElement == null)
                     throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") was not found.");
 
                 if (!clicked)
                     throw new Exception("The web element (" + element.Description + " - " + element.Selector + ") was not visible and was not clicked");
             }
         });
     }