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 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 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 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 IWebElement ExpandRootElement(IWebDriver driver, IWebElement element) { var message = $"Looking for shadowRoot for element {element.TagName}"; var ele = (IWebElement)((IJavaScriptExecutor)driver) .ExecuteScript("return arguments[0].shadowRoot", element); if (ele == null) { LoggingHelper.LogExceptionAndThrow($"FAIL - {message}"); } return(ele); }
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"); } }
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 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); }
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"); }
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); }
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); }
public static void ElementsNotFoundLogAndThrow(string locatorReference, Exception e) { LoggingHelper.LogExceptionAndThrow( $"Elements: {locatorReference} - was not found due to Exception: {e}"); }