Skip to content

Commit

Permalink
Better error response on main window timeout
Browse files Browse the repository at this point in the history
Return a clear error response when loading the main window fails within
the page load timeout. Fixes #89.
  • Loading branch information
aristotelos committed Sep 27, 2024
1 parent 21df7ea commit b3814e1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/FlaUI.WebDriver/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ public Session(Application? app, bool isAppOwnedBySession)
if (app != null)
{
// We have to capture the initial window handle to be able to keep it stable
CurrentWindowWithHandle = GetOrAddKnownWindow(app.GetMainWindow(Automation, PageLoadTimeout));
var mainWindow = app.GetMainWindow(Automation, PageLoadTimeout);
if (mainWindow == null)
{
throw WebDriverResponseException.Timeout($"Could not get the main window of the app within the page load timeout (${PageLoadTimeout.TotalMilliseconds}ms)");
}
CurrentWindowWithHandle = GetOrAddKnownWindow(mainWindow);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/FlaUI.WebDriver/WebDriverResponseException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ private WebDriverResponseException(string message, string errorCode, int statusC
public static WebDriverResponseException WindowNotFoundByHandle(string windowHandle) => new WebDriverResponseException($"No window found with handle '{windowHandle}'", "no such window", 404);

public static WebDriverResponseException NoWindowsOpenForSession() => new WebDriverResponseException($"No windows are open for the current session", "no such window", 404);

public static WebDriverResponseException Timeout(string message) => new WebDriverResponseException($"Timeout: ${message}", "timeout", 500);
}
}

0 comments on commit b3814e1

Please sign in to comment.