In some of my projects to correctly save forms user needs to perform click on "Save" or "Save changes" button. That click cause whole page to reload (changes done will be visible on page after that reload), but if something is wrong validation will stops page from reloading. I want to create a simple assertion to check if that page was reloaded, if not my test will fail. I tried to use this code:
public bool WasPageRefreshed(float seconds)
{
DriverLocal.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.MinValue);
string getReadyState = "return document.readyState;";
for (int i = 0; i < 10; i++)
{
string readyState = GetJsExecutor().ExecuteScript(getReadyState) as string;
if (readyState != "complete")
return true;
Thread.Sleep(TimeSpan.FromMilliseconds(seconds / 10));
}
DriverLocal.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(60));
return false;
}
I use it in Assert.True() to check if page was reloaded but it doesn't work always (I can use it 5 times on same form - 3 times its ok, 2 times test will fail). Is there a way to upgrade it to work correctly in 100% of usage? Or maybe there is another way to check if page was reloaded?