private void TestBasicNavigation(IWebDriver browser) { // <title> element gets project ID injected into it during template execution Assert.Contains(ProjectGuid, browser.Title); // Initially displays the home page Assert.Equal("Hello, world!", browser.GetText("h1")); // Can navigate to the counter page browser.Click(By.PartialLinkText("Counter")); Assert.Equal("Counter", browser.GetText("h1")); // Clicking the counter button works var counterComponent = browser.FindElement("h1").Parent(); Assert.Equal("0", counterComponent.GetText("strong")); browser.Click(counterComponent, "button"); Assert.Equal("1", counterComponent.GetText("strong")); // Can navigate to the 'fetch data' page browser.Click(By.PartialLinkText("Fetch data")); Assert.Equal("Weather forecast", browser.GetText("h1")); // Asynchronously loads and displays the table of weather forecasts var fetchDataComponent = browser.FindElement("h1").Parent(); var table = browser.FindElement(fetchDataComponent, "table", timeoutSeconds: 5); Assert.Equal(5, table.FindElements(By.CssSelector("tbody tr")).Count); }
public static void SelectTodaysDate(this IWebDriver driver, By element) { driver.EnsureElementExists(element); driver.ScrollTo(element); driver.Click(element); Thread.Sleep(200); // This sleep seems to make a difference, oddly enough the 'ensure element exists' fails intermittently without it driver.EnsureElementExists(By.ClassName("datepicker")); driver.Click(By.ClassName("today")); }
public void VisitInBrowser(IWebDriver driver) { _output.WriteLine($"Opening browser at {_listeningUri}..."); driver.Navigate().GoToUrl(_listeningUri); if (driver is EdgeDriver) { // Workaround for untrusted ASP.NET Core development certificates. // The edge driver doesn't supported skipping the SSL warning page. if (driver.Title.Contains("Certificate error", StringComparison.OrdinalIgnoreCase)) { _output.WriteLine("Page contains certificate error. Attempting to get around this..."); driver.Click(By.Id("moreInformationDropdownSpan")); var continueLink = driver.FindElement(By.Id("invalidcert_continue")); if (continueLink != null) { _output.WriteLine($"Clicking on link '{continueLink.Text}' to skip invalid certificate error page."); continueLink.Click(); driver.Navigate().GoToUrl(_listeningUri); } else { _output.WriteLine("Could not find link to skip certificate error page."); } } } }
protected override void Execute(IWebDriver driver, dynamic context, IWebElement element) { if (!element.IsChecked()) { driver.Click(element, (DriverType)context.DriverType); } }
/// <summary> /// Moves the cursor to a given point and performs a click. /// <para>Logs the event optionally.</para> /// </summary> /// <param name="point">...Description to be added...</param> /// <param name="logger"> /// The used <see cref="Logger" /> instance to display logged messages (<see cref="LogEventLevel" /> = /// <see cref="LogEventLevel.Information" />) during /// the method exeuction. /// </param> /// <param name="driver">The browser, that is represented by an <see cref="IWebDriver" /> instance.</param> public static void Click([NotNull] this IWebDriver driver, Point point, [CanBeNull] Logger logger = null) { if (driver == null) { throw new ArgumentNullException(nameof(driver)); } driver.Click(point.X, point.Y, logger); }
public void FillLookUpField(string fieldLabel, string fieldValue, IWebDriver driver) { driver.FindElement(By.XPath($"//input[contains(@aria-label,'{fieldLabel}')]")).Click(); Thread.Sleep(1000); driver.FindElement(By.XPath($"//input[contains(@aria-label,'{fieldLabel}')]")).SendKeys(fieldValue, true); Thread.Sleep(1000); driver.Inivisibility(By.XPath("//label[text()='Loading...']"), 30); driver.Click(driver.FindElement(By.XPath("(//ul[contains(@aria-label,'Lookup Search Results')]/li)[1]"))); Thread.Sleep(500); }
private static bool tryClick(this IWebDriver driver, By by) { try { driver.Click(by); return(true); } catch (Exception e) { return(false); } }
public bool AddItemCart() { _wait.Until((d) => d.FindElement(By.ClassName("popup-close-tip")) != null); _driver.SendKeys( By.ClassName("popup-close-tip")); _driver.Click(By.XPath("//img[@src='https://sj-img.azureedge.net/product/7748-feijao-preto-pink-1kg-m.jpg']")); _wait.Until((d) => d.FindElement(By.ClassName("box-modelo-item")) != null); _driver.SendKeys(By.CssSelector("a[ng-click='adicionarProdutoDetalhe()']")); return(Int32.Parse(_driver.GetText(By.Id("carrinho-qtde"))) >= 1); }
private void Login(IWebDriver driver, UserInfo userInfo) { var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); // BC driver.Navigate().GoToUrl(BASE_URL); // BC wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.LinkText("Log in"))); driver.Click(By.LinkText("Log in")); // Auth0 wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.TitleContains("Sign In")); wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.Name("submit"))); var user = _users.Single(u => u.Id == userInfo.GetId()); driver.SendKeys(By.Name("email"), user.Email); driver.SendKeys(By.Name("password"), user.Password); driver.Click(By.Name("submit")); // BC wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.TitleContains("NHS Digital Buying Catalogue")); }
public string Summary() { _driver.Click(By.XPath(MyStorePageMap.FirstProductImage)); _driver.WaitNClick(15, By.Name(MyStorePageMap.AddToCartButton)); _driver.WaitNClick(10, By.LinkText(MyStorePageMap.ProceedToCheckout)); string result = _driver.GetText(By.Id(MyStorePageMap.TotalPrice)); _driver.WaitNClick(10, By.LinkText(MyStorePageMap.ProceedToCheckout)); return(result); }
public static void SetValue(this IWebDriver driver, By by, string value) { driver.WaitForVisible(by); var element = driver.FindElement(by); //First check that element is able to be interacted with if (driver.Displayed(by)) { //Determine if the value to be set is boolean if (value.Equals("true") || value.Equals("false")) { bool toSelect = bool.Parse(value); //Check if element is selected and shouldn't be, or vice versa, and click if so if ((toSelect & !element.Selected) || (!toSelect & element.Selected)) { driver.Click(by); } } else { element.SendKeys(value); } } }
private void TestBasicNavigation(bool visitFetchData, bool usesAuth, IWebDriver browser, ILogs logs) { browser.Exists(By.TagName("ul")); // <title> element gets project ID injected into it during template execution browser.Contains(Project.ProjectGuid.Replace(".", "._"), () => browser.Title); // Initially displays the home page browser.Equal("Hello, world!", () => browser.FindElement(By.TagName("h1")).Text); // Can navigate to the counter page browser.Click(By.PartialLinkText("Counter")); browser.Contains("counter", () => browser.Url); browser.Equal("Counter", () => browser.FindElement(By.TagName("h1")).Text); // Clicking the counter button works browser.Equal("0", () => browser.FindElement(By.CssSelector("p>strong")).Text); browser.Click(By.CssSelector("p+button")); browser.Equal("1", () => browser.FindElement(By.CssSelector("p>strong")).Text); if (visitFetchData) { browser.Click(By.PartialLinkText("Fetch data")); if (usesAuth) { // We will be redirected to the identity UI browser.Contains("/Identity/Account/Login", () => browser.Url); browser.Click(By.PartialLinkText("Register as a new user")); var userName = $"{Guid.NewGuid()}@example.com"; var password = $"!Test.Password1$"; browser.Exists(By.Name("Input.Email")); browser.FindElement(By.Name("Input.Email")).SendKeys(userName); browser.FindElement(By.Name("Input.Password")).SendKeys(password); browser.FindElement(By.Name("Input.ConfirmPassword")).SendKeys(password); browser.Click(By.Id("registerSubmit")); // We will be redirected to the RegisterConfirmation browser.Contains("/Identity/Account/RegisterConfirmation", () => browser.Url); browser.Click(By.PartialLinkText("Click here to confirm your account")); // We will be redirected to the ConfirmEmail browser.Contains("/Identity/Account/ConfirmEmail", () => browser.Url); // Now we can login browser.Click(By.PartialLinkText("Login")); browser.Exists(By.Name("Input.Email")); browser.FindElement(By.Name("Input.Email")).SendKeys(userName); browser.FindElement(By.Name("Input.Password")).SendKeys(password); browser.Click(By.Id("login-submit")); // Need to navigate to fetch page browser.Click(By.PartialLinkText("Fetch data")); } // Can navigate to the 'fetch data' page browser.Contains("fetch-data", () => browser.Url); browser.Equal("Weather forecast", () => browser.FindElement(By.TagName("h1")).Text); // Asynchronously loads and displays the table of weather forecasts browser.Exists(By.CssSelector("table>tbody>tr")); browser.Equal(5, () => browser.FindElements(By.CssSelector("p+table>tbody>tr")).Count); } foreach (var logKind in logs.AvailableLogTypes) { var entries = logs.GetLog(logKind); var badEntries = entries.Where(e => new LogLevel[] { LogLevel.Warning, LogLevel.Severe }.Contains(e.Level)); badEntries = badEntries.Where(e => !e.Message.Contains("failed: WebSocket is closed before the connection is established.") && !e.Message.Contains("[WDS] Disconnected!") && !e.Message.Contains("Timed out connecting to Chrome, retrying")); Assert.True(badEntries.Count() == 0, "There were Warnings or Errors from the browser." + Environment.NewLine + string.Join(Environment.NewLine, badEntries)); } }
public void SelectFeaturedProduct(int productIndex) { var xPath = $"//*[@id=\"homefeatured\"]/li[{productIndex}]/div/div[1]/div/a[1]"; _driver.Click(By.XPath(xPath)); }
public TPage AcceptCookies <TPage>(TPage page) { Driver.Click(_buttonCookieBanner); return(page); }
protected override void Execute(IWebDriver driver, dynamic context, IWebElement element) { driver.Click(element, (DriverType)context.DriverType); }
public static void Click(this IWebDriver driver, string elementID) { driver.Click(By.Id(elementID)); }
public void ClikckNavBarOption(string link) { driver.Click(By.XPath($"//a[contains(text(),'{link}')]")); }