public void SElementSearchIsLazyAndDoesNotStartOnCreation() { Given.OpenedEmptyPage(); var nonExistentElement = Selene.S("#not-existing-element-id"); Assert.IsNotEmpty(nonExistentElement.ToString()); }
public void InnerSCollectionSearchWaitsNothing() { Given.OpenedEmptyPage(); var elements = Selene.S("div").SS(".will-appear"); When.WithBody(@" <div> <ul>Hello to: <li class='will-appear'>Bob</li> <li class='will-appear' style='display:none'>Kate</li> </ul> </div>" ); When.WithBodyTimedOut(@" <div> <ul>Hello to: <li class='will-appear'>Bob</li> <li class='will-appear' style='display:none'>Kate</li> <li class='will-appear'>Bobik</li> </ul> </div>", 500 ); Assert.AreEqual(2, elements.Count); }
public void SeleneWaitTo_HaveJsReturned_WaitsForPresenceInDom_OfInitiialyAbsent() { Configuration.Timeout = 0.6; Configuration.PollDuringWaits = 0.1; Given.OpenedEmptyPage(); var beforeCall = DateTime.Now; Given.OpenedPageWithBodyTimedOut( @" <p style='display:none'>a</p> <p style='display:none'>b</p> ", 300 ); Selene.WaitTo(Have.JSReturnedTrue( @" var expectedCount = arguments[0] return document.getElementsByTagName('p').length == expectedCount " , 2 )); var afterCall = DateTime.Now; Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); }
public void WaitForVisibility_OnActionsLikeClick_AfterFirstWaitingForParentToBeDisplaid() { Configuration.Timeout = 1.0; Configuration.PollDuringWaits = 0.05; Given.OpenedPageWithBody(@" <p style='display:none'> <a href='#second' style='display:none'>go to Heading 2</a> <h2 id='second'>Heading 2</h2> </p>" ); var beforeCall = DateTime.Now; Selene.ExecuteScript(@" setTimeout( function(){ document.getElementsByTagName('p')[0].style = 'display:block'; }, 400); setTimeout( function(){ document.getElementsByTagName('a')[0].style = 'display:block'; }, 700); " ); S("p").Find("a").Click(); var afterCall = DateTime.Now; Assert.Greater(afterCall, beforeCall.AddSeconds(0.7)); Assert.Less(afterCall, beforeCall.AddSeconds(1.5)); Assert.IsTrue(Configuration.Driver.Url.Contains("second")); }
public static void OpenedEmptyPage() { String uri = new Uri(Path.Combine( runFromAssemblyLocation ? Assembly.GetExecutingAssembly().Location : Directory.GetCurrentDirectory(), emptyPage)).AbsoluteUri; Selene.Open(uri); }
public void YandexTextSearch() { String emptySearchResponse = "Задан пустой поисковый запрос"; Selene.GoToUrl("https://yandex.ru/search"); Selene.S(With.Text(emptySearchResponse)).Should(Have.Text(emptySearchResponse)); }
// TODO: consider renaming to WithBodyTimedOut public static void WithBodyTimedOut(string pageBody, int timeout) { Selene.ExecuteScript(@" setTimeout( function(){ document.getElementsByTagName('body')[0].innerHTML = " + PrepareBodyHTML(pageBody) + "}, " + timeout + ");"); }
public static void ExecuteScriptWithTimeout(string script, int timeout) { // NOTE: script may contain newlines Selene.ExecuteScript(@" setTimeout( function(){ " + script + @" }, " + timeout + ");"); }
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 static void WithBody(string html) { Selene.ExecuteScript( "document.getElementsByTagName('body')[0].innerHTML = \"" + html.Replace("\n", "").Replace("\r", "").Replace("\"", "\\\"") + "\";" ); }
public void FoundByConditionSElementSearchIsLazyAndDoesNotStartEvenOnFollowingInnerSearch() {//TODO: consider testing using FindBy(Have.CssClass("...")) Given.OpenedPageWithBody("<p>have no any items nor visible nor hidden</p>"); var nonExistentElement = Selene.SS(".not-existing").FindBy(Be.Visible).Find("#not-existing-inner"); Assert.IsNotEmpty(nonExistentElement.ToString()); }
public void SCollectionShouldBeEmpty() { Given.OpenedEmptyPage(); Selene.SS("li").Should(Be.Empty); When.WithBody("<ul>Hello to:<li>Dear Bob</li><li>Lovely Kate</li></ul>"); Selene.SS("li").ShouldNot(Be.Empty); }
public void InnerSCollectionSearchIsUpdatedOnNextActualActionLikeQuestioiningCount() { Given.OpenedEmptyPage(); var elements = Selene.S("div").SS(".will-appear"); When.WithBody(@" <div> <ul>Hello to: <li class='will-appear'>Bob</li> <li class='will-appear'>Kate</li> </ul> </div>" ); Assert.AreEqual(2, elements.Count); When.WithBody(@" <div> <ul>Hello to: <li class='will-appear'>Bob</li> <li class='will-appear'>Kate</li> <li class='will-appear'>Joe</li> </ul> </div>" ); Assert.AreEqual(3, elements.Count); }
public static void WithBody(string html) { Selene.ExecuteScript( "document.getElementsByTagName('body')[0].innerHTML = `" + html + "`;" ); }
public void InitDriver() { NSelene.Configuration.Timeout = this.Settings.NSelene.Timeout; IWebDriver webDriver; if (this.Settings.WebDriver.Local == "chrome") { new DriverManager().SetUpDriver(new ChromeConfig()); webDriver = new ChromeDriver(); } else { var options = new ChromeOptions() .AddGlobal("enableVNC", this.Settings.WebDriver.Remote.enableVNC) .AddGlobal("enableVideo", this.Settings.WebDriver.Remote.enableVideo); webDriver = new RemoteWebDriver( new Uri(this.Settings.WebDriver.Remote.uri), options); } Selene.SetWebDriver(webDriver); }
public void SElementSearchIsLazyAndDoesNotStartEvenOnFollowingInnerSearch() { Given.OpenedEmptyPage(); var nonExistentElement = Selene.S("#not-existing").Find("#not-existing-inner"); Assert.IsNotEmpty(nonExistentElement.ToString()); }
public static void Add(params string[] taskTexts) { foreach (var text in taskTexts) { Selene.S("#new-todo").Should(Be.Enabled).SetValue(text).PressEnter(); } }
public void IndexedSElementSearchIsLazyAndDoesNotStartEvenOnFollowingInnerSearch() { Given.OpenedPageWithBody("<p>have no any items</p>"); var nonExistentElement = Selene.SS(".not-existing")[10].Find("#not-existing-inner"); Assert.IsNotEmpty(nonExistentElement.ToString()); }
public void SElementShouldHaveAttribute() { Given.OpenedPageWithBody("<h1 class='big-title'>Hello Babe!</h1>"); Selene.S("h1").ShouldNot(Have.Attribute("class", "big title")); When.WithBody("<h1 class='big title'>Hello world!</h1>"); Selene.S("h1").Should(Have.Attribute("class", "big title")); }
public void SElementShouldBeInDOM() { Given.OpenedEmptyPage(); Selene.S("h1").ShouldNot(Be.InDom); When.WithBody("<h1 style='display:none'>ku ku</h1>"); Selene.S("h1").Should(Be.InDom); }
public void SElementShouldBeEnabled() { Given.OpenedPageWithBody("<input type='text' disabled/>"); Selene.S("input").ShouldNot(Be.Enabled); When.WithBody("<input type='text'/>"); Selene.S("input").Should(Be.Enabled); }
public void FoundByConditionSElementSearchIsLazyAndDoesNotStartOnCreation() { Given.OpenedPageWithBody("<p>have no any items nor visible nor hidden</p>"); var nonExistentElement = Selene.SS(".not-existing").FindBy(Be.Visible); Assert.IsNotEmpty(nonExistentElement.ToString()); }
public void InnerSElementSearchIsLazyAndDoesNotStartOnCreation() { Given.OpenedPageWithBody("<p id='#existing'>Hello!</p>"); var nonExistentElement = Selene.S("#existing").Find("#not-existing-inner"); Assert.IsNotEmpty(nonExistentElement.ToString()); }
public void SeleneWaitTo_HaveNoJsReturned_IsRenderedInError_OnInDomElementsTimeoutFailure() { Configuration.Timeout = 0.25; Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @" <p style='display:none'>a</p> <p style='display:none'>b</p> " ); var beforeCall = DateTime.Now; try { Selene.WaitTo(Have.No.JSReturnedTrue( @" var expectedCount = arguments[0] return document.getElementsByTagName('p').length == expectedCount " , 2 )); } catch (WebDriverTimeoutException error) { var afterCall = DateTime.Now; Assert.Greater(afterCall, beforeCall.AddSeconds(0.25)); var accuracyDelta = 0.2; Assert.Less(afterCall, beforeCall.AddSeconds(0.25 + 0.1 + accuracyDelta)); // TODO: shoud we check timing here too? var lines = error.Message.Split("\n").Select( item => item.Trim() ).ToList(); Assert.Contains("Timed out after 0.25 seconds", lines); Assert.Contains("while waiting entity with locator: OpenQA.Selenium.Chrome.ChromeDriver", lines); Assert.Contains("for condition: not JSReturnedTrue", lines); } // catch (TimeoutException error) // { // var afterCall = DateTime.Now; // Assert.Greater(afterCall, beforeCall.AddSeconds(0.25)); // var accuracyDelta = 0.2; // Assert.Less(afterCall, beforeCall.AddSeconds(0.25 + 0.1 + accuracyDelta)); // // TODO: shoud we check timing here too? // 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.All(p).not count = 2", lines); // Assert.Contains("Reason:", lines); // Assert.Contains("actual: count = 2", lines); // } }
public void SElementShouldHaveValue() { Given.OpenedEmptyPage(); Selene.S("input").ShouldNot(Have.Value("Yo")); When.WithBody("<input value='Yo'></input>"); Selene.S("input").ShouldNot(Have.Value("o_O")); Selene.S("input").Should(Have.Value("Yo")); }
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 SCollectionSearchIsLazyAndDoesNotStartOnCreation() { var nonExistingCollection = Selene.SS(".not-existing"); Assert.IsNotEmpty(nonExistingCollection.ToString()); // TODO: think on improving... actually it does not tell search is not started // it would tell if browser is quited at the moment... but it is not... }
public void SElementSearchIsPostponedUntilActualActionLikeQuestioiningDisplayed() { Given.OpenedEmptyPage(); var element = Selene.S("#will-be-existing-element-id"); When.WithBody(@"<h1 id='will-be-existing-element-id'>Hello kitty:*</h1>"); Assert.IsTrue(element.Displayed); }
public void QuitDriver() { if (this.Settings.WebDriver.HoldBrowserOpen) { return; } Selene.GetWebDriver().Quit(); }
public static void OpenedEmptyPage() { Selene.Open( new Uri( new Uri(Assembly.GetExecutingAssembly().Location), "../../../Resources/empty.html" ).AbsoluteUri ); }