public static List <IWebElement> FoundElementsSuccess(List <IWebElement> elements, DateTime initialTime, string locatorReference)
        {
            var timeToLocateElement = DateTime.UtcNow - initialTime;

            LoggingHelper.Log($"Elements: {locatorReference} - Time to locate: {timeToLocateElement.TotalMilliseconds}ms, Number of Elements Found: {elements.Count}");
            return(elements);
        }
Exemple #2
0
        public static IWebElement GetShadowRoot(IWebDriver driver, List <By> locatorChain, TimeSpan maxWaitTime)
        {
            DateTime    currentTime    = DateTime.UtcNow;
            IWebElement currentElement = null;
            IWebElement currentRoot    = null;
            var         message        = "";

            foreach (var locator in locatorChain)
            {
                currentElement = null;
                while (DateTime.UtcNow < currentTime.Add(maxWaitTime))
                {
                    message = $"Expected {locator} to be found";
                    LoggingHelper.Log(message);
                    try
                    {
                        currentElement = currentRoot == null?driver.FindElement(locator) : currentRoot.FindElement(locator);

                        LoggingHelper.Log($"Pass - {message}");
                        currentRoot = ExpandRootElement(driver, currentElement);
                        break;
                    }
                    catch (NoSuchElementException)
                    {}
                }
                if (currentElement == null)
                {
                    LoggingHelper.LogExceptionAndThrow($"FAIL - {message} and was not found within timeout period of {maxWaitTime}");
                }
            }
            return(currentRoot);
        }
 public static void AssertTrue(bool result, string message)
 {
     if (!result)
     {
         LoggingHelper.LogExceptionAndThrow($"FAIL - The result was expected to be true but was false. - {message}");
     }
     LoggingHelper.Log($"PASS - The result was expected to be true and was true'- {message}.");
 }
 public static void AssertExactText(string actualText, string expectedText)
 {
     if (!string.Equals(actualText, expectedText))
     {
         LoggingHelper.LogExceptionAndThrow($"FAIL - The actual text: '{actualText}', did not equal the expected text: '{expectedText}'.");
     }
     LoggingHelper.Log($"PASS - The actual text: '{actualText}', did equal the expected text: '{expectedText}'.");
 }
 public static void AssertStringContains(string fullString, string stringToLocate)
 {
     if (!fullString.ToLower().Contains(stringToLocate.ToLower()))
     {
         LoggingHelper.LogExceptionAndThrow($"FAIL -  '{stringToLocate}' was not contained within : '{fullString}'");
     }
     LoggingHelper.Log($"PASS - '{stringToLocate}' was contained within : '{fullString}'");
 }
 public static void AssertNumber(string actualText)
 {
     if (!Regex.IsMatch(actualText, @"^\d+$"))
     {
         LoggingHelper.LogExceptionAndThrow($"FAIL - The actual text: '{actualText}', is not a number.");
     }
     LoggingHelper.Log($"PASS - The actual text: '{actualText}', is a valid number.");
 }
 public static void AreSame <T>(T expected, T actual)
 {
     if (!expected.Equals(actual))
     {
         LoggingHelper.LogExceptionAndThrow(
             $"FAIL - The actual value: '{actual}', did not equal the expected value: '{expected}'.");
     }
     LoggingHelper.Log(
         $"PASS - The actual value: '{actual}', did equal the expected value: '{expected}'.");
 }
 public static void VerifyUrlPrefix(string url)
 {
     if (!url.StartsWith("https://"))
     {
         LoggingHelper.LogExceptionAndThrow($"FAIL - https:// was not found in tableau url: {url}");
     }
     else
     {
         LoggingHelper.Log("PASS - Url did contain https:// prefix");
     }
 }
 public static void VerifyDataFieldIsNotEmpty(string propertyName, string property)
 {
     LoggingHelper.Log($"{propertyName}: {property}");
     if (property == string.Empty)
     {
         LoggingHelper.LogExceptionAndThrow($"FAIL - {propertyName} contained no data");
     }
     else
     {
         LoggingHelper.Log($"PASS - {propertyName} did contain data");
     }
 }
Exemple #10
0
 private static void ActionHandler(Actions builder, string actionText, string element)
 {
     try
     {
         builder.Build().Perform();
     }
     catch (Exception e)
     {
         LoggingHelper.LogExceptionAndThrow(
             $"FAIL - UnSuccessfull Action '{actionText}' performed on element: '{element}'. Exception: {e}");
     }
     LoggingHelper.Log($"PASS - Action '{actionText}' has been performed on '{element}'");
 }
 private static List <IWebElement> GetElements(IWebDriver driver, By locator, TimeSpan maxWaitTime)
 {
     try
     {
         return
             (new WebDriverWait(driver, maxWaitTime).Until(
                  ExpectedConditions.PresenceOfAllElementsLocatedBy(locator)).ToList());
     }
     catch (Exception e)
     {
         LoggingHelper.Log($"Exception - '{locator}' - was not found, Exception - '{e}'");
         return(null);
     }
 }
Exemple #12
0
 private static IWebElement WaitUntilClickable(IWebDriver driver, IWebElement element, string elementDescription)
 {
     try
     {
         AssertVisible(element, elementDescription);
         var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
         wait.Until(ExpectedConditions.ElementToBeClickable(element));
     }
     catch (Exception e)
     {
         LoggingHelper.LogExceptionAndThrow($"element '{elementDescription}' was not clickable. Exception: {e}");
     }
     LoggingHelper.Log($"element '{elementDescription}' is clickable");
     return(element);
 }
Exemple #13
0
        public static bool IsElementPresent(IWebDriver driver, By locator)
        {
            var message = $"checking if '{locator}' is present";

            try
            {
                driver.FindElement(locator);
                LoggingHelper.Log($"Present - {message} - returning true");
                return(true);
            }
            catch (Exception)
            {
                LoggingHelper.Log($"Not Present - {message} - returning false");
            }
            return(false);
        }
Exemple #14
0
        private static void AssertVisible(IWebElement element, string elementDescription)
        {
            LoggingHelper.Log($"Asserting element '{elementDescription}' is displayed");
            var visible = false;
            var maxWait = DateTime.UtcNow.AddSeconds(30);

            while (DateTime.UtcNow < maxWait && !visible)
            {
                visible = element.Displayed;
            }
            if (!visible)
            {
                LoggingHelper.LogExceptionAndThrow($"The element '{elementDescription}' was not displayed with in timeout period");
            }

            LoggingHelper.Log($"Element '{elementDescription}' is displayed");
        }
Exemple #15
0
        private static IWebElement GetElement(IWebDriver driver, By locator, TimeSpan maxWaitTime)
        {
            try
            {
                DateTime initialTime         = DateTime.UtcNow;
                var      el                  = new WebDriverWait(driver, maxWaitTime).Until(ExpectedConditions.ElementExists(locator));
                var      timeToLocateElement = DateTime.UtcNow - initialTime;
                LoggingHelper.Log($"Element: {locator} Time to locate: {timeToLocateElement.TotalMilliseconds}ms");
                return(el);
            }
            catch (Exception e)
            {
                LoggingHelper.LogExceptionAndThrow(
                    $"Element: {locator} - was not found due to Exception: {e}");
            }
            LoggingHelper.LogExceptionAndThrow($"Element: {locator} - was not found within timeout period: {maxWaitTime}");

            return(null);
        }
Exemple #16
0
        public static bool AssertElementIsNotDisplayed(IWebDriver driver, By locator, TimeSpan maxWaitTime)
        {
            DateTime currentTime = DateTime.UtcNow;
            var      message     = $"Expected {locator} to not be displayed";

            while (DateTime.UtcNow < currentTime.Add(maxWaitTime))
            {
                try
                {
                    driver.FindElement(locator);
                    LoggingHelper.LogExceptionAndThrow($"FAIL - {message}");
                }
                catch (NoSuchElementException)
                {
                    LoggingHelper.Log($"PASS - {message}");
                }
            }
            LoggingHelper.Log($"PASS - {message} and was not located within timeout period of {maxWaitTime}");
            return(false);
        }