For the complete documentation index, see llms.txt. This page is also available as Markdown.

Attachments

Attach screenshots, traces, videos and any other file to a spec, and find them in every report.

A failing browser test is much easier to fix when you can see the page. TestBox lets any spec attach files to its result: screenshots, Playwright traces, videos, logs, HAR files or anything else. Reporters list the attachments under the spec, and the JUnit reports expose them to Jenkins and GitLab.

Browser specs attach the screenshots, trace and videos of a failed browse() call for you, and you can call attach() from any spec, on any engine.

attach()

attach( required string path, string type = "file", string name = "" )
Argument
Default
Description

path

The absolute path of the file.

type

file

The kind of file, for example file, screenshot, trace, video or log. Reporters show it next to the name.

name

the file name

The display name. Defaults to the file name of path.

attach() returns the spec, so calls chain. Attachments are kept for passed and failed specs alike.

tests/specs/ReportSpec.bx
class extends="testbox.system.BaseSpec" {

    function run() {
        describe( "Monthly report", () => {

            afterEach( () => {
                // Keep the application log of every spec
                attach( expandPath( "/logs/app.log" ), "log" )
            } )

            it( "renders the PDF", () => {
                var pdf = getTempDirectory() & "report.pdf"
                new models.Reports().monthly( pdf )

                attach( path = pdf, type = "file", name = "Monthly report" )
                expect( fileExists( pdf ) ).toBeTrue()
            } )

        } )
    }

}

In xUnit bundles, call attach() from the test method, setup() or teardown().

TestBox records the path you give it; it does not copy the file. Keep attached files where your CI job can collect them, and do not delete them in afterAll() if you want to look at them later.

Automatic Browser Artifacts

A failed browser spec with its screenshot in the HTML report and its Playwright trace
The screenshot, trace and video of a failed browser spec

Automatic browser artifacts require BoxLang and bx-playwright, like every browser spec feature. Browser specs are BoxLang classes, and on BoxLang without bx-playwright they skip before any artifact is recorded.

bx-playwright records screenshots, traces and videos according to its artifact policies. They are all off by default. Turn them on with a profile, for example the built-in ci profile, or with the artifacts setting or browse() option:

Policy
Keeps

off

nothing

on

always

only-on-failure / retain-on-failure

only when the browser context closes as failed

The ci profile keeps a screenshot (only-on-failure), a trace and videos (retain-on-failure) of every failed context:

Or per browse() call:

When the browse() closure throws, whether from a matcher, a bx-playwright assertion or any other error, TestBox closes each browser context as failed, attaches what the policies kept to the running spec, then rethrows the original exception:

Kept file
Attachment type

Screenshot of each page

screenshot

Playwright trace (a .zip)

trace

Video of each page

video

This is the screenshot TestBox attached when the spec expected the last order to be Shipped but the page showed Processing:

Failure screenshot of the dashboard with the last order still Processing
The failure screenshot: the last order is still Processing

Files go to ~/.boxlang/playwright/artifacts unless you set artifacts.directory. When the closure passes, nothing is kept or attached for the on-failure policies. More on policies in the bx-playwright testing guide.

Opening a Trace

A trace records every action, a DOM snapshot before and after it, the console and the network. Open one in the Playwright trace viewer:

Select an action to see the page at that moment, the call parameters and the error. Here the hasText assertion waited 5 seconds for Shipped and the trace shows the Processing pill it found instead:

The Playwright trace viewer showing the failed hasText assertion
The failed assertion in the Playwright trace viewer

Attachments in Reports

Reporter or output
Shows

JSON (json) and Raw

An attachments array of { path, type, name } in every spec's stats, passed or failed.

Simple (simple), Min (min), Dot (dot) and Doc (doc)

Screenshots as thumbnails that open full size, and a list of the other files, each name linking to its file. A trace has a Copy show-trace command button.

JUnit (junit) and ANT JUnit (antjunit)

A <system-out> element on the test case with one [[ATTACHMENT|path]] line per file.

Text (text), Console (console) and the BoxLang runner --stream output

The attachments of failed and errored specs, listed under the failure with their name, type and path.

Screenshots in the HTML Reports

The HTML reporters embed image attachments (png, jpg, gif and webp) in the page, so the screenshot of a failure shows right on the failed spec. Click a thumbnail to see it full size, then click anywhere or press Escape to close it.

A failed browser spec in the Simple report with its screenshot as a thumbnail, and its trace and video listed below
The failure screenshot on the failed spec
The failure screenshot open full size over the report
A click opens it full size

Embedding means the screenshots work wherever the report goes: served by a web runner, saved as a file, or uploaded as a CI artifact. A failed spec's screenshots are embedded once, in its failure card, and the bundle list links to that card.

Images up to 2 MB are embedded. Larger ones stay links. Change the limit with the inlineImageMaxKB reporter option, or set it to 0 to link every image:

Videos, traces and other files are listed under the spec. A trace has a Copy show-trace command button that copies the bxplaywright show-trace command for its path.

The JUnit output follows the convention of the Jenkins JUnit Attachments plugin, which GitLab also reads for its test reports:

  • Jenkins: install the JUnit Attachments plugin and publish the JUnit report. Attachments appear on each test result page.

  • GitLab: publish the report as artifacts:reports:junit and keep the attached files in the job artifacts. GitLab shows screenshots on the failed test in the merge request test report. It resolves the paths inside the job artifacts, so write artifacts under the project directory, for example with artifacts.directory.

When you consume results programmatically, read the attachments from the spec stats:

See Reporters for how to choose a reporter.

Last updated

Was this helpful?