通过 json 配置传递自定义屏幕截图消费者

Pass custom screenshot consumer though json config

嗨,

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

现在我想从流畅的上下文构建切换到 json 配置。我的流利上下文构建看起来像:

    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 配置实现,除了这一行:

.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 / JSON Schema 部分也有示例。