Closed xurizaemon closed 8 months ago
@xurizaemon I liked your suggestion and was thinking about supporting this. But I do not have the bandwidth to support this. A PR is always welcomed!
Please note that there is a purge
option available to purge all screenshots after every run.
The timestamp prefix was added to order screenshots by creation time.
Here is a suggested spec for providing configurable file names for screenshots.
{name[_qualifier[:format]}
, where
{
and }
denote the start and end of a tokenname
is the name of the tokenqualifier
is an optional qualifier for the token. Must be separated from the name by an underscore.format
is an optional format for the token. Must be separated from the qualifier by a colon.The reasoning behind using {}
as delimiters instead of @
is to make it easier to identify the token end delimiter in
the string.
Using http://example.com/mypath/subpath?myquery=1+2+3&another[]=4#somefragment
in URL examples.
Token | Substituted with | Example value(s) |
---|---|---|
{ext} |
The extension of the file captured | html or png |
{fail_prefix} |
The value of fail_prefix from configuration | failed_ , error_ (do include the _ suffix, if required) |
{url} |
Full URL | http_example_com_mypath_subpath__query__myquery_1_plus_2_plus_3_and_another1_4__fragment__somefragment |
{url_origin} |
Scheme with domain | http_example_com |
{url_relative} |
Path + query + fragment | mypath_subpath__query__myquery_1_plus_2_plus_3_and_another1_4__fragment__somefragment |
{url_domain} |
Domain | example_com |
{url_path} |
Path | mypath_subpath |
{url_query} |
Query | myquery_1_plus_2_plus_3_and_another1_4 |
{url_fragment} |
Fragment | somefragment |
{feature_file} |
The filename of the .feature file currently being executed, without extension |
my_example.feature -> my_example |
{step_line} |
Step line number | 1 , 10 , 100 |
{step_line:%03d} |
Step line number with leading zeros. Modifiers are from sprintf() . |
001 , 010 , 100 |
{step_name} |
Step name without Given/When/Then and lower-cased. |
i_am_on_the_test_page |
{datetime} |
Current date and time. defaults to Ymd_His format. |
20010310_171618 |
{datetime:u} |
Current date and time as microtime. Modifiers are from date() . |
1697490961192498 |
Based on the above, the current format can be expressed as:
{datetime:u}.{fail_prefix}{feature_file}.feature_{step_line}.{ext}
resulting in filenames like:
1697490961192498.login.feature_14.png
- success
1697490961192498.failed_login.feature_14.png
- failed
extensions:
DrevOps\BehatScreenshotExtension:
dir: %paths.base%/screenshots
fail: true
purge: false
# New config option.
filenamePattern: {datetime:u}.{fail_prefix}{feature_file}.feature_{step_line}.{ext}
Although adding an ability to provide different file name patterns for successful and failed screenshots is not a part of this issue, it is worth specifying how it would look like in config:
extensions:
DrevOps\BehatScreenshotExtension:
dir: %paths.base%/screenshots
fail: true
purge: false
# New config option.
filenamePattern: {datetime:u}.{feature_file}.feature_{step_line}.{ext}
filenamePatternFailed: {datetime:u}.{fail_prefix}{feature_file}.feature_{step_line}.{ext}
@tannguyen04 When working on this, please note that this implementation should work well with https://github.com/drevops/behat-screenshot/issues/28.
And don't miss the existing WIP in https://github.com/drevops/behat-screenshot/pull/53 :)
You're welcome to squash commits on that branch to base your work on. When doing so please retain commit credit for existing progress ๐
It's fine to start over too! Thanks for picking this up ๐
@tannguyen04 came across the config for this in a repo today and wondered how it had progressed. Did you get anywhere? Can I help in any way?
@xurizaemon I work with @tannguyen04 on this and the priority for this issue has changed a bit. We will be addressing this in a week or two.
Different to #28 (which I read to mean, specifying the output filename in the stepdefinition, eg
Then I save screenshot to my-screenshot.png
).It would be nice to have control over the screenshot filename generation when the filename is not specified.
My use case would be the ability to remove the time-based uniqueness, since then the screenshot filename is based on the feature / step (or failing step), and you can hit reload in the browser to see updated HTML / PNG after a test run. Currently this workflow requires re-opening the newly generated file ๐
Just a wishlist item - looking at
makeFileName()
we'd need to introduce some interpolation of values like@featureFile
,@stepLine
to a template string I expect.