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 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 Visit() { Selene.Open("https://todomvc4tasj.herokuapp.com/"); Selene.WaitTo(Have.JSReturnedTrue( "return " + "$._data($('#new-todo').get(0), 'events').hasOwnProperty('keyup')&& " + "$._data($('#toggle-all').get(0), 'events').hasOwnProperty('change') && " + "$._data($('#clear-completed').get(0), 'events').hasOwnProperty('click')")); }
public void JsScrollIntoView() { Given.OpenedPageWithBody("<input style='margin-top:100cm;' type='text' value='ku ku'/>"); SeleneElement element = S("input"); Selene.WaitTo(Have.No.JSReturnedTrue(ELEMENT_IN_VIEW, element.ActualWebElement)); element.JsScrollIntoView(); Selene.WaitTo(Have.JSReturnedTrue(ELEMENT_IN_VIEW, element.ActualWebElement)); }
public void SeleneWaitTo_HaveNoJsReturned_WaitsForAbsenceInDom_OfInitiialyPresent() { Configuration.Timeout = 0.6; Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @" <p style='display:none'>a</p> <p style='display:none'>b</p> " ); var beforeCall = DateTime.Now; Given.WithBodyTimedOut( @" ", 300 ); SS("p").Should(Have.No.Count(2)); Selene.WaitTo(Have.No.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)); Assert.AreEqual( 0, Configuration.Driver .FindElements(By.TagName("p")).Count ); }
public void FilterTasks() { Selene.Open("https://todomvc4tasj.herokuapp.com/"); Selene.WaitTo(Have.JSReturnedTrue( "return " + "$._data($('#new-todo').get(0), 'events').hasOwnProperty('keyup')&& " + "$._data($('#toggle-all').get(0), 'events').hasOwnProperty('change') && " + "$._data($('#clear-completed').get(0), 'events').hasOwnProperty('click')")); Selene.S("#new-todo").SetValue("a").PressEnter(); Selene.S("#new-todo").SetValue("b").PressEnter(); Selene.S("#new-todo").SetValue("c").PressEnter(); Selene.SS("#todo-list>li").Should(Have.ExactTexts("a", "b", "c")); Selene.SS("#todo-list>li").FindBy(Have.ExactText("b")).Find(".toggle").Click(); Selene.S(By.LinkText("Active")).Click(); Selene.SS("#todo-list>li").FilterBy(Be.Visible).Should(Have.ExactTexts("a", "c")); Selene.S(By.LinkText("Completed")).Click(); Selene.SS("#todo-list>li").FilterBy(Be.Visible).Should(Have.ExactTexts("b")); }
internal void ShouldBeOn(string pageTitleText) { Selene.WaitTo(Match.TitleContaining(pageTitleText)); }