public void It_checks_all_of_the_states_in_a_robust_query_expecting_true() { bool queriedState1 = false; bool queriedState2 = false; var state1 = new State(new LambdaQuery<bool>(() => { queriedState1 = true; return false; })); var state2 = new State(new LambdaQuery<bool>(() => { queriedState2 = true; return true; })); var state3 = new State(new LambdaQuery<bool>(() => true)); state3.CheckCondition(); var robustWrapper = new SpyTimingStrategy(); robustWrapper.StubQueryResult(true, true); var session = BuildSession(robustWrapper); Assert.That(session.FindState(new [] {state1, state2, state3}), Is.SameAs(state3)); Assert.IsFalse(queriedState1); Assert.IsFalse(queriedState2); var query = robustWrapper.QueriesRan<bool>().Single(); var queryResult = query.Run(); Assert.IsTrue(queryResult); Assert.IsTrue(queriedState1); Assert.IsTrue(queriedState2); }
public void RetryUntilTimeout_is_exposed_on_the_session() { var calledOnWrapper = false; browserSession.RetryUntilTimeout(() => { calledOnWrapper = true; }); SpyTimingStrategy.QueriesRan <object>().First().Run(); Assert.That(calledOnWrapper, Is.True); }
public void Query_is_exposed_on_the_session() { Func <string> query = () => "query result"; SpyTimingStrategy.StubQueryResult("expected query result", "immediate query result"); Assert.That(browserSession.Query(query, "expected query result"), Is.EqualTo("immediate query result")); var robustQuery = SpyTimingStrategy.QueriesRan <string>().First(); var queryResult = robustQuery.Run(); Assert.That(queryResult, Is.EqualTo("query result")); }
public void Return_from_RetryUntilTimeout_is_exposed_on_the_session() { Func <string> function = () => "The expected result"; SpyTimingStrategy.StubQueryResult(SpyTimingStrategy.NO_EXPECTED_RESULT, "immediate result"); Assert.That(browserSession.RetryUntilTimeout(function), Is.EqualTo("immediate result")); var query = SpyTimingStrategy.QueriesRan <string>().First(); var queryResult = query.Run(); Assert.That(queryResult, Is.EqualTo("The expected result")); }
public void It_checks_for_missing_elements_with_synchronise() { browserSession = TestSessionBuilder.Build(new SessionConfiguration(), driver, SpyTimingStrategy, null, null, null, new ThrowsWhenMissingButNoDisambiguationStrategy()); SpyTimingStrategy.StubQueryResult(true, false); driver.StubId("Signout", new StubElement(), browserSession, sessionConfiguration); browserSession.FindId("Signin").Missing(); browserSession.FindId("Signout").Missing(); var firstQuery = SpyTimingStrategy.QueriesRan <bool>().ElementAt(0); var secondQuery = SpyTimingStrategy.QueriesRan <bool>().ElementAt(1); var firstQueryResult = RunQueryAndCheckTiming(firstQuery); Assert.That(firstQueryResult, Is.True); var secondQueryResult = RunQueryAndCheckTiming(secondQuery); Assert.That(secondQueryResult, Is.False); }
public void It_checks_all_of_the_states_in_a_robust_query_expecting_true() { bool queriedState1 = false; bool queriedState2 = false; var state1 = new State(new LambdaQuery <bool>(() => { queriedState1 = true; return(false); })); var state2 = new State(new LambdaQuery <bool>(() => { queriedState2 = true; return(true); })); var state3 = new State(new LambdaQuery <bool>(() => true)); state3.CheckCondition(); var robustWrapper = new SpyTimingStrategy(); robustWrapper.StubQueryResult(true, true); var session = BuildSession(robustWrapper); Assert.That(session.FindState(new [] { state1, state2, state3 }), Is.SameAs(state3)); Assert.IsFalse(queriedState1); Assert.IsFalse(queriedState2); var query = robustWrapper.QueriesRan <bool>().Single(); var queryResult = query.Run(); Assert.IsTrue(queryResult); Assert.IsTrue(queriedState1); Assert.IsTrue(queriedState2); }
public void It_waits_between_find_and_click_as_configured(int waitMs) { var stubButtonToBeClicked = StubButtonToBeClicked("Some button locator"); var expectedWait = TimeSpan.FromMilliseconds(waitMs); sessionConfiguration.WaitBeforeClick = expectedWait; var waiterCalled = false; fakeWaiter.DoOnWait(milliseconds => { Assert.That(milliseconds, Is.EqualTo(expectedWait)); AssertButtonFound(); AssertButtonNotClickedYet(stubButtonToBeClicked); waiterCalled = true; }); browserSession.ClickButton("Some button locator"); SpyTimingStrategy.QueriesRan <object>().Last().Run(); Assert.That(waiterCalled, "The waiter was not called"); AssertClicked(stubButtonToBeClicked); }
protected T RunQueryAndCheckTiming <T>(TimeSpan timeout) { var query = SpyTimingStrategy.QueriesRan <T>().Single(); return(RunQueryAndCheckTiming(query, timeout)); }
private void ExecuteLastDeferedRobustAction() { SpyTimingStrategy.QueriesRan <object>().Last().Run(); }