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

Configure screenshot name pattern in behat.yml #37

Closed
xurizaemon opened this issue Dec 15, 2020 · 6 comments · Fixed by #94
Closed

Configure screenshot name pattern in behat.yml #37

xurizaemon opened this issue Dec 15, 2020 · 6 comments · Fixed by #94

Comments

@xurizaemon
Copy link
Contributor

xurizaemon commented Dec 15, 2020

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.

  extensions:
    IntegratedExperts\BehatScreenshotExtension:
      dir: %paths.base%/screenshots
      fail: true
      purge: false
      # eg ...
      filenamePattern: @time-@prefix@featureFile@stepLine.@ext
@AlexSkrypnyk
Copy link
Member

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

@AlexSkrypnyk
Copy link
Member

AlexSkrypnyk commented Oct 16, 2023

Here is a suggested spec for providing configurable file names for screenshots.

Token format

{name[_qualifier[:format]}, where

  • { and } denote the start and end of a token
  • name is the name of the token
  • qualifier 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.

Supported tokens

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

Config changes

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}

Success vs failed patterns

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}      

@AlexSkrypnyk
Copy link
Member

@tannguyen04
When working on this, please note that this implementation should work well with #28.

@xurizaemon
Copy link
Contributor Author

xurizaemon commented Jan 22, 2024

And don't miss the existing WIP in #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 😁

@xurizaemon
Copy link
Contributor Author

@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?

@AlexSkrypnyk
Copy link
Member

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

AlexSkrypnyk pushed a commit that referenced this issue Mar 13, 2024
Co-authored-by: Chris Burgess <chrisburgess@catalyst.net.nz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants