Last active
November 30, 2018 15:30
-
-
Save YevgeniyShunevych/5dda08446feecf60c40c7339f58b2aa4 to your computer and use it in GitHub Desktop.
Atata - refresh page and wait until condition is met
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Atata | |
{ | |
public static class PageObjectExtensions | |
{ | |
public static TOwner RefreshPageAndWaitUntil<TOwner>(this TOwner pageObject, Func<TOwner, bool> predicate, double timeout, double retryInterval) | |
where TOwner : PageObject<TOwner> | |
{ | |
TOwner activePageObject = pageObject; | |
bool isOk = AtataContext.Current.Driver. | |
Try(TimeSpan.FromSeconds(timeout), TimeSpan.FromSeconds(retryInterval)). | |
Until(x => | |
{ | |
activePageObject = activePageObject.RefreshPage(); | |
return predicate(activePageObject); | |
}); | |
if (!isOk) | |
throw new TimeoutException("Failed to wait for condition with page refresh."); | |
return activePageObject; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Atata; | |
using NUnit.Framework; | |
namespace SampleApp.UITests | |
{ | |
public class SampleTests : UITestFixture | |
{ | |
[Test] | |
public void RefreshPageAndWaitUntil() | |
{ | |
Go.To<SomePage>(). | |
CurrentTime.Get(out TimeSpan? time). | |
RefreshPageAndWaitUntil(x => x.CurrentTime.Value > time.Value.Add(TimeSpan.FromSeconds(15)), timeout: 20, retryInterval: 2); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment