Skip to content

Make the default file name for 'Capture Page Screenshot' more unique #268

Closed

Description

@sdarshanam

capture_page_screenshot keyword saves screenshot by suffixing index.

Can this be changed to use the current date time instead of index to make it more unique.

    if not filename:
        self._screenshot_index += 1
        filename = 'selenium-screenshot-%d.png' % self._screenshot_index

Activity

  1. ombre42 commented on Jan 24, 2014

    @ombre42
    Contributor

    Capture Page Screenshot takes a filename argument so you can have any naming scheme you want. To control the filename when there is a failure you can do something similar to the following:

    Register Keyword To Run On Failure    Save Selenium Screenshot
    
    *** Keywords ***
    Save Selenium Screenshot
        ${screenshot_index}=    Get Variable Value    ${screenshot_index}    ${0}
        Set Global Variable    ${screenshot_index}    ${screenshot_index.__add__(1)}
        ${time}=    Evaluate    str(time.time())    time
        Capture Page Screenshot    selenium-screenshot-${time}-${screenshot_index}.png
    

    The reasoning behind still using an index is that time.time is not guaranteed to be more granular than a second (on Windows it is). Two screenshots within a second is possible and we do not want one to overwrite the other.

    If you are requesting that the default filename be more unique, than please say so.

  2. sdarshanam commented on Jan 25, 2014

    @sdarshanam
    Author

    Thanks Kevin. I will try this out. Nevertheless, can the default file name made more unique.

  3. ombre42 commented on Jan 27, 2014

    @ombre42
    Contributor

    @sdarshanam I think this would be a good idea. I believe a lot of people are re-inventing the wheel out there.
    Besides datetime, another option to consider would be using a UUID, like Selenium does for a session ID.
    The only concern would be breaking existing tests due to the path being too long.

  4. sdarshanam commented on Jan 29, 2014

    @sdarshanam
    Author

    Do we really need 'selenium-screenshot-' as part of the file name? we already know its a png (screenshot) and its from selenium, moreover its a default file name, so why not just have UUID as file name?

  5. mulmschneider commented on Jul 30, 2014

    @mulmschneider

    I've created a pull request for more unique screenshot names, but a quick workaround is to just redefine the 'Run on Failure' keyword:

    *** Settings ***
    Library           Selenium2Library
    Library           uuid
    
    *** Keywords ***
    Init
        Register Keyword To Run On Failure  Capture Page Screenshot With Unique Name
    
    Capture Page Screenshot With Unique Name
        ${uuid} =  uuid4
        Capture Page Screenshot  selenium-${uuid}.png
    
  6. aaltat commented on May 23, 2016

    @aaltat
    Contributor

    The current code in master, which is not yet released allows more configuration on the file name. Therefore closing the issue.

    If you feel that this issue should not have been closed, send an update and we will re-open the issue.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions