Package: selenium-screenshots
Table of ContentsShort Overview.ExampleInstallation via pip:Basic UsageArgumentsAdvanced Usageselenium_screenshots.Screenshots(…)ArgumentsMethods ofscreenshots_handlerobjectscreenshots_handler.create_screenshot(…)screenshots_handler.delete_all_screenshots(…)screenshots_handler.delete_not_unique_screenshots(…)How to create screenshot every time when you caught an ExceptionLinksProject local LinksContactsLicenseShort Overview.selenium_screenshots is a python package that helps to create many screenshots for selenium webdrivers.Examplefromseleniumimportwebdriverfromselenium_screenshotsimportmake_screenshot# Please define here any webdriver which you would like to use E.G. driver = webdriver.Chrome()# When you would want to create a screenshot, just callmake_screenshot(driver)make_screenshot(driver,"some_description")make_screenshot(driver,"characters_%%forbidden_in_the_..filename")As the result you will get screenshots in the directory:./screenshots/…1.png2_some_description.png3_characters___forbidden_in_the___filename.pngIf you run this code some other time then you’ll get 3 more screenshots:1.png2_some_description.png3_characters___forbidden_in_the___filename.png4.png5_some_description.png6_characters___forbidden_in_the___filename.pngAs you can see user shouldn’t worry about screenshot’s numbers as they will be handled automatically.Installation via pip:pipinstallselenium_screenshotsBasic UsageFull signature of selenium_screenshots.make_screenshot(…)fromselenium_screenshotsimportmake_screenshotmake_screenshot(webdriver,str_description="",str_path_dir_with_screenshots="screenshots",)Argumentswebdriver:The only mandatary argument. Any selenium webdriver which to use for making of screenshot.str_description=””:Description of the screenshot to add to the screenshot filename.If in the screenshot description will be used symbols forbidden in the filenames they will be replaced on “_”.If filename of a new screenshot is longer than 50 symbols then it will be cut to 50.str_path_dir_with_screenshots=”screenshots”:Path to the directory where you want to save a new screenshotAdvanced Usageselenium_screenshots.Screenshots(…)Firstly, you have to define an object of class Screenshots to be able to handle screenshots.This object will be namedscreenshots_handlerin the code below.fromseleniumimportwebdriverfromselenium_screenshots.mainimportScreenshots# Please define here any webdriver which you would like to use E.G. driver = webdriver.Chrome()screenshots_handler=Screenshots(webdriver,str_path_dir_with_screenshots="screenshots",int_screenshots_to_delete_half=9999,int_max_length_of_filename=50,)Argumentswebdriver:The only mandatary argument. Any selenium webdriver which to use for making of screenshots.str_path_dir_with_screenshots=”screenshots”:Path to directory where to save screenshots.int_screenshots_to_delete_half=9999:Number of the screenshots in the directory when try to delete most old halfint_max_length_of_filename=50:Max length of a new screenshot filename.If filename of a new screenshot is longer then filename will be cut.Methods ofscreenshots_handlerobjectscreenshots_handler.create_screenshot(…)This method do exactly the same asselenium_screenshots.make_screenshot(…)in theBasic Usagescreenshots_handler.create_screenshot(str_description="")str_description=””:Description of the screenshot to add to the screenshot filename.If in the screenshot description is used symbols forbidden in the filenames they will be replaced on “_”.If filename of a new screenshot is longer than N symbols then it will be cut to N.screenshots_handler.delete_all_screenshots(…)This method will delete all screenshots in the directory.Max used screenshot number won’t be lost, so new screenshot will have next number rather than 1.screenshots_handler.delete_all_screenshots()screenshots_handler.delete_not_unique_screenshots(…)This method will delete screenshots with not unique descriptions.screenshots_handler.delete_not_unique_screenshots(is_to_delete_screenshots_without_description=False)is_to_delete_screenshots_without_description=False:Flag if to delete screenshots without descriptionHow to create screenshot every time when you caught an ExceptionYou can use this python package to make screenshots for every exceptionwith preserved description of an error in the screenshot filename.fromselenium_screenshotsimportmake_screenshottry:# Some code which you would like to testexceptExceptionasex:make_screenshot(webdriver,str_description=str(ex))raiseLinksPYPIreadthedocsGitHubProject local LinksCHANGELOG.CONTRIBUTING.ContactsEmail:stas.prokopiev@gmail.comvk.comFacebookLicenseThis project is licensed under the MIT License.