Exemple #1
0
        /// <summary>
        /// Select a specified value from a specified drop down
        /// There is redundant logic in this method so that if the specified text is not found in its entirety,
        /// it will search for an element that contains the specified text.
        /// If now option in the drop down is found, an error will be logged and an exception thrown to stop the test.
        /// </summary>
        /// <param name="element">The drop down to use</param>
        /// <param name="expectedValue">The value to select</param>
        public static void SelectFromDropDown(IWebElement element, string expectedValue)
        {
            if (expectedValue == null)
            {
                return;
            }
            var recievedValue = DoSelect(element, expectedValue);

            if (recievedValue != expectedValue)
            {
                if (recievedValue.Contains(expectedValue))
                {
                    return;
                }
                LogFunctions.WriteWarning("Selected element not as expected. Recieved: " + recievedValue + " should have been: " + expectedValue);
                LogFunctions.WriteWarning("Attempting select one more time.");
                recievedValue = DoSelect(element, expectedValue);
                if (recievedValue != expectedValue)
                {
                    LogFunctions.WriteError("Selected element not as expected. Recieved: " + recievedValue + " should have been: " + expectedValue);
                    throw new Exception("Selected element not as expected");
                }
                LogFunctions.WriteInfo(expectedValue + " has been selected.");
            }
            else
            {
                LogFunctions.WriteInfo(expectedValue + " has been selected.");
            }
        }
Exemple #2
0
        /// <summary>
        /// This method will type a specified value into a specified text box element
        /// Error checking and validation are done to ensure that the expected value has been typed correctly into the text box
        /// If the text is unable to be entered into the text box, errors are written and an exception is thrown to stop the test
        /// </summary>
        /// <param name="element">The text box to type into</param>
        /// <param name="expectedValue">The text that should be entered</param>
        public static void Type(IWebElement element, string expectedValue)
        {
            if (expectedValue == null)
            {
                LogFunctions.WriteError("Did not get an expected value!");
                return;
            }
            if (expectedValue == "blank")
            {
                expectedValue = "";
            }
            Browser.WaitForElementDisplayed(element);
            Browser.WaitForElementEnabled(element);
            element.Click();
            element.Clear();
            element.SendKeys(expectedValue.Replace("%", "").Trim());
            element.SendKeys(Keys.Tab);
            string recievedValue = element.GetAttribute("value");

            if (recievedValue != expectedValue)
            {
                LogFunctions.WriteWarning("Element value not as expected. Recieved: " + recievedValue + " should have been: " + expectedValue);
                throw new Exception("Typed element not as expected");
            }
            LogFunctions.WriteInfo(expectedValue + " has been typed into the element.");
        }
Exemple #3
0
 /// <summary>
 /// The Checkbox method provides the ability to check or uncheck a checkbox and validate that it is set correctly
 /// based on the expected value that is passed in
 /// </summary>
 /// <param name="element">The checkbox element</param>
 /// <param name="turnOn">True if the checkbox should be checked, false if the checkbox should be unchecked</param>
 /// <returns>True if the checkbox is set as expected, false if it is not set as expected</returns>
 public static bool Checkbox(IWebElement element, bool turnOn)
 {
     if (!element.Displayed)
     {
         return(false);
     }
     if (!element.Enabled)
     {
         return(false);
     }
     if (element.Selected && turnOn)
     {
         LogFunctions.WriteWarning("Checkbox already selected.  No changes made");
         return(element.Selected);
     }
     if (element.Selected && !turnOn)
     {
         LogFunctions.WriteInfo("Checkbox has been un-selected.");
         element.Click();
         return(!element.Selected);
     }
     if (!element.Selected && turnOn)
     {
         LogFunctions.WriteInfo("Checkbox has been selected.");
         element.Click();
         return(element.Selected);
     }
     if (!element.Selected && !turnOn)
     {
         LogFunctions.WriteWarning("Checkbox already not selected.  No changes made");
         return(!element.Selected);
     }
     LogFunctions.WriteError("Checkbox error"); Browser.TakeScreenshot("CheckboxStatusError");
     return(false);
 }
 public static void Quit()
 {
     _webDriver.Close();
     _webDriver.Quit();
     foreach (var pid in _pid)
     {
         try
         {
             Process.GetProcessById(pid);
         }
         catch (ArgumentException)
         {
             LogFunctions.WriteInfo("Process " + pid + " completed sucessfully.");
             continue;
         }
         try
         {
             var handle = Process.GetProcessById(pid).MainWindowHandle;
             if (handle.ToInt32() == 0)
             {
                 LogFunctions.WriteWarning("Waiting for Process " + pid + " to complete on its own." + DateTime.Now);
                 Process.GetProcessById(pid).WaitForExit(300000);
                 LogFunctions.WriteWarning("Wait completed: " + DateTime.Now);
                 try { Process.GetProcessById(pid); }
                 catch (ArgumentException)
                 {
                     LogFunctions.WriteInfo("Process " + pid + " completed sucessfully.");
                     continue;
                 }
                 Process.GetProcessById(pid).Kill();
                 throw new ApplicationException("Manually killed this process");
             }
         }
         catch (InvalidOperationException)
         {
             try
             {
                 Process.GetProcessById(pid).Kill();
                 throw new ApplicationException("Invalid Operation - Manually killed this process");
             }
             catch (ArgumentException) { LogFunctions.WriteInfo("Process " + pid + " completed sucessfully on second try."); }
         }
     }
 }