我有以下自定義RetryAttribute
採取從這篇文章:NUnit retry dynamic attribute。它工作正常,但是當我在Selenium中遇到超時錯誤時,它不起作用。C# - 硒 - 重試屬性不工作與硒超時
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() {
//....
}
這怎麼解決?