Atata 2.4.0 is Released

November 16, 2022 by Yevgeniy Shunevych


Atata 2.4.0 is released with new page snapshot functionality.

Changelog

New Features

  • minor #695 Add FillPathTemplateString methods to AtataContext
  • major #697 Add AddArtifact methods to AtataContext
  • major #698 Add page snapshot functionality

Changes and Enhancements

  • minor #696 Overcome GetDevToolsSession slowness issue for Chrome and Edge on Windows
  • major #699 Use Selenium.WebDriver package v4.6.0
  • minor #700 Add TakeScreenshot method to AtataContext and mark ILogManager.Screenshot method as obsolete
  • minor #702 Update screenshots functionality to work with AtataContext without navigation
  • minor #703 Add TakeScreenshotAttribute and mark ScreenshotAttribute as obsolete

Page Snapshots

A new functionality for taking a page snapshot. A snapshot can be either HTML or MHTML file. Now when a test fails in addition to screenshot you get a page snapshot, which you can inspect.

For Chromium-based browsers (Chrome and Edge) a snapshot by default is taken using CDP command Page.captureSnapshot and saved as .MHTML file with styles and images.

Note that Page.captureSnapshot command is in experimental state so the result page snapshot may not 100% be equal to an original page.

For other browsers a snapshot is taken using IWebDriver.PageSource property and saved as .HTML file without styles.

Methods

A method added to Report<TOwner>:

public TOwner PageSnapshot(string title = null);

Usage:

Go.To<SomePage>()
    .Report.PageSnapshot();

A method added to AtataContext:

public void TakePageSnapshot(string title = null);

Usage:

AtataContext.Current.TakePageSnapshot();

Configuration

A property is added to AtataContextBuilder:

public PageSnapshotsAtataContextBuilder PageSnapshots { get; }

PageSnapshotsAtataContextBuilder contains the following methods:

// Used by default.
public PageSnapshotsAtataContextBuilder UseCdpOrPageSourceStrategy();

public PageSnapshotsAtataContextBuilder UsePageSourceStrategy();

public PageSnapshotsAtataContextBuilder UseCdpStrategy();

public PageSnapshotsAtataContextBuilder UseStrategy(IPageSnapshotStrategy strategy);

// The default value is "{snapshot-number:D2}{snapshot-pageobjectname: - *}{snapshot-pageobjecttypename: *}{snapshot-title: - *}".
public PageSnapshotsAtataContextBuilder UseFileNameTemplate(string fileNameTemplate);

Usage

AtataContext.Configure()
    .PageSnapshots.UseCdpStrategy()
    .PageSnapshots.UseFileNameTemplate("{snapshot-number:D2}...");

NUnit

An extra configuration method for NUnit is added to AtataContextBuilder:

public AtataContextBuilder TakePageSnapshotOnNUnitError(string title = "Failed");

Also UseAllNUnitFeatures() configuration method now includes invoking of TakePageSnapshotOnNUnitError().

Trigger Attribute

Additionally TakePageSnapshotAttribute trigger is added.

AddArtifact Methods

New methods are added to AtataContext that add a file to the Artifacts directory:

public void AddArtifact(string relativeFilePath, string fileContent, string artifactType = null, string artifactTitle = null);

public void AddArtifact(string relativeFilePath, string fileContent, Encoding encoding, string artifactType = null, string artifactTitle = null);

public void AddArtifact(string relativeFilePath, byte[] fileBytes, string artifactType = null, string artifactTitle = null);

public void AddArtifact(string relativeFilePath, Stream stream, string artifactType = null, string artifactTitle = null);

public void AddArtifact(string relativeFilePathWithoutExtension, FileContentWithExtension fileContentWithExtension, string artifactType = null, string artifactTitle = null);

A new ArtifactAddedEvent is published via EventBus after a file is saved. You can subscribe to the event, for example, to add files to reporting system.

This functionality is used by page snapshots and also can be used for custom file saving.