How to wait for Mouse.Cursor state by default
Posted: Wed May 25, 2016 12:37 pm
Hi,
The application i'm automating doesn't accept input when saving or searching. While it's busy, the mouse.cursor state is "[Cursor: WaitCursor]" visible as a spinning blue circle in Windows 7, so when manually using the application it's easy to wait for this busy-state to disappear before doing something else.
I've built a rudimentary while-loop in c# to wait for the cursor to change to a state other than WaitCursor, but I'll have to make a coded step every time I want to do this.
I'd prefer it if it were possible to do this by default: as long as mouse.cursor = WaitCursor, wait, without having to do this every time I save or search something. Is there common functionality for this, i.e. a setting somewhere?
EDIT
Code I've written:
The application i'm automating doesn't accept input when saving or searching. While it's busy, the mouse.cursor state is "[Cursor: WaitCursor]" visible as a spinning blue circle in Windows 7, so when manually using the application it's easy to wait for this busy-state to disappear before doing something else.
I've built a rudimentary while-loop in c# to wait for the cursor to change to a state other than WaitCursor, but I'll have to make a coded step every time I want to do this.
I'd prefer it if it were possible to do this by default: as long as mouse.cursor = WaitCursor, wait, without having to do this every time I save or search something. Is there common functionality for this, i.e. a setting somewhere?
EDIT
Code I've written:
Code: Select all
public static void WaitForSaved(int maxLoopDuration)
{
string currentState = Mouse.Cursor.ToString();
System.Diagnostics.Stopwatch newWatch = System.Diagnostics.Stopwatch.StartNew();
while (currentState == "[Cursor: WaitCursor]" && newWatch.Elapsed.Seconds <= maxLoopDuration)
{
Thread.Sleep(500);
currentState = Mouse.Cursor.ToString();
}
//if you want the test to fail after maxLoopDuration:
if(newWatch.Elapsed.Seconds > maxLoopDuration)
{
Ranorex.Report.Error("Application still reports busy state after exceeding the allotted time (maxLoopDuration)");
}
}