Beispiel #1
0
 public static void EndAutomation()
 {
     extent.EndTest(test);
     extent.Flush();
     System.Diagnostics.Process.Start(Report.reportPath);
     WriteConsole.Green("Automation has succeeded");
 }
Beispiel #2
0
 public static void ClickOnIt(this IWebElement element, string elementName)
 {
     if (elementName == null)
     {
         Report.Log(LogStatus.Fail, "Click", String.Format("[{0}] : clicked", elementName));
     }
     else
     {
         element.Click();
         WriteConsole.Cyan(String.Format("[{0}] : clicked", elementName));
         Report.Log(LogStatus.Pass, "Click", String.Format("[{0}] : clicked", elementName));
     }
 }
Beispiel #3
0
 public static void SelectByValue(this IWebElement element, string elementName, string text)
 {
     if (elementName == null)
     {
         Report.Log(LogStatus.Fail, "Select Dropdown", String.Format("[{0}] : select [{1}]", elementName, text));
     }
     else
     {
         SelectElement oSelect = new SelectElement(element);
         oSelect.SelectByValue(text);
         WriteConsole.Cyan(String.Format("[{0}] : select [{1}]", elementName, text));
         Report.Log(LogStatus.Pass, "Select Dropdown", String.Format("[{0}] : select [{1}]", elementName, text));
     }
 }
Beispiel #4
0
 public static void EnterText(this IWebElement element, string elementName, string text)
 {
     if (elementName == null)
     {
         Report.Log(LogStatus.Fail, "EnterText", String.Format("[{0}] : key in [{1}]", elementName, text));
     }
     else
     {
         element.Clear();
         element.SendKeys(text);
         WriteConsole.Cyan(String.Format("[{0}] : key in [{1}]", elementName, text));
         Report.Log(LogStatus.Pass, "EnterText", String.Format("[{0}] : key in [{1}]", elementName, text));
     }
 }
Beispiel #5
0
 public static void MouseOverThenClick(this IWebElement element, IWebDriver driver, string elementName)
 {
     if (elementName == null)
     {
         Report.Log(LogStatus.Fail, "MouseOverThenClick", String.Format("[{0}] : Hovered then click", elementName));
     }
     else
     {
         Actions action = new Actions(driver);
         //Hover Element
         action.MoveToElement(element).Click().Perform();     //action.MoveToElement(element).Click().Perform(); //hover then click
         WriteConsole.Cyan(String.Format("[{0}] : Hovered then click", elementName));
         Report.Log(LogStatus.Pass, "MouseOverThenClick", String.Format("[{0}] : Hovered then click", elementName));
     }
 }
Beispiel #6
0
        public static bool IsDisplayed(this IWebElement element, string elementName)
        {
            bool result;

            try
            {
                result = element.Displayed;
                WriteConsole.Cyan(String.Format("[{0}] : Displayed", elementName));
                Report.Log(LogStatus.Pass, "IsDisplayed", String.Format("[{0}] : Displayed", elementName));
            }
            catch (Exception)
            {
                result = false;
                WriteConsole.Cyan(String.Format("[{0}] : not Displayed", elementName));
                Report.Log(LogStatus.Fail, "IsDisplayed", String.Format("[{0}] : not Displayed", elementName));
            }

            return(result);
        }
Beispiel #7
0
        public static bool Alert(this IWebDriver driver, int seconds = 20)
        {
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(seconds));

            try
            {
                wait.Until(ExpectedConditions.AlertIsPresent());
                //element = driver.FindElement(by);
                WriteConsole.DarkCyan(String.Format("Element found --> {0}"));
                Report.Log(LogStatus.Pass, "Check Alert Box", String.Format("Element found --> {0}"));
                return(true);
            }
            catch (Exception e)
            {
                WriteConsole.DarkMagenta(String.Format("Exception of checking visable : {0} [{1}]", "alert", e.Message.ToString()));
                Report.Log(LogStatus.Warning, "Check Alert Box", String.Format("Exception of checking visable : {0} [{1}]", "alert", e.Message.ToString()));
                return(false);
            }
        }
Beispiel #8
0
        public static IWebElement PresenceAll(this IWebDriver driver, By by, int seconds = 20)
        {
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(seconds));
            IWebElement   element;

            try
            {
                wait.Until(ExpectedConditions.PresenceOfAllElementsLocatedBy(by));
                element = driver.FindElement(by);
                WriteConsole.DarkCyan(String.Format("Element found --> {0}", by.ToString()));
                Report.Log(LogStatus.Pass, "Check Element PresenceAll", String.Format("Element found --> {0}", by.ToString()));
                return(element);
            }
            catch (Exception e)
            {
                WriteConsole.DarkMagenta(String.Format("Exception of checking visable : {0} [{1}]", by.ToString(), e.Message.ToString()));
                Report.Log(LogStatus.Warning, "Check Element PresenceAll", String.Format("Exception of Wait : {0} [{1}]", by.ToString(), e.Message.ToString()));
                return(null);
            }
        }
Beispiel #9
0
        // Will wait for seconds by default
        public static IWebElement Exist(this IWebDriver driver, By by)
        {
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
            IWebElement   element;

            try
            {
                wait.Until(ExpectedConditions.ElementExists(by));
                element = driver.FindElement(by);
                WriteConsole.DarkCyan(String.Format("Element found --> {0}", by.ToString()));
                Report.Log(LogStatus.Pass, "Check Element Exist", String.Format("Element found --> {0}", by.ToString()));
                return(element);
            }
            catch (Exception e)
            {
                WriteConsole.DarkMagenta(String.Format("Exception of Wait : {0} [{1}]", by.ToString(), e.Message.ToString()));
                Report.Log(LogStatus.Warning, "Check Element Exist", String.Format("Exception of Wait : {0} [{1}]", by.ToString(), e.Message.ToString()));
                return(null);
            }
        }