public void LazyWrappedWithoutEventFiring() { // Create lazy element without event firing var lazy = new LazyElement(this.TestObject, this.WebDriver.GetLowLevelDriver(), this.InputBox.By); Assert.IsFalse(lazy.WrappedElement is IWrapsElement, "Element should not be wrapped"); }
public void LazyElementGetBy() { By testBy = By.CssSelector("#ItemsToAutomate"); LazyElement testLazyElement = new LazyElement(this.TestObject, testBy, "TEST"); Assert.AreEqual(testBy, testLazyElement.By); }
public void DoubleClickWithLazy() { this.NavigateToUrl(siteAutomationUrl); // Trigger a right click event var icon = new LazyElement(this.TestObject, datePickerImage); var calendar = new LazyElement(this.TestObject, datePickerCalendar); // Make sure we can see the calendar if we need to take a screenshot icon.ScrollIntoView(0, this.WebDriver.Manage().Window.Size.Height / 2); Assert.IsFalse(calendar.Displayed); // Make sure single click displays the calendar icon.Click(); this.WebDriver.Wait().ForPageLoad(); Assert.IsTrue(calendar.Displayed); // Make sure another click makes the calendar go away icon.Click(); this.WebDriver.Wait().ForPageLoad(); Assert.IsFalse(calendar.Displayed); // Make sure another double click results in the calendar not being displayed icon.DoubleClick(); this.WebDriver.Wait().ForPageLoad(); Assert.IsFalse(calendar.Displayed); }
public void LazyElementFindElementsGetVisible() { LazyElement lazyRoot = new LazyElement(this.TestObject, By.CssSelector("#ItemsToAutomate")); IWebElement secondTable = lazyRoot.FindElements(By.CssSelector("TABLE"))[1]; IWebElement getSecondTable = ((LazyElement)secondTable).GetRawVisibleElement(); Assert.AreEqual(secondTable.Text, getSecondTable.Text); }
public void LazyElementSendKeysWithInteractionNavComplex() { WebDriver.Navigate().GoToUrl("https://www.google.com/"); LazyElement lazyRoot = new LazyElement(this.TestObject, By.Name("q")); lazyRoot.SendKeys("SEARCH" + Keys.Tab + "TXT"); Assert.AreEqual("SEARCH", lazyRoot.GetValue()); }
public void LazyPreCaching() { // Create the lazy element and use it LazyElement footer = new LazyElement(this.TestObject, By.CssSelector("FOOTER P"), "Footer"); // Make sure we are getting back the same cached element Assert.IsNull(footer.CachedElement, "The cached element should be null as we never triggered a find"); }
public void LazyShadowRootTimeout() { // Create the lazy element and use it LazyElement footer = new LazyElement(this.TestObject, By.CssSelector("FOOTER P"), "Footer"); // Make sure we don't get a shadow root back Assert.IsNull(footer.GetShadowRoot(), "There is no shadow root so fail"); }
public void LazyElementExistsNow() { LazyElement slowLoad = new LazyElement(this.TestObject, By.CssSelector("#AsyncContent[style*='block']")); WebDriver.Navigate().GoToUrl(SeleniumConfig.GetWebSiteBase() + "Automation/AsyncPage"); Assert.IsFalse(slowLoad.ExistsNow, "Element should not exist yet"); }
public void ClickElementByJavascriptFromHoverDropdownWithLazy() { NavigateToUrl(); LazyElement button = new LazyElement(this.TestObject, employeeButton); button.ClickElementByJavaScript(); WebDriver.Wait().ForPageLoad(); WebDriver.Wait().ForExactText(employeePageTitle, "Index"); }
public void LazyGetExistTriggerFind() { // Create the lazy element and use it LazyElement footer = new LazyElement(this.TestObject, By.CssSelector("FOOTER P"), "Footer"); IWebElement cacheFooter = footer.GetTheVisibleElement(); // Make sure get exists triggers a new find Assert.AreNotEqual(footer.CachedElement, footer.GetTheExistingElement()); }
public void LazyGetVisibleTriggerFind() { // Create the lazy element and use it LazyElement footer = new LazyElement(this.TestObject, By.CssSelector("FOOTER P"), "Footer"); footer.GetRawVisibleElement(); // Make sure get visible triggers a new find Assert.AreNotEqual(footer.CachedElement, footer.GetRawVisibleElement()); }
public void LazyWebElementToWebDriverUnwrappedDriver() { WebDriver.Navigate().GoToUrl(TestSiteAutomationUrl); IWebDriver driver = this.WebDriver.GetLowLevelDriver(); LazyElement lazy = new LazyElement(this.TestObject, driver, AutomationShowDialog1); IWebDriver basedriver = SeleniumUtilities.WebElementToWebDriver(lazy); Assert.AreEqual("OpenQA.Selenium.Chrome.ChromeDriver", basedriver.GetType().ToString()); }
public void LazyGetsTriggerFind() { // Create the lazy element and use it LazyElement footer = new LazyElement(this.TestObject, By.CssSelector("FOOTER P"), "Footer"); IWebElement cacheFooter = footer.GetRawVisibleElement(); // Make sure the second event didn't trigger a new find Assert.AreEqual(cacheFooter, footer.CachedElement); }
/// <summary> /// Create a HTML accessibility report /// </summary> /// <param name="context">The scan context, this is either a web driver or web element</param> /// <param name="testObject">The TestObject to associate the report with</param> /// <param name="getResults">Function for getting the accessibility scan results</param> /// <param name="throwOnViolation">Should violations cause and exception to be thrown</param> public static void CreateAccessibilityHtmlReport(this ISearchContext context, SeleniumTestObject testObject, Func <AxeResult> getResults, bool throwOnViolation = false) { // If we are using a lazy element go get the raw element instead LazyElement raw = context as LazyElement; if (raw != null) { context = ((LazyElement)context).GetRawExistingElement(); } // Check to see if the logger is not verbose and not already suspended bool restoreLogging = testObject.Log.GetLoggingLevel() != MessageType.VERBOSE && testObject.Log.GetLoggingLevel() != MessageType.SUSPENDED; AxeResult results; string report = GetAccessibilityReportPath(testObject); testObject.Log.LogMessage(MessageType.INFORMATION, "Running accessibility check"); try { // Suspend logging if we are not verbose or already suspended if (restoreLogging) { testObject.Log.SuspendLogging(); } results = getResults(); context.CreateAxeHtmlReport(results, report); } finally { // Restore logging if we suspended it if (restoreLogging) { testObject.Log.ContinueLogging(); } } // Add the report testObject.AddAssociatedFile(report); testObject.Log.LogMessage(MessageType.INFORMATION, $"Ran accessibility check and created HTML report: {report} "); // Throw exception if we found violations and we want that to cause an error if (throwOnViolation && results.Violations.Length > 0) { throw new ApplicationException($"Accessibility violations, see: {report} for more details."); } // Throw exception if the accessibility check had any errors if (results.Error.Length > 0) { throw new ApplicationException($"Accessibility check failure, see: {report} for more details."); } }
public void LazyWithParentAndWithoutMatch() { // Get the lazy element without a parent LazyElement flowerTableCaptionWithoutParent = new LazyElement(this.TestObject, By.CssSelector("#FlowerTable CAPTION > Strong"), "Flower table"); // Make sure we are finding the correct table Assert.AreEqual("Flower Table", this.FlowerTableCaptionWithParent.Text); // Make sure we got the table caption we are looking for Assert.AreEqual(this.FlowerTableCaptionWithParent.Text, flowerTableCaptionWithoutParent.Text); }
public void LazyElementFindElementsStackedWithStale() { LazyElement lazyRoot = new LazyElement(this.TestObject, By.CssSelector("#ItemsToAutomate")); IWebElement secondTable = lazyRoot.FindElements(By.CssSelector("TABLE"))[1]; IWebElement lastTableHeader = ((LazyElement)secondTable).FindElements(By.CssSelector("THEAD TH"))[4]; this.WebDriver.Navigate().GoToUrl(SeleniumConfig.GetWebSiteBase()); this.WebDriver.Navigate().GoToUrl(SeleniumConfig.GetWebSiteBase() + "Automation"); Assert.AreEqual("Color", lastTableHeader.Text); }
/// <summary> /// Gets LazyElement from page model's lazy element store if it exists, otherwise /// initializes a new instance of the LazyElement and adds it to the lazy element store /// </summary> /// <param name="parent">The LazyElement parent element</param> /// <param name="locator">The 'by' selector for the element</param> /// <param name="userFriendlyName">A user friendly name, for logging purposes</param> /// <returns>The LazyElement</returns> protected LazyElement GetLazyElement(LazyElement parent, By locator, [CallerMemberName] string userFriendlyName = null) { string lazyElementStoreKey = parent.ToString() + locator.ToString() + userFriendlyName; if (!this.lazyElementStore.ContainsKey(lazyElementStoreKey)) { this.lazyElementStore.Add(lazyElementStoreKey, new LazyElement(parent, locator, userFriendlyName)); } return(this.lazyElementStore[lazyElementStoreKey]); }
public void SetTextBoxAndVerifyValueTestWithLazy() { string expectedValue = "Tester"; NavigateToUrl(); LazyElement lazy = new LazyElement(this.TestObject, firstNameTextBox); lazy.SetTextBox(expectedValue); string actualValue = WebDriver.GetElementAttribute(firstNameTextBox); VerifyText(actualValue, expectedValue); }
/// <summary> /// Create a HTML accessibility report for a specific web element and all of it's children /// </summary> /// <param name="webDriver">The WebDriver</param> /// <param name="testObject">The TestObject to associate the report with</param> /// <param name="element">The WebElement you want to use as the root for your accessibility scan</param> /// <param name="throwOnViolation">Should violations cause and exception to be thrown</param> public static void CreateAccessibilityHtmlReport(this IWebDriver webDriver, SeleniumTestObject testObject, IWebElement element, bool throwOnViolation = false) { // If we are using a lazy element go get the raw element instead LazyElement raw = element as LazyElement; if (raw != null) { element = ((LazyElement)element).GetRawExistingElement(); } CreateAccessibilityHtmlReport(element, testObject, () => webDriver.Analyze(element), throwOnViolation); }
public void DragAndDrop() { this.WebDriver.Navigate().GoToUrl(siteAutomationUrl); this.WebDriver.Wait().ForPageLoad(); var dropped = new LazyElement(this.TestObject, By.Id("DROPPED")); Assert.IsFalse(dropped.ExistsNow); this.WebDriver.DragAndDrop(By.Id("draggable"), By.Id("droppable2")); Assert.IsTrue(dropped.ExistsNow); }
public void AccessibilityHtmlReportWithLazyElement() { WebDriver.Navigate().GoToUrl(TestSiteAutomationUrl); WebDriver.Wait().ForPageLoad(); LazyElement foodTable = new LazyElement(this.TestObject, By.Id("FoodTable")); WebDriver.CreateAccessibilityHtmlReport(this.TestObject, foodTable); string file = this.TestObject.GetArrayOfAssociatedFiles().Last(x => x.EndsWith(".html")); Assert.IsTrue(new FileInfo(file).Length > 0, "Accessibility report is empty"); }
public void LazyGetExistTriggerFind() { // Create the lazy element and use it LazyElement footer = new LazyElement(this.TestObject, By.CssSelector("FOOTER P"), "Footer"); footer.GetRawVisibleElement(); // Make sure the page is reloaded LeaveAndReturnToPage(this.WebDriver); // Make sure get exists triggers a new find Assert.AreNotEqual(footer.CachedElement, footer.GetRawExistingElement()); }
public void SeparateLazyElementInteractions() { SeleniumDriverManager newDriver = new SeleniumDriverManager(() => WebDriverFactory.GetBrowserWithDefaultConfiguration(BrowserType.HeadlessChrome), this.TestObject); newDriver.GetWebDriver().Navigate().GoToUrl("https://magenicautomation.azurewebsites.net/"); this.ManagerStore.Add("test", newDriver); this.TestObject.WebDriver.Navigate().GoToUrl("https://magenicautomation.azurewebsites.net/Automation"); LazyElement topNew = new LazyElement(this.TestObject, newDriver.GetWebDriver(), By.CssSelector("*")); LazyElement topDefault = new LazyElement(this.TestObject, By.CssSelector("*")); Assert.AreNotEqual(topNew.Text, topDefault.Text); }
public void NewFindDifferentThanCached() { // Create the lazy element and use it LazyElement footer = new LazyElement(this.TestObject, By.CssSelector("FOOTER P"), "Footer"); // Trigger a find and save off the element footer.GetValue(); IWebElement footerElementBefore = footer.CachedElement; // Do the event again and save off the changed element footer.GetValue(); // Make sure doing a new find returns an element that is not the same as the cached element Assert.AreNotEqual(WebDriver.FindElement(footer.By), footerElementBefore); }
public void LazyElementCached() { // Create the lazy element and use it LazyElement footer = new LazyElement(this.TestObject, By.CssSelector("FOOTER P"), "Footer"); // Trigger a find and save off the element footer.GetValue(); IWebElement footerElementBefore = footer.CachedElement; // Do the event again and save off the changed element footer.GetValue(); IWebElement footerElementAfter = footer.CachedElement; // Make sure the second event didn't trigger a new find Assert.AreEqual(footerElementBefore, footerElementAfter); }
public void LazyCaching() { // Create the lazy element and use it LazyElement footer = new LazyElement(this.TestObject, By.CssSelector("FOOTER P"), "Footer"); // Trigger a find and save off the element footer.GetValue(); IWebElement footerElementBefore = footer.CachedElement; // Do the event again and save off the changed element footer.GetValue(); // Go to another page so the old element will be stale, this will force us to get a new one WebDriver.Navigate().GoToUrl(SeleniumConfig.GetWebSiteBase() + "Automation/AsyncPage"); // Trigger a new find, this should be new because the cached element is stale footer.GetValue(); Assert.AreNotEqual(footerElementBefore, footer.CachedElement); }
public void DragAndDropToOffset() { this.WebDriver.Navigate().GoToUrl(siteAutomationUrl); this.WebDriver.Wait().ForPageLoad(); var draggable = new LazyElement(this.TestObject, By.Id("draggable")); var secondDrop = new LazyElement(this.TestObject, By.Id("droppable2")); var secondDroped = new LazyElement(secondDrop, By.Id("DROPPED")); // Make syure the drag and drop hasn't already happened Assert.IsFalse(secondDroped.ExistsNow); // Get where the second drop location is relative to the original location int horizontalDiff = secondDrop.Location.X + (secondDrop.Size.Width / 4) - draggable.Location.X; int verticalDiff = secondDrop.Location.Y + (secondDrop.Size.Height / 4) - draggable.Location.Y; this.WebDriver.DragAndDropToOffset(By.Id("draggable"), horizontalDiff, verticalDiff); // Make sure we actually dropped on the second drop location Assert.IsTrue(secondDroped.ExistsNow); }
private TValue ReadOriginalValue_NoLock(LazyElement elem) { return(ReadOriginalValue_NoLock(list.IndexOf(elem), elem.origIndex)); }
TValue ReadOriginalValue(LazyElement elem) { return(ReadOriginalValue(list.IndexOf(elem), elem.origIndex)); }
public void LazyElementGetTestObject() { LazyElement testLazyElement = new LazyElement(this.TestObject, By.CssSelector("#ItemsToAutomate"), "TEST"); Assert.AreEqual(this.TestObject, testLazyElement.TestObject); }