Fixed storage paths for Selenium screenshots or logs possible?

  • Details:

    Currently I use Python 3.10 and Selenium. I used here in the area of functional testing here in particular UI Testing accordingly also Selenium screenshots. But since I work on different computers, the paths to the folder change accordingly.

        # -*- coding: utf-8 -*-
        import unittest
    import HtmlTestRunner
    from selenium import webdriver
    from selenium.common.exceptions import NoAlertPresentException
    from selenium.common.exceptions import NoSuchElementException
    from import Service
    from import ChromeDriverManager
    # logging.basicConfig(filename = file_name, level = logging.DEBUG)
    ### Browser Testing Checklist ###
    Browser Testing Checklist   
    Project name: | <required> |
    Project manager name: | <required> |
    Project description:  | <required> |
    Browser Test Plan   
    Which browser versions are being used by your target audience?  
    Can you ensure the availability of all those browser versions?  
    Which devices / hardware is needed for conducting those browser tests?  
    Content yes/no
    Are all images available across browsers?   
    Are used fonts working for every browser version?   
    Are all audio files available for every browser?    
    Can the content be consumed on every browser version?   
    Layout  yes/no
    Is the layout consistent?   
    Are all layout element behaving as expected?    
    Is the (responsive) layout working in all browser versions? 
    Are animations and effects running smoothly and as expected?    
    Functionality   yes/no
    Are all features useable in the targeted browser versions?  
    Are all available integrations and 3rd party services running as expected?  
    Are all forms and other dynamic interactions working across browsers?   
    "Are all interactions working equally good with touch input 
    (e.g. from a mobile device) and mouse input (e.g. from a desktop computer)?"
    '''Define class'''
    class OpenDevcrowd(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
            self.base_url = ""
            self.verificationErrors = []
            self.accept_next_alert = True
        ### Start Testing here:###
        # what is testing # | window size | target |
        # tomyside Page     |  1920, 994  |      |
        '''Start Test Mainpage here '''
        def test_tomyside_mainpage(self):
            # Test name: open_tomyside_mainpage
            # Step # | name | target | value
            # 1 | open | / |
            # 2 | setWindowSize | 1920x994 |
            self.driver.set_window_size(1920, 994)
            # 3 | wait | wait 30 |
            # 4 | wait | wait 30 |
            # 5 | close | Firefox |
        Setup: This part is for Assertion setup, logging and more 
        def is_element_present(self, how, what):
                self.driver.find_element(by=how, value=what)
            except NoSuchElementException as e:
                return False
            return True
        def is_alert_present(self):
            except NoAlertPresentException as e:
                return False
            return True
        def close_alert_and_get_its_text(self):
                alert = self.driver.switch_to_alert()
                alert_text = alert.text
                if self.accept_next_alert:
                return alert_text
                self.accept_next_alert = True
        def tearDown(self):
            self.assertEqual([], self.verificationErrors)

    if name == 'main':


    Is there a possibility to set the paths in the structure so that they can still be executed on different computers without constantly adjusting the path?

  • May be you can do something like, get the current working directory and then combine it with your folder/filename to dynamically store your screenshots and logs in a specific folder relative to your project directory.

    I've used something like this in Java,

    System.setProperty("", System.getProperty("user.dir") + "//chromedriver");
    System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "FFLogs.txt");
    File file = new File(System.getProperty("user.dir") + "//data/report-" + currentDate + ".csv");
    String logFile = "./Target/Result-" + currentDate + ".jtl";

    You can figure out something on the same line in Python with,

    driver.save_screenshot('./project_directory/save_screenshot.png') for storing in your current project/code directory.

    Note: I haven't worked with Python personally. But, you should be able to get the current directory and combine it as a string to the filename and parse it to save your screenshot/logs.

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2