【发布时间】:2017-11-10 08:23:47
【问题描述】:
我有以下自定义 RetryAttribute 取自这篇文章:NUnit retry dynamic attribute。它工作正常,但是当我在 Selenium 中遇到超时错误时,它不起作用。
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
wait.Until(ExpectedConditions.ElementToBeClickable(element));
重试自定义属性:
/// <summary>
/// RetryDynamicAttribute may be applied to test case in order
/// to run it multiple times based on app setting.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class RetryDynamicAttribute : RetryAttribute {
private const int DEFAULT_TRIES = 1;
static Lazy<int> numberOfRetries = new Lazy<int>(() => {
int count = 0;
return int.TryParse(ConfigurationManager.AppSettings["retryTest"], out count) ? count : DEFAULT_TRIES;
});
public RetryDynamicAttribute() :
base(numberOfRetries.Value) {
}
}
然后应用自定义属性。
[Test]
[RetryDynamic]
public void Test() {
//....
}
如何解决?
【问题讨论】:
标签: c# unit-testing selenium nunit