public void Search() { Open("http://google.com/ncr"); S(By.Name("q")).SetValue("Selenide").PressEnter(); SS(".srg>.g")[0].Should(Have.Text("Selenide: concise UI tests in Java")); }
public void YandexTextSearch() { String emptySearchResponse = "Задан пустой поисковый запрос"; Selene.GoToUrl("https://yandex.ru/search"); Selene.S(With.Text(emptySearchResponse)).Should(Have.Text(emptySearchResponse)); }
public void SEeleneCollectionSearchWithText() { String searchText = "Dear"; String xpathTextSearch = String.Format("//*[contains(text(),'{0}')]", searchText); // search using wrapped driver methods ReadOnlyCollection <IWebElement> webElements = Selene.GetWebDriver().FindElements(By.XPath(xpathTextSearch)); Assert.NotNull(webElements); Assert.Greater(webElements.Count, 0); StringAssert.Contains(searchText, webElements[0].Text); // search thru NSelene By seleneLocator = NSelene.With.Text(searchText); IWebDriver webDriver = Selene.GetWebDriver(); SeleneCollection seleWebElements = Selene.SS(seleneLocator); Assert.NotNull(seleWebElements); Assert.AreEqual(seleWebElements.Count, webElements.Count); StringAssert.Contains(searchText, seleWebElements[0].Text); // confirm all have searchText seleWebElements = Selene.SS(seleneLocator, webDriver); Assert.AreEqual(seleWebElements.FilterBy(Have.Text(searchText)).Count, seleWebElements.Count); // exercise NSelene extension methods Selene.SS(seleneLocator).Should(Have.Texts("Bob", "Frank")); Selene.SS(seleneLocator).ShouldNot(Have.Texts("Bob")); Selene.SS(seleneLocator).ShouldNot(Have.Texts("Bob", "Kate", "Frank")); Selene.SS(seleneLocator).Should(Have.ExactTexts("Dear Bob", "Dear Frank")); }
public void Should_HaveText_IsRenderedInError_OnElementDifferentTextFailure() { Configuration.Timeout = 0.25; Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @" <label>initial</label> " ); try { S("label").Should(Have.Text("new")); } catch (TimeoutException error) { var lines = error.Message.Split("\n").Select( item => item.Trim() ).ToList(); Assert.Contains("Timed out after 0.25s, while waiting for:", lines); Assert.Contains("Browser.Element(label).Should(Have.TextContaining(«new»))", lines); Assert.Contains("Reason:", lines); Assert.Contains("Actual text: «initial»", lines); Assert.Contains( "Actual webelement: <label>initial</label>", lines ); Assert.AreEqual( "initial", Configuration.Driver.FindElement(By.TagName("label")).Text ); } }
public void Should_HaveText_WaitsForVisibility_OfInitialyHidden() { Configuration.Timeout = 0.6; Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @" <label style='display:none'>initial</label> " ); var beforeCall = DateTime.Now; Given.ExecuteScriptWithTimeout( @" document.getElementsByTagName('label')[0].style.display = 'block'; ", 300 ); S("label").Should(Have.Text("initial")); var afterCall = DateTime.Now; Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); Assert.AreEqual( "initial", Configuration.Driver .FindElement(By.TagName("label")).Text ); }
public void Search() { Google.Open(); Google.Search("selenide"); Google.Results[0].Should(Have.Text("Selenide: concise UI tests in Java")); }
public void HaveText() { Given.OpenedPageWithBody("<h1>Hello Babe!</h1>"); S("h1").Should(Have.Text("Hello")); S("h1").Should(Have.No.Text("Hello world!")); S("h1").Should(Have.No.ExactText("Hello")); S("h1").Should(Have.ExactText("Hello Babe!")); }
public void SElementShouldHaveText() { Given.OpenedPageWithBody("<h1>Hello Babe!</h1>"); Selene.S("h1").Should(Have.Text("Hello")); Selene.S("h1").ShouldNot(Have.Text("Hello world!")); Selene.S("h1").ShouldNot(Have.ExactText("Hello")); Selene.S("h1").Should(Have.ExactText("Hello Babe!")); }
public void HookWaitAction_SetPerElements_CanLogActionsLikeClickAndShould() { List <string> log = new List <string>(); Configuration.Timeout = 0.1; Configuration.PollDuringWaits = 0.01; Action <object, Func <string>, Action> logIt = (entityObject, describeComputation, wait) => { log.Add($"{entityObject}.{describeComputation()}: STARTED"); try { wait(); log.Add($"{entityObject}.{describeComputation()}: PASSED"); } catch (Exception error) { log.Add($"{entityObject}.{describeComputation()}: FAILED"); throw error; } }; Given.OpenedPageWithBody(@" <button>Click me!</button> "); var button = S("button").With(_hookWaitAction: logIt); var allButtons = SS("button").With(_hookWaitAction: logIt); var absent = S(".absent").With(_hookWaitAction: logIt); var allAbsent = SS(".absent").With(_hookWaitAction: logIt); allButtons.Should(Have.Count(1)); button.Should(Have.ExactText("Click me!")); button.Click(); button.With(clickByJs: true).Click(); try { absent.Click(); } catch {} try { absent.Should(Have.Text("some")); } catch {} try { allAbsent.Should(Have.Count(1)); } catch {} try { absent.FindAll(".child").Should(Have.Count(1)); } catch {} Assert.AreEqual(log, @"Browser.All(button).Should(Have.Count = 1): STARTED Browser.All(button).Should(Have.Count = 1): PASSED Browser.Element(button).Should(Have.ExactText(«Click me!»)): STARTED Browser.Element(button).Should(Have.ExactText(«Click me!»)): PASSED Browser.Element(button).ActualWebElement.Click(): STARTED Browser.Element(button).ActualWebElement.Click(): PASSED Browser.Element(button).JsClick(centerXOffset: 0, centerYOffset: 0): STARTED Browser.Element(button).JsClick(centerXOffset: 0, centerYOffset: 0): PASSED Browser.Element(.absent).ActualWebElement.Click(): STARTED Browser.Element(.absent).ActualWebElement.Click(): FAILED Browser.Element(.absent).Should(Have.TextContaining(«some»)): STARTED Browser.Element(.absent).Should(Have.TextContaining(«some»)): FAILED Browser.All(.absent).Should(Have.Count = 1): STARTED Browser.All(.absent).Should(Have.Count = 1): FAILED Browser.Element(.absent).All(.child).Should(Have.Count = 1): STARTED Browser.Element(.absent).All(.child).Should(Have.Count = 1): FAILED" .Split("\n").Select(item => item.Trim()).ToList() ); }
public void FindByRequestOther() { var searchRequest = "PUBLIC OFFERING"; _homePage.SearchByRequest(searchRequest); _searchResultPage.SearchResultItemByText(searchRequest) .Should(Have.Text(searchRequest)); }
public void FindByRequest() { var searchRequest = "TBC Bank CEO"; _homePage.SearchByRequest(searchRequest); _searchResultPage.SearchResultItemByText(searchRequest) .Should(Have.Text(searchRequest)); }
public void Search() { Open("http://google.com/ncr"); S(By.Name("q")).SetValue("Selenide").PressEnter(); SS(".srg>.g")[0].Should(Have.Text("Selenide: concise UI tests in Java")); SS(".srg>.g")[0].Find("h3>a").Click(); wait.Until(UrlToBe("http://selenide.org/")); }
public void SElementLocalizedTextSearch() { String name = "абвгдежзийклмнопрстуфхцчшщъыьэюя"; Given.OpenedPageWithBody(String.Format("<h1>Hello {0}!</h1>", name)); Selene.S(With.Text(name)).Should(Have.Text(String.Format("Hello {0}!", name))); IWebDriver driver = Selene.GetWebDriver(); IWebElement element = driver.FindElement(By.XPath(String.Format("//h1[contains(text(), '{0}')]", name))); StringAssert.AreEqualIgnoringCase("h1", element.TagName); Selene.S(With.XPath(String.Format("//h1[contains(text(), '{0}')]", name))).Should(Have.Text(String.Format("Hello {0}!", name))); }
public void SetEmployeeDataAndView(String strEmployeeName, String date) { TxtEmployeeName.Should(Be.Visible).SetValue(strEmployeeName); EmployeeSearchResultSection.Should(Have.Text(strEmployeeName)).Click(); // Set date via JS. Selene.ExecuteScript( @" document.getElementById('attendance_date') .value = " + '"' + date + '"' + "" ); BtnView.Click(); TableResults.Should(Be.Visible); }
public void Should_HaveText_DoesNotWaitForNoOverlay() // TODO: but should it? { Configuration.Timeout = 0.6; Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @" <div id='overlay' style=' display:block; position: fixed; display: block; width: 100%; height: 100%; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0,0,0,0.1); z-index: 2; cursor: pointer; ' > </div> <label>initial</label> " ); var beforeCall = DateTime.Now; Given.ExecuteScriptWithTimeout( @" document.getElementById('overlay').style.display = 'none'; ", 300 ); S("label").Should(Have.Text("initial")); var afterCall = DateTime.Now; Assert.Less(afterCall, beforeCall.AddSeconds(0.3)); Assert.AreEqual( "initial", Configuration.Driver .FindElement(By.TagName("label")).Text ); // Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); // Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); }
public void SElementSearchWithTextResultConditons() { String searchText = "Hello there!"; String xpathSearchText = String.Format(@"//*[contains(text(), ""{0}"")]", searchText); IWebDriver webDriver = Selene.GetWebDriver(); IWebElement element = webDriver.FindElement(By.XPath(xpathSearchText)); StringAssert.Contains(searchText, element.Text); // verify can use part of the search text in the condition Selene.S(NSelene.With.Text(searchText)).Should(Have.Text("Hello")); // verify can use the raw text in assertions - more about it in a dedicated class(es) SElementTextMultiLineSearchTests Selene.S(NSelene.With.Text("there!"), webDriver).Should(Have.ExactText(searchText)); Selene.S(NSelene.With.ExactText(element.Text), webDriver).Should(Have.ExactText(element.Text)); }
public void SElementMultilineTextSearch() { String[] names = { "Alice", "Bob" }; String elementText = String.Format(@" Hello {0} and {1}!", names[0], names[1]); Given.OpenedPageWithBody(String.Format(@"<h1>{0}</h1>", elementText)); IWebDriver driver = Selene.GetWebDriver(); String searchText = Regex.Replace(elementText.Replace("\n", " ").Replace("\r", ""), "^ +", ""); IWebElement element = driver.FindElement(By.XPath(String.Format("//h1[contains(text(), '{0}')]", searchText))); Assert.NotNull(element); StringAssert.AreEqualIgnoringCase("h1", element.TagName); Selene.S(With.XPath(String.Format("//h1[contains(text(), '{0}')]", searchText))).Should(Be.InDom).Should(Have.Text(String.Format("Hello {0}", names[0]))); Selene.S(With.Text(names[0])).Should(Have.Text(searchText)); }
public void Should_HaveText_WaitsForAskedText_OfInitialyOtherText() { Configuration.Timeout = 0.6; Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @" <label>initial</label> " ); var beforeCall = DateTime.Now; Given.OpenedPageWithBodyTimedOut( @" <label>new</label> " , 300 ); S("label").Should(Have.Text("new")); var afterCall = DateTime.Now; Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); Assert.AreEqual( "new", Configuration.Driver .FindElement(By.TagName("label")).Text ); Assert.AreEqual( "new", Configuration.Driver .FindElement(By.TagName("label")).Text ); }
public void MultilineTextSearchIntegrationTest() { String url = "http://www.rfbr.ru/rffi/ru/"; String cssSelector = "div.grants > p"; // NOTE: The element on the page has a <br/> and a newline // removing newline makes the search string one space shorter // searchString = "Информация для заявителейи исполнителей проектов"; // making it difficult to impossible to "predict" the right matching expression String searchString = @"Информация для заявителей и исполнителей проектов"; Selene.GoToUrl(url); // NOTE: slurps exceptions but not in a "Nunit" way try { // Selene.S(With.Text(searchString)).Should(Be.InDom); Selene.S(String.Format("text={0}", searchString.Replace("\n", "").Replace("\r", "")), Selene.GetWebDriver()).Should(Be.InDom); // Selene.S(With.Text(searchString)).Should(Have.Text(searchString)); } catch (TimeoutException e) { Console.Error.WriteLine("Exception (ignored) " + e.ToString()); } catch (NoSuchElementException e) { Console.Error.WriteLine("Exception (ignored) " + e.ToString()); } // Break down the element text into single line chunks, successfully find each string elementText = (Selene.GetWebDriver()).FindElement(By.CssSelector(cssSelector)).Text; elementText = Selene.S(With.Css(cssSelector)).Text; foreach (String line in elementText.Split('\n')) { searchString = line.Replace("\r", ""); Console.Error.WriteLine("Searching by inner Text fragment:" + searchString); Selene.S(With.Text(searchString)).Should(Be.InDom); Selene.S(With.Text(searchString)).Should(Have.Text(searchString)); } }
public Results ShouldHaveText(int index, string value) { list[index].Should(Have.Text(value)); return(this); }
public SeleneElement SearchResultItemByText(string searchResultItemText) { return(SearchResultItems .FindBy(Have.Text(searchResultItemText))); }
public void AssertNthResultHasText(int index, string text) { this.Results[index].Should(Have.Text(text)); }