public void Should_HaveCount_IsRenderedInError_OnAbsentElementTimeoutFailure() { Configuration.Timeout = 0.25; Configuration.PollDuringWaits = 0.1; Given.OpenedEmptyPage(); var beforeCall = DateTime.Now; try { SS("p").Should(Have.Count(2)); } 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).count = 2", lines); Assert.Contains("Reason:", lines); Assert.Contains("actual: count = 0", lines); } }
public void Should_HaveCount_WaitsForAsked_OfInitialyOtherVisibleCount() { Configuration.Timeout = 0.6; Configuration.PollDuringWaits = 0.1; Given.OpenedPageWithBody( @" <p>a</p> " ); var beforeCall = DateTime.Now; Given.OpenedPageWithBodyTimedOut( @" <p>a</p> <p>b</p> " , 300 ); SS("p").Should(Have.Count(2)); var afterCall = DateTime.Now; Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); Assert.Less(afterCall, beforeCall.AddSeconds(0.6)); Assert.AreEqual( 2, Configuration.Driver .FindElements(By.TagName("p")).Count ); }
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 SCollectionShouldHaveCountAtLeastAndCount() { Given.OpenedEmptyPage(); SS("li").ShouldNot(Have.Count(2)); When.WithBody("<ul>Hello to:<li>Dear Bob</li><li>Lovely Kate</li></ul>"); SS("li").ShouldNot(Have.CountAtLeast(3)); SS("li").Should(Have.Count(2)); SS("li").Should(Have.CountAtLeast(1)); }
public void ReturnsFalse_AfterWaitingTimeout_OnNotMatched_WithExceptionReason() { Configuration.Timeout = 0.75; var beforeCall = DateTime.Now; var result = SS("#absent").WaitUntil(Have.Count(2)); var afterCall = DateTime.Now; Assert.IsFalse(result); Assert.IsTrue(afterCall >= beforeCall.AddSeconds(Configuration.Timeout)); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (Have.Count() != Want.Count()) { yield break; } if (Have.All(i => Want.Any(j => j.Id == i.Id)) && Want.All(i => Have.Any(j => j.Id == i.Id))) { yield return(new ValidationResult( "It is not possible to create a trade for the same items.", new[] { "Have", "Want" })); } }
public void AllwaysReturnsBoolWithoutWaiting() { var beforeCall = DateTime.Now; Given.OpenedPageWithBody("<p id='existing'>Hello!</p>"); // EXPECT Assert.IsFalse(SS("#absent").Matching(Have.Count(2))); Assert.IsTrue(SS("#absent").Matching(Have.No.Count(2))); Assert.IsTrue(SS("#existing").Matching(Have.Count(1))); Assert.IsFalse(SS("#existing").Matching(Have.No.Count(1))); var afterCall = DateTime.Now; Assert.IsTrue(afterCall < beforeCall.AddSeconds(Configuration.Timeout / 2)); }
public void Should_HaveCount_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 ); SS("p").Should(Have.Count(2)); var afterCall = DateTime.Now; Assert.Greater(afterCall, beforeCall.AddSeconds(0.3)); Assert.Less(afterCall, beforeCall.AddSeconds(1.0)); }