Skip to content

Instantly share code, notes, and snippets.

@YevgeniyShunevych
Last active November 30, 2018 15:30
Show Gist options
  • Save YevgeniyShunevych/5dda08446feecf60c40c7339f58b2aa4 to your computer and use it in GitHub Desktop.
Save YevgeniyShunevych/5dda08446feecf60c40c7339f58b2aa4 to your computer and use it in GitHub Desktop.
Atata - refresh page and wait until condition is met
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;
}
}
}
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