/// <summary> /// Locates and selects the format to export to. Will only work when /// running tests locally. /// </summary> /// <param name="type">The type.</param> /// <param name="downloadsPath">The downloads path.</param> /// <param name="expectedFileName">The expected file name.</param> /// <param name="stringComparison">The string comparison.</param> /// <exception cref="NoSuchElementException"></exception> public virtual void ExportTo(string type, string downloadsPath, string expectedFileName, StringComparison stringComparison = StringComparison.Ordinal) { var fullPath = Path.Combine(downloadsPath, expectedFileName); var element = ExportDropDownComponent .Expand() .GetEnabledItems() .FirstOrDefault(e => String.Equals( e.TextHelper().InnerText, type, StringComparison.Ordinal)); if (element == null) { throw new NoSuchElementException(); } element.Click(); WrappedDriver .Wait(TimeSpan.FromMinutes(5)) .Until(d => File.Exists(fullPath)); }
/// <summary> /// Tries the go to step. /// </summary> /// <param name="stepName">Name of the step.</param> /// <param name="resolve">The resolve.</param> /// <param name="reject">The reject.</param> /// <param name="stringComparison">The string comparison.</param> /// <returns> /// The operation success status. /// </returns> /// <exception cref="ArgumentNullException"> /// resolve /// or /// reject /// </exception> /// <exception cref="NotImplementedException"></exception> public virtual bool TryGoToStep(string stepName, Action <ICheckoutStepPage> resolve = null, Action <ICheckoutStepPage> reject = null, StringComparison stringComparison = StringComparison.Ordinal) { if (String.IsNullOrEmpty(stepName)) { throw new ArgumentNullException(stepName); } var indexOfStep = GetAllStepNames().IndexOf( name => String.Equals( name, stepName, stringComparison)); var result = TryGoToStep(indexOfStep, resolve, reject); if (result) { // For unknown reasons the step is changing correctly but the // step name is being a bit slow to update. WrappedDriver .Wait(TimeSpan.FromSeconds(1)) .Until(d => { return(String.Equals( GetCurrentStepName(), stepName, stringComparison)); }); } return(result); }
/// <summary> /// Retrieves the viewmodel. /// </summary> /// <returns></returns> public virtual HeaderLinksModel ViewModel() { var wait = WrappedDriver.Wait(TimeSpan.FromSeconds(30)); var isLoggedIn = wait.Exists(LogoutSelector.ToString()); var hasShoppingCartItems = wait.Exists(ShoppingCartSelector); var hasPrivateMessages = wait.Exists(PrivateMessagesSelector); var hasWishList = WrappedDriver.FindElements(WishListSelector).Any(); var model = new HeaderLinksModel { IsAuthenticated = isLoggedIn, CustomerName = isLoggedIn ? CustomerInfoElement.Text : null, ShoppingCartEnabled = hasShoppingCartItems, ShoppingCartItems = hasShoppingCartItems ? ShoppingCartQtyElement.TextHelper().ExtractInteger() : 0, AllowPrivateMessages = hasPrivateMessages, UnreadPrivateMessages = hasPrivateMessages ? PrivateMessageLabelElement.Text : null, WishlistEnabled = hasWishList, WishlistItems = hasWishList ? WishListQtyElement.TextHelper().ExtractInteger() : 0, Currency = CurrencyElement.SelectedOption.TextHelper().InnerText, Language = LanguageElement.SelectedOption.TextHelper().InnerText }; return(model); }
/// <summary> /// Adds the new related product. /// </summary> /// <param name="productName">Name of the product.</param> /// <returns></returns> public virtual RelatedProductsComponent AddNewRelatedProduct(string productName) { var currentPageHandle = WrappedDriver.CurrentWindowHandle; var windowHandles = WrappedDriver.WindowHandles; var newWindowHandle = default(string); AddNewRelatedProductElement.Click(); // Wait for the new window to appear. WrappedDriver .Wait(TimeSpan.FromSeconds(10)) .Until(d => newWindowHandle = d.WindowHandles .Except(windowHandles) .FirstOrDefault()); // Switch to the new window. WrappedDriver.SwitchTo().Window(newWindowHandle); SearchProductPopup.Load(); SearchProductPopup.SearchForProduct(productName); // Switch back. WrappedDriver.SwitchTo().Window(currentPageHandle); // Wait for the grid to finish loading. WrappedDriver .Wait(TimeSpan.FromSeconds(10)) .UntilChain(d => RelatedProductsGrid.IsBusy()) .UntilChain(d => !RelatedProductsGrid.IsBusy()); return(this); }
private void WaitForInitalization() { var wait = WrappedDriver.Wait(TimeSpan.FromSeconds(10)); var timeoutMS = wait.Timeout.TotalMilliseconds; var pollingMS = wait.PollingInterval.TotalMilliseconds; var script = AddTinyMCEUtilities(String.Empty) + "var el = {args}[0];" + "var editor = tinyMCEUtilities.getEditor(el);" + "tinyMCEUtilities.waitForInitialization(editor," + $"{timeoutMS}," + $"{pollingMS}," + "{resolve}," + "{reject});"; script = JavaScript.RemoveComments(script); script = JavaScript.Clean(script); var waiter = new PromiseBody(WrappedDriver) { Arguments = new[] { new JavaScriptValue(WrappedElement) }, Script = script }; // Condense the script. waiter.Format(); waiter.Execute(WrappedDriver.JavaScriptExecutor()); wait.Until(d => waiter.Finished); waiter.Wait(TimeSpan.FromSeconds(10)); }
/// <summary> /// Searches for product. /// </summary> /// <param name="productName">Name of the product.</param> public virtual void SearchForProduct(string productName) { var currentWindowHandle = WrappedDriver.CurrentWindowHandle; ProductNameElement.SetValue(productName); SearchElement.Click(); WrappedDriver .Wait(TimeSpan.FromSeconds(2)) .Until(d => !ProductsGrid.IsBusy()); var firstCheckbox = ProductsGrid .GetCell(0, 0) .FindElement(By.TagName("input")); var checkbox = new CheckboxElement(firstCheckbox); checkbox.Check(true); SaveElement.Click(); // Wait for the page to close. WrappedDriver .Wait(TimeSpan.FromSeconds(10)) .Until(d => !d.WindowHandles.Contains(currentWindowHandle)); }
/// <summary> /// Adds to cart and calls resolve/reject if the product was or wasn't /// added to the cart. /// </summary> /// <param name="resolve">The resolve.</param> /// <param name="reject">The reject.</param> /// <returns></returns> public virtual IBaseProductPage AddToCart( Action <IBaseProductPage> resolve, Action <IBaseProductPage> reject) { AddToCartButtonElement.Click(); WrappedDriver .Wait(TimeSpan.FromSeconds(30)) .Until(d => HasNotifications()); HandleNotification(el => { var hasError = el.Classes().Contains("error"); DismissNotifications(); if (hasError) { reject(this); } else { resolve(this); } }); return(this); }
/// <summary> /// Prints the order details. /// </summary> public virtual void Print() { var tabHelper = WrappedDriver.TabHelper(); var initialTabs = tabHelper.GetTabHandles().ToList(); var initialTab = WrappedDriver.CurrentWindowHandle; WrappedDriver .Wait(TimeSpan.FromSeconds(30)) .Until( d => tabHelper.GetTabHandles().Count() > initialTabs.Count); WrappedDriver .SwitchTo() .Window(tabHelper .GetTabHandles() .Except(initialTabs) .First()); var printWindowHandle = WrappedDriver.CurrentWindowHandle; WrappedDriver.WaitForUserSignal(TimeSpan.FromMinutes(5)); // Close the tab if it's still open. if (WrappedDriver.CurrentWindowHandle == printWindowHandle) { WrappedDriver.Close(); } // Switch back to the initial window handle. WrappedDriver.SwitchTo().Window(initialTab); }
/// <summary> /// Views the order. Need to pass in a row from the OrdersGrids. /// </summary> /// <param name="gridRow">The grid row.</param> /// <returns></returns> /// <exception cref="NotImplementedException"></exception> public virtual Order.IEditPage ViewOrder(IWebElement gridRow) { if (gridRow == null) { throw new ArgumentException(nameof(gridRow)); } var hasCorrectTagName = String.Equals( gridRow.TagName, "tr", StringComparison.OrdinalIgnoreCase); if (!hasCorrectTagName) { throw new UnexpectedTagNameException("Expected 'tr' but " + $"element had '{gridRow.TagName}' instead."); } var bttn = gridRow.FindElement(viewButtonSelector); WrappedDriver .Wait(TimeSpan.FromSeconds(2)) .UntilPageReloads(bttn, e => e.Click()); return(pageObjectFactory.PreparePage <Order.IEditPage>()); }
/// <summary> /// Will click an element that will close the collapsable if not /// already closed and wait for the animation to finish. /// </summary> /// <param name="element"></param> /// <returns></returns> public virtual CollapsableComponent <T> Close(IWebElement element = null) { if (!IsExpanded()) { if (element == null) { if (CloseElements.Any()) { CloseElements.First().Click(); } else if (ToggleElements.Any()) { ToggleElements.First().Click(); } else { throw new NoSuchElementException("Failed to locate " + "any elements to collpase the collapsable element."); } } else { element.Click(); } WrappedDriver .Wait(animationData.AnimationDuration + TimeSpan.FromSeconds(2)) .Until(d => !IsCurrentlyAnimating()); } return(this); }
/// <summary> /// Finalizes and confirms the order. /// </summary> /// <param name="resolve">Called if</param> /// <param name="reject"></param> /// <returns></returns> /// <exception cref="NotImplementedException"></exception> public virtual bool TryConfirm(Action <ICompletedPage> resolve, Action <ICheckoutPage> reject) { // Check if on right step. if (GetCurrentStepName() != "Confirm order") { throw new Exception("Not on correct step."); } ConfirmElement.Click(); // Wait until the please wait message appears and then either // dissapears or becomes null. var result = WrappedDriver .Wait(TimeSpan.FromSeconds(60 * 5)) .TrySequentialWait( out var exc, d => ConfirmPleaseWaitElement?.Displayed ?? true, d => !ConfirmPleaseWaitElement?.Displayed ?? true); if (result) { var completedPage = pageObjectFactory .PreparePage <ICompletedPage>(); resolve(completedPage); } else { reject(this); } return(result); }
/// <summary> /// Saves the customer and continues to edit. /// </summary> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public virtual IEditPage SaveAndContinueEdit() { WrappedDriver .Wait(TimeSpan.FromSeconds(5)) .UntilPageReloads(SaveAndContinueElement, e => e.Click()); return(pageObjectFactory.PrepareComponent(this)); }
/// <summary> /// Returns to the customer list. /// </summary> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public virtual IListPage BackToCustomerList() { WrappedDriver .Wait(TimeSpan.FromSeconds(5)) .UntilPageReloads(BackToCustomerListElement, e => e.Click()); return(pageObjectFactory.PreparePage <IListPage>()); }
private void PreviousMonth() { CalendarContainerElement.FindElement(calendarPrevMonthSelector).Click(); WrappedDriver .Wait(TimeSpan.FromMilliseconds(500)) .Until(d => CalendarContainerElement.Displayed); }
/// <summary> /// Begins the impersonation session. /// </summary> /// <returns></returns> public virtual Public.Home.IHomePage PlaceOrder() { WrappedDriver .Wait(TimeSpan.FromSeconds(10)) .UntilPageReloads(PlaceOrderElement, e => e.Click()); return(pageObjectFactory.PreparePage <Public.Home.IHomePage>()); }
/// <summary> /// Goes to the customer info page. /// </summary> /// <returns></returns> public virtual IInfoPage CustomerInfo() { WrappedDriver .Wait(TimeSpan.FromSeconds(2)) .UntilPageReloads(CustomerInfoElement, e => e.Click()); return(pageObjectFactory.PreparePage <IInfoPage>()); }
/// <summary> /// Goes to the product. /// </summary> /// <returns></returns> public virtual IBaseProductPage GoToProduct() { WrappedDriver .Wait(TimeSpan.FromSeconds(5)) .UntilPageReloads(ProductTitleElement, e => e.Click()); return(pageObjectFactory.PreparePage <IBaseProductPage>()); }
/// <summary> /// Saves the customer and continues to edit them on the /// <see cref="T:ApertureLabs.Selenium.NopCommerce.PageObjects.Shared.Admin.Customers.IEditPage" />. /// </summary> /// <returns></returns> public virtual IEditPage SaveAndContinue() { WrappedDriver .Wait(TimeSpan.FromSeconds(2)) .UntilPageReloads(SaveAndContinueElement, el => el.Click()); return(pageObjectFactory.PreparePage <IEditPage>()); }
/// <summary> /// Clicks the edit button. /// </summary> /// <returns></returns> public virtual IEditPage Edit() { WrappedDriver .Wait(TimeSpan.FromSeconds(2)) .UntilPageReloads(EditElement, e => e.Click()); return(pageObjectFactory.PreparePage <IEditPage>()); }
/// <summary> /// Goes to the create new address page. /// </summary> /// <returns></returns> public virtual IAddressCreatePage AddNewAddress() { WrappedDriver .Wait(TimeSpan.FromSeconds(2)) .UntilPageReloads(AddNewAddressElement, e => e.Click()); return(pageObjectFactory.PreparePage <IAddressCreatePage>()); }
private void DisplayCalendar() { if (IsPopup && !CalendarContainerElement.Displayed) { WrappedElement.Click(); WrappedDriver.Wait(datePickerComponentOptions.AnimationDuration) .Until(d => CalendarContainerElement.Displayed); } }
/// <summary> /// Updates the wishlist. /// </summary> /// <returns></returns> public virtual IWishListPage UpdateWishlist() { WrappedDriver .Wait(TimeSpan.FromSeconds(5)) .UntilPageReloads(UpdateWishlistElement, e => e.Click()); // Page should have reloaded. Load(); return(this); }
private void HideCalendar() { if (IsPopup && CalendarContainerElement.Displayed) { WrappedDriver.CreateActions() .SendKeys(Keys.Escape) .Perform(); WrappedDriver.Wait(datePickerComponentOptions.AnimationDuration) .Until(d => !CalendarContainerElement.Displayed); } }
/// <summary> /// Restarts the application. /// </summary> public virtual void RestartApplication() { ExpandDropDown(); RestartApplicationElement.Click(); // Wait until stale. WrappedDriver .Wait(TimeSpan.FromSeconds(10)) .Until(d => IsStale()); Load(); }
/// <summary> /// Clears the cache. /// </summary> public virtual void ClearCache() { ExpandDropDown(); ClearCacheElement.Click(); // Wait until stale. WrappedDriver .Wait(TimeSpan.FromSeconds(10)) .Until(d => IsStale()); Load(); }
/// <summary> /// Backs to top. /// </summary> public virtual void BackToTop() { if (BackToTopElement.Displayed) { BackToTopElement.Click(); // Wait until the element is no longer displayed. WrappedDriver .Wait(TimeSpan.FromSeconds(5)) .Until(d => !BackToTopElement.Displayed); } }
/// <summary> /// Deletes this order. /// </summary> /// <returns></returns> public virtual IListPage Delete() { var deleteEl = DeleteElement; deleteEl.Click(); WrappedDriver .Wait(TimeSpan.FromSeconds(5)) .Until(d => deleteEl.IsStale()); return(pageObjectFactory.PreparePage <IListPage>()); }
/// <summary> /// Searches this instance. /// </summary> /// <returns></returns> public virtual IListPage Search() { var searchEl = SearchElement; searchEl.Click(); WrappedDriver .Wait(TimeSpan.FromSeconds(10)) .Until(d => searchEl.IsStale()); return(pageObjectFactory.PreparePage <IListPage>()); }
/// <summary> /// Waits for the <c>dataName</c> to be defined on the /// $(WrappedElement).data() object. Assumes that <c>WrappedElement</c> /// has been assigned to. /// </summary> /// <param name="dataName"> /// Name of the property on the data object. /// </param> /// <param name="timeout">The timeout.</param> protected virtual void WaitForInitialization(string dataName, TimeSpan timeout) { var js = WrappedDriver.JavaScriptExecutor(); var script = $"var el = arguments[0];" + $"return '{dataName}' in $(el).data();"; WrappedDriver.Wait(timeout) .Until(d => (bool)js.ExecuteScript(script, WrappedElement)); }
/// <summary> /// Selects an item if not already selected. /// </summary> /// <param name="item"></param> /// <param name="stringComparison"></param> public virtual void SelectItem(string item, StringComparison stringComparison = StringComparison.Ordinal) { var isAlreadySelected = GetSelectedOptions() .Any(opt => String.Equals( opt, item, stringComparison)); if (isAlreadySelected) { return; } Expand(); var el = OptionElements.FirstOrDefault( e => String.Equals( e.TextHelper().InnerText, item, stringComparison)); // Throw if the element doesn't exist. if (el == null) { throw new NoSuchElementException(); } // Use keyboard or mouse depending on config. if (configuration.ControlWithKeyboardInsteadOfMouse) { el.SendKeys(Keys.Enter); } else { el.Click(); } if (configuration.AutoClose) { // Wait until the dropdown is hidden. WrappedDriver .Wait(animationData.AnimationDuration) .Until(d => !el.Displayed); } // Wait until the new item is present in the list. WrappedDriver .Wait(animationData.AnimationDuration) .Until( d => GetSelectedOptions().Any( opt => String.Equals(opt, item, stringComparison))); }