feat(cypress): command log steps rework #1205
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Allure Cypress automatically converts commands into Allure steps. It does so by listening
command:start
andcommand:end
,The PR reworks this mechanism to be based on the command log instead. It aligns with our general attitude to represent things as they are reported by the framework itself: the command log is the main reporting mechanism that Cypress provides to users in interactive mode.
Note
The Cypress command log supports events, e.g., the
fetch
events, which allow tracking HTTP requests made with the fetch API. Events like this are not the subject of this PR. The implementation currently doesn't create steps from them. We may support such events in the future.Features
Child commands and assertions
Previously, Allure Cypress didn't include child commands, e.g., assertions. Now, it includes them as substeps of their parent command.
Example
The Comman log
Allure Report before
Allure Report after
Properties of command log entries
Previously, Allure Cypress used to create step parameters from the
attributes.args
list of a command object. Now it uses theattributes.consoleProps
function of a command log entry. This is the function Cypress uses to print the properties in the console when a user clicks on an entry in interactive mode.The main difference is that
consoleProps
provides key-value pairs instead of a list of values, which allows as to use the actual names instead of syntetic ones. Additionally, many Cypress commands include extra useful data in such props.Example
The Comman log and the console
Allure Report before
Allure Report after
Custom command log entries
Cypress allow users to add extra entries to the command log with
Cypress.log
. Allure Cypress now correctly converts them into steps. Child entries (type: "child"
) are included as substeps of the nearest running parent step (if any).Example
The Comman log
Allure Report
Hidden commands and log entries
Some commands take the
{ log: true }
option. Cypress precludes such commands from the command log. Allure Cypress doesn't convert them to steps as well.Example
The Comman log
Allure Report
Command log groups
Command log entries can be grouped by providing the
{ groupStart: true }
option toCypress.log
. Allure Cypress converts such entries to steps. Every step created untillog.endGroup
is called becomes a substep. This applies to steps from the command log as well as to steps created withallure.step
.Example
The Comman log
Allure Report
Note
Since @badeball/cypress-cucumber-preprocessor uses the
Cypress.log
API to group command log entries of a cucumber step, such grouping is automatically preserved by Allure Cypress. This wasn't the case earlier (see #1059).Screenshots
Allure Cypress now uses the attachment step feature to report screenshots created with
cy.screenshot
or created by Cypress automatically when a test fails.Example
Allure Report before
Allure Report after
Other changes
serialize
(inallure-js-commons/sdk/utils
) now supports a newreplacer
option. A value must be a function with the following signature(this: unknown, key: string, value: unknown) => unknown
. If provided, it's used byserialize
to pre-process object property values.Cypress.on("fail", ...)
, which are created by a user or a 3rd party plugin. The exception is throws only if there are no subsequent listeners. Otherwise, it passes the responsibility of throwing to the next listener.Checklist
Closes #1059.