Skip to content

Commit e4cb900

Browse files
unknownunknown
authored andcommitted
Added WaitForFile to the Waiter object
1 parent f91c3ac commit e4cb900

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

Selenium/ComInterfaces/_Waiter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public interface _Waiter {
2121
[DispId(830), Description("Waits for the given function to return true. Ex: Waiter.Until addressOf MyFunction")]
2222
object Until(object function, object argument = null, int timeout = -1, string timeoutMessage = null);
2323

24+
[DispId(876), Description("Waits for a file to be ready.")]
25+
void WaitForFile(string path, int timeout = -1);
2426
}
2527

2628
}

Selenium/Waiter.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Selenium.Internal;
33
using System;
44
using System.ComponentModel;
5+
using System.IO;
56
using System.Runtime.InteropServices;
67

78
namespace Selenium {
@@ -265,6 +266,25 @@ private static bool IsNotNullOrFalse<T>(T value) {
265266
return !(value == null || value is bool && (bool)(object)value == false);
266267
}
267268

269+
270+
271+
/// <summary>
272+
/// Waits for a file to be ready.
273+
/// </summary>
274+
/// <param name="path">File path</param>
275+
/// <param name="timeout">Timeout in milliseonds</param>
276+
public void WaitForFile(string path, int timeout = -1) {
277+
Waiter.WaitUntil(() => {
278+
if (File.Exists(path)) {
279+
try {
280+
File.Move(path, path);
281+
return true;
282+
} catch (System.IO.IOException) { }
283+
}
284+
return false;
285+
}, timeout, 100);
286+
}
287+
268288
}
269289

270290
}

0 commit comments

Comments
 (0)