在编码的ui中,有一种等待控件存在的方法UITestControl.WaitForControlExist(waitTime);.有没有办法等待控件不存在?我能想到的最好的方法是创建一个像这样的扩展方法:
public static bool WaitForControlClickable(this UITestControl control, int waitTime = 10000)
{
Point p;
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
while (stopwatch.ElapsedMilliseconds < waitTime)
{
if (control.TryGetClickablePoint(out p))
{
return true;
}
Thread.Sleep(500);
}
return control.TryGetClickablePoint(out p);
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法呢?此外,我正在寻找一种相反的方法.
因此,WaitForControlExists 实际上所做的是调用公共 WaitForControlPropertyEqual,如下所示:
return this.WaitForControlPropertyEqual(UITestControl.PropertyNames.Exists, true, timeout);
Run Code Online (Sandbox Code Playgroud)
您的助手可以调用:
public bool WaitForControlPropertyNotEqual(string propertyName,
object propertyValue, int millisecondsTimeout)
Run Code Online (Sandbox Code Playgroud)
此外,正如 Kek 指出的,还有一个 WaitForControlNotExist 公共方法。
请注意,它们似乎都使用相同的助手(也是公共的):
public static bool WaitForCondition<T>(T conditionContext, Predicate<T> conditionEvaluator, int millisecondsTimeout)
Run Code Online (Sandbox Code Playgroud)
这个助手本质上在当前线程上执行 Thread.Sleep 操作,与您的操作非常相似。
| 归档时间: |
|
| 查看次数: |
11276 次 |
| 最近记录: |