private string TakeScreenshot(IBrowserWrapper browserWrapper) { var testContext = TestSuiteRunner.TestContextProvider.GetGlobalScopeTestContext(); try { var deploymentDirectory = testContext.DeploymentDirectory; if (!string.IsNullOrWhiteSpace(TestSuiteRunner.Configuration.TestRunOptions.ScreenshotPath)) { deploymentDirectory = CreateDirectory(Path.Combine(TestSuiteRunner.Configuration.TestRunOptions.ScreenshotPath, DateTime.UtcNow.ToString("yyyyMMdd"))); } var filename = Path.Combine(deploymentDirectory, $"{testContext.FullyQualifiedTestClassName}_{testContext.TestName}_{testAttemptNumber}.png"); TestSuiteRunner.LogVerbose( $"(#{Thread.CurrentThread.ManagedThreadId}) {TestName}: Taking screenshot {filename}"); browserWrapper.TakeScreenshot(filename); TestSuiteRunner.TestContextAccessor.GetTestContext().AddResultFile(filename); return(filename); } catch (Exception ex) { TestSuiteRunner.LogError(new Exception( $"(#{Thread.CurrentThread.ManagedThreadId}) {TestName}: Failed to take screenshot.", ex)); return(null); } }
/// <summary> /// Waits until DotVVM event Init is performed. ///</summary> /// <param name="browser"></param> /// <param name="maxDotvvmLoadTimeout">is the maximum time interval in which the DotVVM has to be loaded.</param> public static void WaitUntilDotvvmInited(this IBrowserWrapper browser, int maxDotvvmLoadTimeout = 8000) { if (!IsDotvvmPage(browser, maxDotvvmLoadTimeout)) { throw new PageLoadException("Page did not initiate DotVVM."); } }
/// <inheritdoc /> public ElementWrapperCollection(IEnumerable collection, string selector, IBrowserWrapper browserWrapper) { this.collection = new List <TElement>(collection.Cast <TElement>()); Selector = selector; SetReferences(selector); BrowserWrapper = (TBrowser)browserWrapper; }
private static void ChangeAndTestLocalization(IBrowserWrapper browser) { AssertUI.InnerTextEquals(browser.First("p"), "This comes from resource file!", false, true); // change language browser.Last("a").Click(); AssertUI.InnerTextEquals(browser.First("p"), "Tohle pochází z resource souboru!", false, true); }
protected BrowserComponent(IBrowserWrapper <TFrame, TRequest> browser, ICefAdapter cefAdapter, IFrameAdapter <TFrame> frameAdapter, IRequestAdapter <TRequest> requestAdapter) { this.browser = browser; this.cefAdapter = cefAdapter; this.frameAdapter = frameAdapter; this.requestAdapter = requestAdapter; }
private static void CheckUrlGenerationMethod(IBrowserWrapper browser, bool isSpaLink = false) { void checkNavigatedUrl(string selector, string relativeUrl) { var href = browser.Single(selector).GetAttribute("href"); Assert.AreEqual(relativeUrl, new Uri(href).AbsolutePath); } checkNavigatedUrl("a[data-ui='optional-parameter-client']", "/ControlSamples/Repeater/RouteLink"); checkNavigatedUrl("a[data-ui='optional-parameter-server']", "/ControlSamples/Repeater/RouteLink"); checkNavigatedUrl("a[data-ui='0-parameters-client']", "/"); checkNavigatedUrl("a[data-ui='0-parameters-server']", "/"); checkNavigatedUrl("a[data-ui='optional-parameter-prefixed-client']", "/ControlSamples/Repeater/RouteLink"); checkNavigatedUrl("a[data-ui='optional-parameter-prefixed-server']", "/ControlSamples/Repeater/RouteLink"); checkNavigatedUrl("a[data-ui='parameter-prefixed-client']", "/ControlSamples/Repeater/RouteLink/id-1"); checkNavigatedUrl("a[data-ui='parameter-prefixed-server']", "/ControlSamples/Repeater/RouteLink/id-1"); checkNavigatedUrl("a[data-ui='optional-parameter-at-start-client']", "/ControlSamples/Repeater/RouteLink"); checkNavigatedUrl("a[data-ui='optional-parameter-at-start-server']", "/ControlSamples/Repeater/RouteLink"); checkNavigatedUrl("a[data-ui='optional-prefixed-parameter-at-start-client']", "/id-1/ControlSamples/Repeater/RouteLink"); checkNavigatedUrl("a[data-ui='optional-prefixed-parameter-at-start-client']", "/id-1/ControlSamples/Repeater/RouteLink"); }
public static void AlertTextEquals(IBrowserWrapper wrapper, string expectedValue, bool caseSensitive = false, bool trim = true) { var alertTextEquals = new AlertTextEqualsValidator(expectedValue, caseSensitive, trim); EvaluateValidator <AlertException, IBrowserWrapper>(wrapper, alertTextEquals); }
public static void IsNotDisplayed(IBrowserWrapper wrapper, string selector, Func <string, By> tmpSelectedMethod = null) { var elements = wrapper.FindElements(selector, tmpSelectedMethod); var operationRunner = All(elements); var isNotDisplayedValidator = new IsNotDisplayedValidator(); operationRunner.Evaluate <BrowserException>(isNotDisplayedValidator); }
public static void HyperLinkEquals(IBrowserWrapper wrapper, string selector, string url, UrlKind kind, params UriComponents[] components) { var elements = wrapper.FindElements(selector); var operationRunner = All(elements); var hyperLinkEquals = new HyperLinkEqualsValidator(url, kind, components); operationRunner.Evaluate <UnexpectedElementStateException>(hyperLinkEquals); }
public static void CheckArticleCount(IBrowserWrapper browser, string repeaterUiId, int expectedCount) { var articles = browser.First($"div[data-ui='{repeaterUiId}']").FindElements("article[data-ui='test-article']"); if (articles.Count != expectedCount) { throw new UnexpectedElementStateException($"There should be only 2 article in the repeater. There are {articles.Count}"); } }
/// <summary> /// Waits for dotvvm postback to be finished. /// </summary> /// <param name="browser"></param> /// <param name="timeout">Timeout in ms.</param> public static void WaitForPostback(this IBrowserWrapper browser, int timeout = 20000) { if (browser.IsDotvvmPage()) { browser.WaitFor(() => string.Equals("false", browser.GetJavaScriptExecutor().ExecuteScript("return dotvvm.isPostbackRunning()").ToString(), StringComparison.OrdinalIgnoreCase) , timeout, "DotVVM postback still running."); } }
private void CheckSelectAllOnFocus(IBrowserWrapper browser, string textBoxDataUi, bool isSelectAllOnFocusTrue = true) { var textBox = browser.Single(textBoxDataUi, SelectByDataUi); textBox.Click(); var selectedText = (string)browser.GetJavaScriptExecutor().ExecuteScript($"return window.getSelectionText('{textBoxDataUi}');"); var expectedText = isSelectAllOnFocusTrue ? "Testing text" : ""; Assert.AreEqual(expectedText, selectedText); }
private void TestLinkButton(IBrowserWrapper browser, string id, bool shouldBeEnabled, ref int currentPresses) { browser.First($"#{id}").Click(); if (shouldBeEnabled) { currentPresses++; } AssertUI.InnerTextEquals(browser.First("#linkbuttons-pressed"), currentPresses.ToString()); }
private void SearchFlightForBestConference(IBrowserWrapper wrapper, FlightSearchPageObject page) { page.SearchForm.From = "Prague"; page.SearchForm.To = "London Heathrow"; page.SearchForm.Depart = new DateTime(2018, 11, 21); page.SearchForm.Return = new DateTime(2018, 11, 24); page.SearchForm.TicketClass = TicketClassData.Get(TicketClass.Business); page.SearchForm.Search(); }
private void CheckTableRow(IBrowserWrapper browser, int row) { var table = browser.Single("table"); // get expected value - last column var value = table.ElementAt("tr", row).ElementAt("td", 3).GetInnerText(); // check other columns to contain same value AssertUI.InnerTextEquals(table.ElementAt("tr", row).ElementAt("td", 1), value); AssertUI.InnerTextEquals(table.ElementAt("tr", row).ElementAt("td", 2), value, false); // server binding renders True with capital T, knockout binding renders true with lower case t -> comparison is case insensitive }
/// <summary> /// Determines whether tested page is dotvvm. /// </summary> /// <param name="browser"></param> /// <returns></returns> public static bool IsDotvvmPage(this IBrowserWrapper browser) { try { return(string.Equals("true", browser.GetJavaScriptExecutor().ExecuteScript("return dotvvm instanceof DotVVM").ToString(), StringComparison.OrdinalIgnoreCase)); } catch (Exception ex) { return(false); } }
private void ValidateDefaultRouteLinkState(IBrowserWrapper browser, string suffix = "") { AssertUI.HyperLinkEquals(browser.First("#opt1_empty"), "FeatureSamples/ParameterBinding/OptionalParameterBinding" + suffix, UrlKind.Relative, UriComponents.PathAndQuery); AssertUI.HyperLinkEquals(browser.First("#opt1_param_empty"), "FeatureSamples/ParameterBinding/OptionalParameterBinding" + suffix, UrlKind.Relative, UriComponents.PathAndQuery); AssertUI.HyperLinkEquals(browser.First("#opt1_param_A2"), "FeatureSamples/ParameterBinding/OptionalParameterBinding" + suffix, UrlKind.Relative, UriComponents.PathAndQuery); AssertUI.HyperLinkEquals(browser.First("#opt1_param_ID2"), "FeatureSamples/ParameterBinding/OptionalParameterBinding/4", UrlKind.Relative, UriComponents.PathAndQuery); AssertUI.HyperLinkEquals(browser.First("#opt1_param_ID2A2"), "FeatureSamples/ParameterBinding/OptionalParameterBinding/5", UrlKind.Relative, UriComponents.PathAndQuery); AssertUI.HyperLinkEquals(browser.First("#opt2_empty"), "FeatureSamples/ParameterBinding/OptionalParameterBinding2/300", UrlKind.Relative, UriComponents.PathAndQuery); AssertUI.HyperLinkEquals(browser.First("#opt2_param_A"), "FeatureSamples/ParameterBinding/OptionalParameterBinding2/300", UrlKind.Relative, UriComponents.PathAndQuery); AssertUI.HyperLinkEquals(browser.First("#opt2_param_2"), "FeatureSamples/ParameterBinding/OptionalParameterBinding2/3", UrlKind.Relative, UriComponents.PathAndQuery); AssertUI.HyperLinkEquals(browser.First("#opt2_param_ID2A2"), "FeatureSamples/ParameterBinding/OptionalParameterBinding/4", UrlKind.Relative, UriComponents.PathAndQuery); }
private void CheckSeparators(IBrowserWrapper browser, string repeaterDataUi) { var repeater = browser.Single(repeaterDataUi, this.SelectByDataUi); for (int i = 0; i < repeater.Children.Count; i++) { if (i % 2 == 0) { AssertUI.Attribute(repeater.Children[i], "data-ui", s => s == "item"); } else { AssertUI.Attribute(repeater.Children[i], "data-ui", s => s == "separator"); } } }
private void CheckRadioButtonsState(IBrowserWrapper browser, RadioButtonValues selectedColor) { var radios = new List <IElementWrapper>(); radios.Add(browser.Single("radio-red", this.SelectByDataUi)); radios.Add(browser.Single("radio-green", this.SelectByDataUi)); radios.Add(browser.Single("radio-blue", this.SelectByDataUi)); var selectedColorElement = browser.Single("selected-color", this.SelectByDataUi); int checkedRadioIndex = (int)selectedColor; AssertUI.IsChecked(radios[checkedRadioIndex]); radios.RemoveAt(checkedRadioIndex); radios.ForEach(AssertUI.IsNotChecked); AssertUI.TextEquals(selectedColorElement, selectedColor.ToString().ToLower()); }
private void ReturnedFileDownload(IBrowserWrapper browser, string fileContent) { browser.NavigateToUrl(SamplesRouteUrls.FeatureSamples_ReturnedFile_ReturnedFileSample); var jsexec = browser.GetJavaScriptExecutor(); jsexec.ExecuteScript("window.downloadURL = \"\";"); jsexec.ExecuteScript("DotVVM.prototype.performRedirect = function(url){window.downloadURL = url};"); browser.First("textarea").SendKeys(fileContent); browser.First("input").SendKeys(Keys.Enter); var downloadURL = (string)jsexec.ExecuteScript("return window.downloadURL;"); Assert.IsNotNull(downloadURL); string returnedFile; using (var client = new WebClient()) { returnedFile = client.DownloadString(browser.GetAbsoluteUrl(downloadURL)); } Assert.AreEqual(fileContent, returnedFile); }
private void AddExceptionMetadata(TestExceptionBase exception, IBrowserWrapper wrapper) { ExecuteSafe(() => { exception.WebBrowser = CurrentWebBrowser.Factory.Name; }); var result = ExecuteSafe(() => { exception.CurrentUrl = CurrentWebBrowser.Driver.Url; }); // when browser is frozen then taking screenshot is non-sense. if (!result) { return; } ExecuteSafe(() => { try { exception.Screenshot = TakeScreenshot(wrapper); } catch { //TODO try take a screenshot by other way } }); }
private static void Feature_StaticCommand_ComboBoxSelectionChangedViewModel_Core(IBrowserWrapper browser) { browser.Wait(); // select second value in the first combo box, the second one should select the second value too browser.ElementAt("select", 0).Select(1).Wait(); browser.ElementAt("select", 1).Select(1).Wait(); AssertUI.IsSelected(browser.ElementAt("select", 0).ElementAt("option", 1)); AssertUI.IsSelected(browser.ElementAt("select", 1).ElementAt("option", 1)); // select third value in the first combo box, the second one should select the third value too browser.ElementAt("select", 0).Select(2).Wait(); browser.ElementAt("select", 1).Select(2).Wait(); AssertUI.IsSelected(browser.ElementAt("select", 0).ElementAt("option", 2)); AssertUI.IsSelected(browser.ElementAt("select", 1).ElementAt("option", 2)); // select first value in the first combo box, the second one should select the first value too browser.ElementAt("select", 0).Select(0).Wait(); browser.ElementAt("select", 1).Select(0).Wait(); AssertUI.IsSelected(browser.ElementAt("select", 0).ElementAt("option", 0)); AssertUI.IsSelected(browser.ElementAt("select", 1).ElementAt("option", 0)); // click the first button - the second value should be selected in the first select, the second select should not change browser.ElementAt("input", 0).Click().Wait(); AssertUI.IsSelected(browser.ElementAt("select", 0).ElementAt("option", 1)); AssertUI.IsSelected(browser.ElementAt("select", 1).ElementAt("option", 0)); // click the second button - the third value should be selected in the second select, the first select should not change browser.ElementAt("input", 1).Click().Wait(); AssertUI.IsSelected(browser.ElementAt("select", 0).ElementAt("option", 1)); AssertUI.IsSelected(browser.ElementAt("select", 1).ElementAt("option", 2)); // click the third button - the first value should be selected in the second select, the first select should not change browser.ElementAt("input", 2).Click().Wait(); AssertUI.IsSelected(browser.ElementAt("select", 0).ElementAt("option", 1)); AssertUI.IsSelected(browser.ElementAt("select", 1).ElementAt("option", 0)); }
private static void CheckIfInnerTextEqualsToOne(IBrowserWrapper browser, string dataUi) { AssertUI.InnerTextEquals(browser.FindElements($"[data-ui='{dataUi}']").First(), 1.ToString()); }
public BrowserLoadedEventArgsImpl(IBrowserWrapper <TFrame, TRequest> browser) { this.browser = browser; }
public void TestInit() { browser = CreateMockedIBrowserWrapper(); }
/// <summary> /// Initializes a new instance of the <see cref="Core.ElementWrapper"/> class. /// </summary> /// <param name="webElement">The web element.</param> /// <param name="browserWrapper">The browser wrapper.</param> /// <param name="selector">The selector.</param> public ElementWrapperFluentApi(IWebElement webElement, IBrowserWrapper browserWrapper) : base(webElement, browserWrapper) { }
public FlightSearchPageObject(IBrowserWrapper browser) : base(browser) { SearchForm = new SearchFormControlObject(browser); }
private void ValidatePostbackHandlersComplexSection(string sectionSelector, IBrowserWrapper browser) { IElementWrapper section = null; browser.WaitFor(() => { section = browser.First(sectionSelector); }, 2000, "Cannot find static commands section."); var index = browser.First("[data-ui=\"command-index\"]"); // confirm first section.ElementAt("input[type=button]", 0).Click(); AssertUI.AlertTextEquals(browser, "Confirmation 1"); browser.ConfirmAlert(); browser.Wait(); AssertUI.InnerTextEquals(index, "1"); // cancel second section.ElementAt("input[type=button]", 1).Click(); AssertUI.AlertTextEquals(browser, "Confirmation 1"); browser.ConfirmAlert(); browser.Wait(); AssertUI.AlertTextEquals(browser, "Confirmation 2"); browser.DismissAlert(); browser.Wait(); AssertUI.InnerTextEquals(index, "1"); // confirm second section.ElementAt("input[type=button]", 1).Click(); AssertUI.AlertTextEquals(browser, "Confirmation 1"); browser.ConfirmAlert(); browser.Wait(); AssertUI.AlertTextEquals(browser, "Confirmation 2"); browser.ConfirmAlert(); browser.Wait(); AssertUI.InnerTextEquals(index, "2"); // confirm third section.ElementAt("input[type=button]", 2).Click(); Assert.IsFalse(browser.HasAlert()); browser.Wait(); AssertUI.InnerTextEquals(index, "3"); // confirm fourth section.ElementAt("input[type=button]", 3).Click(); AssertUI.AlertTextEquals(browser, "Generated 1"); browser.ConfirmAlert(); browser.Wait(); AssertUI.InnerTextEquals(index, "4"); // confirm fifth section.ElementAt("input[type=button]", 4).Click(); AssertUI.AlertTextEquals(browser, "Generated 2"); browser.ConfirmAlert(); browser.Wait(); AssertUI.InnerTextEquals(index, "5"); // confirm conditional section.ElementAt("input[type=button]", 5).Click(); Assert.IsFalse(browser.HasAlert()); browser.Wait(); AssertUI.InnerTextEquals(index, "6"); browser.First("input[type=checkbox]").Click(); section.ElementAt("input[type=button]", 5).Click(); AssertUI.AlertTextEquals(browser, "Conditional 1"); browser.ConfirmAlert(); browser.Wait(); AssertUI.InnerTextEquals(index, "6"); browser.First("input[type=checkbox]").Click(); section.ElementAt("input[type=button]", 5).Click(); Assert.IsFalse(browser.HasAlert()); browser.Wait(); AssertUI.InnerTextEquals(index, "6"); browser.First("input[type=checkbox]").Click(); section.ElementAt("input[type=button]", 5).Click(); AssertUI.AlertTextEquals(browser, "Conditional 1"); browser.ConfirmAlert(); browser.Wait(); AssertUI.InnerTextEquals(index, "6"); //localization - resource binding in confirm postback handler message section.ElementAt("input[type=button]", 6).Click(); AssertUI.AlertTextEquals(browser, "EnglishValue"); browser.ConfirmAlert(); browser.Wait(); AssertUI.InnerTextEquals(index, "7"); browser.First("#ChangeLanguageCZ").Click(); browser.WaitFor(() => { index = browser.First("[data-ui=\"command-index\"]"); AssertUI.InnerTextEquals(index, "0"); }, 1500, "Redirect to CZ localization failed."); section = browser.First(sectionSelector); //ChangeLanguageEN section.ElementAt("input[type=button]", 6).Click(); AssertUI.AlertTextEquals(browser, "CzechValue"); browser.DismissAlert(); browser.Wait(); AssertUI.InnerTextEquals(index, "0"); section.ElementAt("input[type=button]", 6).Click(); AssertUI.AlertTextEquals(browser, "CzechValue"); browser.ConfirmAlert(); browser.Wait(); AssertUI.InnerTextEquals(index, "7"); }
private void Control_GridViewShowHeaderWhenNoData(IBrowserWrapper browser) { browser.FindElements("[data-ui='ShowHeaderWhenNoDataGrid']").FindElements("th").First().IsDisplayed(); }
private void CheckTreeItems(IBrowserWrapper browser, int level, int count) { browser.FindElements($"[data-ui='offset_{level}']").ThrowIfDifferentCountThan(count); }