The list of screenshot taking methods of AtataContextBuilder:

public AtataContextBuilder<TScreenshotConsumer>

AddScreenshotConsumer<TScreenshotConsumer>(TScreenshotConsumer consumer)

where TScreenshotConsumer : IScreenshotConsumer

Adds the screenshot consumer. Is used for custom screenshot processing.

public AtataContextBuilder<IScreenshotConsumer>

AddScreenshotConsumer(string typeNameOrAlias)

Adds the screenshot consumer. typeNameOrAlias can accept full type name, custom IScreenshotConsumer alias (registered via ScreenshotConsumerAliases.Register method) or predefined “file” alias.

public AtataContextBuilder<FileScreenshotConsumer>

AddScreenshotFileSaving()

Adds the FileScreenshotConsumer instance for the screenshot saving to file.

File Screenshots Configuration

By default AddScreenshotFileSaving method configures FileScreenshotConsumer with the following settings:

  • Folder path: $@"Logs\{AtataContext.BuildStart:yyyy-MM-dd HH_mm_ss}\{AtataContext.Current.TestName}"
  • File name format: $"{screenshotInfo.Number:D2} - {screenshotInfo.PageObjectFullName}{screenshotInfo.Title?.Prepend(" - ")}"
  • Image format: Png.

The list of extension methods to configure FileScreenshotConsumer:

public AtataContextBuilder<FileScreenshotConsumer>

With(ScreenshotImageFormat imageFormat)

Specifies the image format of the file screenshot consumer.

public AtataContextBuilder<FileScreenshotConsumer>

WithFolderPath(Func<string> folderPathBuilder)

Specifies the folder path builder of the file screenshot consumer.

public AtataContextBuilder<FileScreenshotConsumer>

WithFileName(Func<ScreenshotInfo, string> fileNameBuilder)

Specifies the file name builder of the file screenshot consumer.

public AtataContextBuilder<FileScreenshotConsumer>

WithFilePath(Func<ScreenshotInfo, string> filePathBuilder)

Specifies the file path builder of the file screenshot consumer.

Usage

The below example configures FileScreenshotConsumer to use separate folder for each test:

AtataContext.Configure().
    // Do some initialization.
    AddScreenshotFileSaving().
        WithFolderPath(() => $@"Logs\{AtataContext.BuildStart:yyyy-MM-dd HH_mm_ss}\{AtataContext.Current.TestName}").
        WithFileName(screenshotInfo => $"{screenshotInfo.Number:D2} - {screenshotInfo.PageObjectFullName}{screenshotInfo.Title?.Prepend(" - ")}").
    Build();

If you need to take a screenshot only on test failure, you may configure FileScreenshotConsumer to save all screenshot files to the same folder:

AtataContext.Configure().
    // Do some initialization.
    TakeScreenshotOnNUnitError().
    AddScreenshotFileSaving().
        WithFolderPath(() => $@"Logs\{AtataContext.BuildStart:yyyy-MM-dd HH_mm_ss}").
        WithFileName(screenshotInfo => $"{AtataContext.Current.TestName} - {screenshotInfo.PageObjectFullName}").
    Build();