通过json-config传递自定义屏幕截图消费者



嗨,

基于这个项目,我将Atata框架与ExtentReports一起使用:https://github.com/atata-framework/atata-samples/tree/master/ExtentReports

现在我想从fluent上下文构建切换到json-config。我流畅的上下文构建看起来像:

AtataContext.GlobalConfiguration
.UseChrome()
.WithArguments("--start-maximized")
.WithLocalDriverPath()
.WithFixOfCommandExecutionDelay()
.UseCulture("en-US")
.UseAllNUnitFeatures()
.AddDebugLogging()
.AddScreenshotFileSaving()
.WithArtifactsFolderPath()
.AddLogConsumer(new ExtentLogConsumer())
.WithMinLevel(LogLevel.Info)
.EventSubscriptions.Add(new ExtentScreenshotFileEventHandler());

AtataContext.GlobalConfiguration.AutoSetUpDriverToUse();

我几乎可以通过json-config实现所有内容,除了这一行:

.EventSubscriptions.Add(new ExtentScreenshotFileEventHandler());

我的配置:

{
"driver": {
"type": "chrome",
"alias": "chrome",
"options": {
"arguments": [ "start-maximized" ],
"userProfilePreferences": {
"download.default_directory": "{artifacts}"
}
}
},
"culture": "en-US",
"useAllNUnitFeatures": true,
"logConsumers": [
{
"type": "nlog-file",
"folderPath": "{artifacts}",
"minLevel": "Debug"
},
{
"type": "AtataUITests1.Core.Reporting.ExtentLogConsumer, AtataUITests1",
"minLevel": "Info"
}
],
"screenshotConsumers": [
{
"type": "file",
"folderPath": "{artifacts}"
}
]
}

当我尝试将新的screenshotConsumer添加到json:时

"screenshotConsumers": [
{
"type": "file",
"folderPath": "{artifacts}"
},
{
"type": "AtataUITests1.Core.Reporting.ExtentScreenshotFileEventHandler, AtataUITests1"
}
]

它显示错误:

System.InvalidCastException : Unable to cast object of type 'AtataUITests1.Core.Reporting.ExtentScreenshotFileEventHandler' to type 'Atata.IScreenshotConsumer'.

我的问题是:有可能通过json传递这个自定义屏幕截图消费者吗?

感谢

ExtentScreenshotFileEventHandler不是屏幕截图使用者,而是事件处理程序。所以它应该放在";eventSubscriptions";部分如下:

"eventSubscriptions": [
{
"handlerType": "AtataUITests1.Core.Reporting.ExtentScreenshotFileEventHandler, AtataUITests1"
}
]

还有一个关于Atata.Configuration.Json/JONSchema部分的示例。

最新更新