Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add page snapshot functionality #698

Closed
YevgeniyShunevych opened this issue Nov 11, 2022 · 8 comments
Closed

Add page snapshot functionality #698

YevgeniyShunevych opened this issue Nov 11, 2022 · 8 comments
Assignees
Labels
Milestone

Comments

@YevgeniyShunevych
Copy link
Member

YevgeniyShunevych commented Nov 11, 2022

A new functionality for taking a page snapshot, which can be either HTML or MHTML file. For Chromium-based browsers (Chrome and Edge) a snapshot by default is taken using CDP command Page.captureSnapshot. For other browsers a snapshot is taken using IWebDriver.PageSource property.

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 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.

@Piedone
Copy link

Piedone commented Nov 15, 2022

Can you use this if you don't have a page object? I.e. when visiting a page without using Atata, just navigating to it. We'd take a snapshot of the current page.

@YevgeniyShunevych
Copy link
Member Author

You mean you have built AtataContext with initialized Driver, don't do any Go.To navigations, but navigated thru Driver directly?

@Piedone
Copy link

Piedone commented Nov 15, 2022

Yes, exactly.

@YevgeniyShunevych
Copy link
Member Author

Such scenario was not considered. But I made another commit to make it work. Now it's fine.

@Piedone
Copy link

Piedone commented Nov 16, 2022

Awesome, thank you.! This looks good. We'll check it out once you release it.

@YevgeniyShunevych
Copy link
Member Author

Atata v2.4.0 is released already.

@Piedone
Copy link

Piedone commented Nov 17, 2022

Yep, seen it, thanks. We'll check this out as soon as we can.

@Piedone
Copy link

Piedone commented Nov 25, 2022

We've added the usage of this feature to the Lombiq UI Testing Toolbox for Orchard Core in this PR. In hindsight, it's straightforward, but the first time it was quick complex to understand where the snapshot can actually be retrieved from.

Thank you again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants