internal static IWebElement PeekElement(this IWebDriver driver, WebElement webElement, int seconds = 1) { using (ImplicitWaitContext.Create(TimeSpan.FromSeconds(seconds))) { return webElement.Element; } }
public static bool RegisterTrigger(Type page, WebElement webElement) { lock (NavigationTriggers) { var newlyAdded = !NavigationTriggers.ContainsKey(page); NavigationTriggers[page] = webElement; return newlyAdded; } }
public MyBeazleyLoginPage(IWebDriver driver, string title = null, string url = null, ContainerWebElement parentContainer = null) : base(driver, "myBeazley UAT", url, parentContainer) { //Beazley Link LinkLogoBeazley = new LinkWebElement<MyBeazleyLoginPage>("LinkLogoBeazley", this); //Privacy links - RB_PrivacyLinks PrivacyLinks = new LinkWebElement<MyBeazleyLoginPage>("PrivacyLinks", this); //Privacy links - RB_PrivacyLinks TcPrivacyLinks = new LinkWebElement<MyBeazleyLoginPage>("TC_PrivacyLinks", this); //Privacy links - RB_PrivacyLinks PcPrivacyLinks = new LinkWebElement<MyBeazleyLoginPage>("PC_PrivacyLinks", this); //Header logo HeaderLogo = new WebElement("HeaderLogo", this); //myBeazley right image BeazleyRightImage = new LinkWebElement<MyBeazleyLoginPage>("BeazleyRightImage", this); //Sign in title label TitleLabelLogin = new WebElement("TitleLabelLogin", this); //Sign in Submit BtnSignIn = new LinkWebElement<MyBeazleyHomePage>("BtnSignIn", this); //Sign in Submit FailedBtnSignIn = new WebElement("BtnSignIn", this); //Username field and label //UsernameField = new WebElement(Locator.Create(With.Id, "UsernameField"), this); UsernameField = new WebElement("UsernameField", this); UsernameLabel = new WebElement("UsernameLabel", this); //Password Field and label PasswordField = new WebElement("PasswordField", this); PasswordLabel = new WebElement("PasswordLabel", this); //Forgotten your password? ForgottenPassword = new LinkWebElement<MyBeazleyLoginPage>("ForgottenPassword", this); //DdlSelectLanguage = new SelectWebElement(Locator.Create(With.Id, "searchlang"), this); LanguageLocator = new WebElement("LanguageLocator", this); ErrorLoginMessage = new WebElement("ErrorLoginMessage", this); EmptyUsernameError = new WebElement("EmptyUsernameError", this); //loginerror }
public static Func<IWebDriver, bool> ExpectedConditions_ElementExists(WebElement webElement) { return driver => TryAction(driver, webElement.Identifier, "ExpectedConditions_ElementExists", (seleniumDriver, elementLocator, actionName) => { IWebElement targetElement = driver.PeekElement(webElement); var elementWasFound = targetElement != null; if (!elementWasFound) { LogElemNotFound(); } Log.Info(string.Format("{0} {1} = {2}", actionName, webElement.Identifier, elementWasFound)); return elementWasFound; }); }
public static Func<IWebDriver, bool> ExpectedConditions_ElementIsNotVisible(WebElement webElement) { return driver => TryAction(driver, webElement.Identifier, "ExpectedConditions_ElementIsNotVisible", (seleniumDriver, elementLocator, actionName) => { IWebElement targetElement = driver.PeekElement(webElement); if (targetElement == null) { LogElemNotFound(); return false; } bool result = !targetElement.Displayed; Log.Info(string.Format("{0} {1} = {2}", actionName, webElement.Identifier, result)); return result; }); }
public static Func<IWebDriver, bool> ExpectedConditions_ElementIsVisible(WebElement webElement) { return driver => TryAction(driver, webElement.Identifier, "ExpectedConditions_ElementIsVisible", (seleniumDriver, elementLocator, actionName) => { IWebElement targetElement = driver.PeekElement(webElement); if (targetElement == null) { LogElemNotFound(); return false; } bool result; using (ImplicitWaitContext.Create(TimeSpan.FromSeconds(1))) { result = targetElement.Displayed; } Log.Info(string.Format("{0} {1} = {2}", actionName, webElement.Identifier, result)); return result; }); }
public MyBeazleyHomePage(IWebDriver driver, string title, string url, ContainerWebElement parentContainer = null) : base(driver, "myBeazley UAT - Quotes", url, parentContainer) //ova e title { SignOutButton = new LinkWebElement<MyBeazleyLoginPage>("logoff", this); }
public ElementNotPresentException(WebElement webElement) : base(string.Format("Element {0} no longer exists on page", webElement)) { }
public static WaitElementHelper Element(WebElement element) { return new WaitElementHelper(element); }
public static Func<IWebDriver, bool> ExpectedConditions_TextNotPresent(WebElement webElement, string text) { return driver => TryAction(driver, webElement.Identifier, "ExpectedConditions_TextPresent", (seleniumDriver, elementLocator, actionName) => { IWebElement targetElement = driver.PeekElement(webElement); var elementDoesNotExist = targetElement == null; if (elementDoesNotExist) { LogElemNotFound(); throw new ElementNotPresentException(webElement); } string elementValue = targetElement.GetAttribute("value") ?? targetElement.Text ?? string.Empty; bool textIsNotPresent = !elementValue.ToLowerInvariant().Contains(text.ToLowerInvariant()); Log.Info(string.Format("{0} -> {1} value {2} contains {3} = {4}", actionName, webElement.Identifier, elementValue, text, textIsNotPresent)); return textIsNotPresent; }); }
public static Func<IWebDriver, bool> ExpectedConditions_ElementIsNotEnabled(WebElement webElement) { return driver => TryAction(driver, webElement.Identifier, "ExpectedConditions_ElementIsExists", (seleniumDriver, elementLocator, actionName) => { IWebElement targetElement = driver.PeekElement(webElement); var elementDoesNotExist = targetElement == null; if (elementDoesNotExist) { LogElemNotFound(); return false; } Log.Info(string.Format("Chek if enabled for : {0}", webElement.Identifier)); var disabledAttributeValue = targetElement.GetAttribute("disabled"); if (!String.IsNullOrEmpty(disabledAttributeValue) && (disabledAttributeValue.Equals("true"))) return true; bool notEnabled = !targetElement.Enabled; Log.Info(string.Format("{0} {1} = {2}", actionName, webElement.Identifier, notEnabled)); return notEnabled; }); }
public static Func<IWebDriver, bool> ExpectedConditions_IsVisibleAndEnabled(WebElement webElement) { return driver => TryAction(driver, webElement.Identifier, "ExpectedConditions_IsVisibleAndEnabled", (seleniumDriver, elementLocator, actionName) => { IWebElement targetElement = driver.PeekElement(webElement); var elementExists = targetElement != null; Log.Info(string.Format("{0} {1} = {2}", actionName, webElement.Identifier, elementExists)); if (!elementExists) { LogElemNotFound(); return false; } Log.Info(string.Format("VisibleEnabled test for {0}", webElement.Identifier)); var displayed = targetElement.Displayed; bool enabled; var disabledAttributeValue = targetElement.GetAttribute("disabled"); if (!String.IsNullOrEmpty(disabledAttributeValue) && (disabledAttributeValue.Equals("true"))) enabled = false; else enabled = targetElement.Enabled; Log.Info(string.Format("VisibleEnabled test - displayed:{0}, enabled:{1}", displayed, enabled)); var result = displayed && enabled; Log.Info(String.Format("{0} -> visibleEnabled test for {1} was {2}!", actionName, webElement.Identifier, result ? "successful" : "not successful")); return result; }); }
public static Func<IWebDriver, bool> ExpectedConditions_IsNotStale(WebElement webElement) { return driver => TryAction(driver, webElement.Identifier, "ExpectedConditions_IsNotStale", (seleniumDriver, elementLocator, actionName) => { IWebElement targetElement = driver.PeekElement(webElement); var elementExists = targetElement != null; Log.Info(string.Format("{0} {1} = {2}", actionName, webElement.Identifier, elementExists)); if (!elementExists) { LogElemNotFound(); return false; } bool result; switch (targetElement.TagName.ToLower()) { case "input": case "a": case "img": case "select": case "option": case "button": case "tr": case "td": { Log.Info(string.Format("Stale test for {0}", webElement.Identifier)); var displayed = targetElement.Displayed; bool enabled; var disabledAttributeValue = targetElement.GetAttribute("disabled"); if (!String.IsNullOrEmpty(disabledAttributeValue) && (disabledAttributeValue.Equals("true"))) enabled = false; else enabled= targetElement.Enabled; Log.Info(string.Format("Stale test - displayed:{0}, enabled:{1}", displayed, enabled)); result = displayed && enabled; } break; default: { // stale test for non-buttons Log.Info("Stale test for non-clickable element."); targetElement.Click(); result = true; } break; } Log.Info(String.Format("{0} -> stale test for {1} was {2}!", actionName, webElement.Identifier, result ? "successful" : "not successful")); return result; }); }
public WaitElementHelper(WebElement element) : base(true) { WebElement = element; }