Skip to content

[πŸ› Bug]: Β #14777

@morettolss

Description

@morettolss

What happened?

I had a particular case, creating the file and calling the function at the same time it happened that the first file was overwritten by the second one that was being generated. The error does not seem to be reproducible in a standard way but only after X attempts.

How can we reproduce the issue?

print_settings = {
            "recentDestinations": [{
                "id": "Save as PDF",
                "origin": "local",
                "account": "",
            }],
            "selectedDestinationId": "Save as PDF",
            "version": 2,
            "isHeaderFooterEnabled": False,
            "isLandscapeEnabled": True
        }

        user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_2) AppleWebKit/537.36 (KHTML, like Gecko) ' \
                    'Chrome/110.0.0.0 Safari/537.36'

        options = webdriver.ChromeOptions()
        options.add_argument(f'user-agent={user_agent}')
        options.add_argument("--start-maximized")
        options.add_argument('--window-size=1920,1080')
        options.add_argument(f"user-data-dir=path/tmp/")
        options.add_argument("--headless")
        options.add_argument('--disable-gpu')
        options.add_argument('--no-sandbox')
        options.add_argument('--enable-print-browser')
        options.add_experimental_option("prefs", {
            "printing.print_preview_sticky_settings.appState": json.dumps(print_settings),
            "savefile.default_directory": f'path/tmp/',  # Change default directory for downloads
            "download.default_directory": f'path/tmp/',  # Change default directory for downloads
            "download.prompt_for_download": False,  # To auto download the file
            "download.directory_upgrade": True,
            "profile.default_content_setting_values.automatic_downloads": 1,
            "safebrowsing.enabled": True
        })
        options.add_argument("--kiosk-printing")

        #driver = Chrome(service=service, options=options)
        driver = Chrome( options=options)
        html_bs64 = base64.b64encode(body.encode('utf-8')).decode()
        driver.get("data:text/html;base64," + html_bs64)
        pdf_data = driver.execute_cdp_cmd("Page.printToPDF", print_settings)
        driver.quit()
        f = open(fname_dir, 'wb')
        f.write(base64.b64decode(pdf_data['data']))
        f.close()

Relevant log output

no log output

Operating System

ubuntu

Selenium version

pytohn selenium==4.24.0

What are the browser(s) and version(s) where you see this issue?

Chrome 110

What are the browser driver(s) and version(s) where you see this issue?

Chrome 110

Are you using Selenium Grid?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-needs-triagingA Selenium member will evaluate this soon!C-pyPython BindingsI-defectSomething is not working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions