public static void ClearAndTypeInTextBox(this IWebElement element, string text) { SeleniumGetMethods.GetElement(element); element.Clear(); element.SendKeys(text); Reporter.AddTestInfo(ProjectUtilities.Utilities.GetCurrentMethod() + " => " + "Elemento encontrado: " + element.GetElementAttribute() + " - Valor preenchido: " + text); }
protected string GetValue(By locator) { string text = WaitForElement(locator).GetAttribute("value"); Reporter.AddTestInfo(3, "RETURN: " + text); return(text); }
protected string GetText(By locator) { string text = WaitForElement(locator).Text; Reporter.AddTestInfo(3, "RETURN: " + text); return(text); }
protected void MouseOver(By locator) { Actions action = new Actions(driver); action.MoveToElement(WaitForElement(locator)).Build().Perform(); Reporter.AddTestInfo(3, ""); }
public static void CheckboxChecked(this IWebElement element) { SeleniumGetMethods.GetElement(element); Reporter.AddTestInfo(ProjectUtilities.Utilities.GetCurrentMethod() + " => " + "Elemento encontrado: " + element.GetElementAttribute()); element.Click(); }
protected void ClickJavaScript(By locator) { wait.Until(ExpectedConditions.ElementExists(locator)); IWebElement element = driver.FindElement(locator); javaScriptExecutor.ExecuteScript("arguments[0].click();", element); Reporter.AddTestInfo(3, ""); }
protected void SendKeysJavaScript(By locator, string value) { wait.Until(ExpectedConditions.ElementExists(locator)); IWebElement element = driver.FindElement(locator); javaScriptExecutor.ExecuteScript("arguments[0].value='" + value + "';", element); Reporter.AddTestInfo(3, "PARAMETER: " + value); }
public string GetTitle() { string title = driver.Title; Reporter.AddTestInfo(2, "RETURN: " + title); return(title); }
protected bool ReturnIfElementIsSelected(By locator) { wait.Until(ExpectedConditions.ElementExists(locator)); bool result = driver.FindElement(locator).Selected; Reporter.AddTestInfo(3, "RETURN: " + result); return(result); }
protected bool ReturnIfElementsAreDisplayed(By locator) { wait.Until(ExpectedConditions.PresenceOfAllElementsLocatedBy(locator)); bool result = driver.FindElement(locator).Displayed; Reporter.AddTestInfo(3, "RETURN: " + result); return(result); }
protected void SendKeysWithoutWaitVisible(By locator, string text) { wait.Until(ExpectedConditions.ElementExists(locator)); IWebElement element = driver.FindElement(locator); element.SendKeys(text); Reporter.AddTestInfo(3, "PARAMETER: " + text); }
protected void ScrollToElementJavaScript(By locator) { wait.Until(ExpectedConditions.ElementExists(locator)); IWebElement element = driver.FindElement(locator); javaScriptExecutor.ExecuteScript("arguments[0].scrollIntoView(true);", element); Reporter.AddTestInfo(3, ""); }
public string GetURL() { string url = driver.Url; Reporter.AddTestInfo(2, "RETURN: " + url); return(url); }
public static void NavigateToPage(string url) { try { WebdriverHooks.Driver.Navigate().GoToUrl(url); Reporter.AddTestInfo(ProjectUtilities.Utilities.GetCurrentMethod() + " => " + "Acessando a página: " + url); } catch { } }
public static void AssertElementNotPresent(By locator) { try { Assert.False(WebdriverHooks.Driver.FindElement(locator).Displayed); Reporter.AddTestInfo(ProjectUtilities.Utilities.GetCurrentMethod() + " => " + "Elemento encontrado: " + locator); } catch (Exception ex) { Assert.Fail("{0} Element displayed", ex); } }
public static void AssertElementContainsText(IWebElement element, string text) { try { Assert.That(element.Text.Contains(text)); Reporter.AddTestInfo(ProjectUtilities.Utilities.GetCurrentMethod() + " => " + "Elemento encontrado: " + element.GetElementAttribute() + " - Valor: " + text); } catch (Exception ex) { Assert.Fail("{0} Text at element NOT CONTAINS expected text", ex); } }
public static void AssertValueInElement(IWebElement element, string value) { try { Assert.That(element.GetAttribute("value") == value); Reporter.AddTestInfo(ProjectUtilities.Utilities.GetCurrentMethod() + " => " + "Elemento encontrado: " + element.GetElementAttribute()); } catch (Exception ex) { Assert.Fail("{0} Value at element NOT EQUAL", ex); } }
protected bool ReturnIfElementExists(By locator) { try { bool result = driver.FindElement(locator).Displayed; Reporter.AddTestInfo(3, "RETURN: " + result); return(true); } catch { return(false); } }
public static void SelectText(this IWebElement element, string text) { SeleniumGetMethods.GetElement(element); if (text.HasValue()) { new SelectElement(element).SelectByText(text); Reporter.AddTestInfo(ProjectUtilities.Utilities.GetCurrentMethod() + " => " + "Elemento encontrado: " + element.GetElementAttribute() + " - Valor selecionado: " + text); } else { Reporter.AddTestInfo(ProjectUtilities.Utilities.GetCurrentMethod() + " => " + "Elemento encontrado: " + element.GetElementAttribute() + " - Valor selecionado: [NENHUM]"); } }
public static void TypeInTextBox(this IWebElement element, string text) { SeleniumGetMethods.GetElement(element); if (text.HasValue()) { element.SendKeys(text); Reporter.AddTestInfo(ProjectUtilities.Utilities.GetCurrentMethod() + " => " + "Elemento encontrado: " + element.GetElementAttribute() + " - Valor preenchido: " + text); } else { Reporter.AddTestInfo(ProjectUtilities.Utilities.GetCurrentMethod() + " => " + "Elemento encontrado: " + element.GetElementAttribute() + " - Valor preenchido: [VAZIO]"); } }
public static void AssertElementDisplayed(IWebElement element) { try { if (SeleniumGetMethods.GetElement(element)) { Assert.That(element.Displayed); Reporter.AddTestInfo(ProjectUtilities.Utilities.GetCurrentMethod() + " => " + "Elemento encontrado: " + element.GetElementAttribute()); } } catch (Exception ex) { Assert.Fail("{0} Element no displayed", ex); } }
public static void AssertTextInElement(IWebElement element, string text) { WaitHelpers.WaitForElementHelpers.WaitForElementClickable(element); Assert.That(element.Text == text); Reporter.AddTestInfo(ProjectUtilities.Utilities.GetCurrentMethod() + " => " + "Elemento encontrado: " + element.GetElementAttribute() + " - Valor: " + text); //try //{ // Assert.That(element.Text == text); // Reporter.AddTestInfo(ProjectUtilities.Utilities.GetCurrentMethod() + " => " + "Elemento encontrado: " + element.GetElementAttribute() + " - Valor: "+ text); //} //catch (Exception ex) //{ // Assert.Fail("{0} Text at element NOT EQUAL", ex); //} }
public static bool GetElement(IWebElement element) { try { if (element.Displayed || element.Enabled) { return(true); } return(false); } catch (NoSuchElementException ex) { Reporter.AddTestInfo(ProjectUtilities.Utilities.GetCurrentMethod() + " => " + "ERRO! Elemento esperado não apareceu." + "<pre>" + ex.Message + "</pre>"); Reporter.TestException(ex); Assert.IsTrue(false); return(false); } }
protected void Click(By locator) { Stopwatch timeOut = new Stopwatch(); timeOut.Start(); while (timeOut.Elapsed.Seconds <= Convert.ToInt32(ConfigurationManager.AppSettings["Default.DEFAULT_TIMEOUT_IN_SECONDS"])) { try { WaitForElement(locator).Click(); timeOut.Stop(); Reporter.AddTestInfo(3, ""); return; } catch (System.Reflection.TargetInvocationException) { } catch (StaleElementReferenceException) { } catch (System.InvalidOperationException) { } catch (WebDriverException e) { if (e.Message.Contains("Other element would receive the click")) { continue; } if (e.Message.Contains("Element is not clickable at point")) { continue; } throw e; } } throw new Exception("Given element isn't visible"); }
public void NavigateTo(string url) { DriverFactory.Instance.Navigate().GoToUrl(url); Reporter.AddTestInfo(2, "PARAMETER: " + url); }
protected void ClearAndSendKeys(By locator, String text) { WaitForElement(locator).Clear(); WaitForElement(locator).SendKeys(text); Reporter.AddTestInfo(3, "PARAMETER: " + text); }
protected void ScrollToTop() { javaScriptExecutor.ExecuteScript("window.scrollTo(0, 0);"); Reporter.AddTestInfo(3, ""); }
public void Refresh() { DriverFactory.Instance.Navigate().Refresh(); Reporter.AddTestInfo(2, ""); }
public void OpenNewTab() { javaScriptExecutor.ExecuteScript("window.open();"); Reporter.AddTestInfo(2, ""); }
public void SetFocusToFirstTab() { driver.SwitchTo().Window(driver.WindowHandles.First()); Reporter.AddTestInfo(2, ""); }