您好我想从app.config值动态传递重试次数.
app.config包含以下行:
<add key="retryTest" value="3"/>
Run Code Online (Sandbox Code Playgroud)
我已经定义了这个变量:
public static readonly int numberOfRetries = int.Parse(ConfigurationManager.AppSettings["retryTest"]);
Run Code Online (Sandbox Code Playgroud)
最后,我想将该变量作为参数传递给Retry NUnit属性:
[Test, Retry(numberOfRetries)]
public void Test()
{
//....
}
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
"属性参数必须是属性参数类型的常量表达式,typeof表达式或数组创建表达式"
如何动态传递该值?
我RetryAttribute从这篇文章中获取了以下自定义:NUnit重试动态属性.它工作正常但是当我在Selenium中出现超时错误时它无效.
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
wait.Until(ExpectedConditions.ElementToBeClickable(element));
Run Code Online (Sandbox Code Playgroud)
重试自定义属性:
/// <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() : …Run Code Online (Sandbox Code Playgroud)