private static void ChangeAndTestLocalization(IBrowserWrapperFluentApi browser) { browser.First("p").CheckIfInnerTextEquals("This comes from resource file!", false, true); // change language browser.Last("a").Click(); browser.First("p").CheckIfInnerTextEquals("Tohle pochází z resource souboru!", false, true); }
private static void CheckUrlGenerationMethod(IBrowserWrapperFluentApi 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 CheckArticleCount(IBrowserWrapperFluentApi 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}"); } }
private void TestLinkButton(IBrowserWrapperFluentApi browser, string id, bool shouldBeEnabled, ref int currentPresses) { browser.First($"#{id}").Click(); if (shouldBeEnabled) { currentPresses++; } browser.First("#linkbuttons-pressed").CheckIfInnerTextEquals(currentPresses.ToString()); }
private void CheckTableRow(IBrowserWrapperFluentApi 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 table.ElementAt("tr", row).ElementAt("td", 1).CheckIfInnerTextEquals(value, false); table.ElementAt("tr", row).ElementAt("td", 2).CheckIfInnerTextEquals(value, false); // server binding renders True with capital T, knockout binding renders true with lower case t -> comparison is case insensitive }
private void CheckSeparators(IBrowserWrapperFluentApi browser, string repeaterDataUi) { var repeater = browser.Single(repeaterDataUi, this.SelectByDataUi); for (int i = 0; i < repeater.Children.Count; i++) { if (i % 2 == 0) { repeater.Children[i].CheckAttribute("data-ui", s => s == "item"); } else { repeater.Children[i].CheckAttribute("data-ui", s => s == "separator"); } } }
private void CheckRadioButtonsState(IBrowserWrapperFluentApi browser, RadioButtonValues selectedColor) { var radios = new List <IElementWrapperFluentApi>(); 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; radios[checkedRadioIndex].CheckIfIsChecked(); radios.RemoveAt(checkedRadioIndex); radios.ForEach(r => r.CheckIfIsNotChecked()); selectedColorElement.CheckIfTextEquals(selectedColor.ToString().ToLower()); }
private void ShowHideControl(IBrowserWrapperFluentApi browser) { // verify the second pager is hidden browser.First(".pagination").CheckIfIsDisplayed(); browser.ElementAt(".pagination", 1).CheckIfIsNotDisplayed(); browser.First("ul").FindElements("li").ThrowIfDifferentCountThan(2); // verify the second pager appears browser.Single("populate-button", this.SelectByDataUi).Click(); // verify the second pager appears browser.First(".pagination").CheckIfIsDisplayed(); browser.ElementAt(".pagination", 1).CheckIfIsDisplayed(); browser.First("ul").FindElements("li").ThrowIfDifferentCountThan(3); // switch to another page browser.First(".pagination").ElementAt("li a", 4).Click(); // verify the second pager is still visible browser.First(".pagination").CheckIfIsDisplayed(); browser.ElementAt(".pagination", 1).CheckIfIsDisplayed(); browser.First("ul").FindElements("li").ThrowIfDifferentCountThan(3); }
private void ReturnedFileDownload(IBrowserWrapperFluentApi browser, string fileContent) { browser.NavigateToUrl(SamplesRouteUrls.FeatureSamples_ReturnedFile_ReturnedFileSample); var jsexec = browser.GetJavaScriptExecutor(); jsexec.ExecuteScript("var downloadURL = \"\";"); jsexec.ExecuteScript("DotVVM.prototype.performRedirect = function(url){downloadURL = url};"); browser.First("textarea").SendKeys(fileContent); browser.First("input").SendKeys(Keys.Enter); var downloadURL = (string)jsexec.ExecuteScript("return downloadURL"); Assert.IsNotNull(downloadURL); string returnedFile; using (var client = new WebClient()) { returnedFile = client.DownloadString(browser.GetAbsoluteUrl(downloadURL)); } Assert.AreEqual(fileContent, returnedFile); }
private void CheckTreeItems(IBrowserWrapperFluentApi browser, int level, int count) { browser.FindElements($"[data-ui='offset_{level}']").ThrowIfDifferentCountThan(count); }
private static void Feature_StaticCommand_ComboBoxSelectionChangedViewModel_Core(IBrowserWrapperFluentApi 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(); browser.ElementAt("select", 0).ElementAt("option", 1).CheckIfIsSelected(); browser.ElementAt("select", 1).ElementAt("option", 1).CheckIfIsSelected(); // 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(); browser.ElementAt("select", 0).ElementAt("option", 2).CheckIfIsSelected(); browser.ElementAt("select", 1).ElementAt("option", 2).CheckIfIsSelected(); // 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(); browser.ElementAt("select", 0).ElementAt("option", 0).CheckIfIsSelected(); browser.ElementAt("select", 1).ElementAt("option", 0).CheckIfIsSelected(); // 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(); browser.ElementAt("select", 0).ElementAt("option", 1).CheckIfIsSelected(); browser.ElementAt("select", 1).ElementAt("option", 0).CheckIfIsSelected(); // 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(); browser.ElementAt("select", 0).ElementAt("option", 1).CheckIfIsSelected(); browser.ElementAt("select", 1).ElementAt("option", 2).CheckIfIsSelected(); // 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(); browser.ElementAt("select", 0).ElementAt("option", 1).CheckIfIsSelected(); browser.ElementAt("select", 1).ElementAt("option", 0).CheckIfIsSelected(); }
private static void CheckIfInnerTextEqualsToOne(IBrowserWrapperFluentApi browser, string dataUi) { browser.FindElements($"[data-ui='{dataUi}']").First().CheckIfInnerTextEquals(1.ToString()); }