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

[Bug]: Not able to download the files using playwright #33145

Open
surbhiD opened this issue Oct 16, 2024 · 2 comments
Open

[Bug]: Not able to download the files using playwright #33145

surbhiD opened this issue Oct 16, 2024 · 2 comments

Comments

@surbhiD
Copy link

surbhiD commented Oct 16, 2024

Version

1.46.0

Steps to reproduce

Opened the browser
navigated to page
filled the details on page and clicked on export button
Actual : some random id is visible on screen but not able to open it .The file is saved no where

expected: correct file name should get downloaded.also on page the correct file names appears near download icon of page

Expected behavior

expected: correct file name should get downloaded.also on page the correct file names appears near download icon of page

Actual behavior

Actual : some random id is visible on screen but not able to open it .The file is saved no where
Image

Additional context

this is how i am launching the browser def create_browser(self):
"""
Creates a browser instance for Chrome using Playwright.
"""
try:
self.browser = self.playwright.chromium.launch(
channel= 'chrome',
headless = False,
slow_mo = 1000,

            args = self.get_browser_args()
        )

    except Exception as exception:
        raise Exception(f'Unable to launch Chrome browser for testing. Exception noted: {exception}')
    return self.browser

def get_browser_args(self):
    """
    Returns all the required arguments for launching the browser.
    """
    args = [
        "--test-type",
        "--disable-extensions",
        "--proxy-server='direct://'",
        "--proxy-bypass-list=*",
        '--ignore-certificate-errors',
        "--no-sandbox",
        "--disable-dev-shm-usage",
        "--disable-browser-side-navigation",
        "--disable-web-security",
        "--disable-infobars",
        "--disable-popup-blocking",
        "--disable-features=VizDisplayCompositor",
        "--disable-gpu",
        "--disable-setuid-sandbox",
        "--disable-software-rasterizer",
        "--start-maximized",
        '--disable-blink-features=AutomationControlled',
        '--disable-features=IsolateOrigins,site-per-process',
        '--disable-site-isolation-trials'
    ]

also for download using this code def download_file(self, timeout_seconds):
"""
Waits for a download to complete within the specified timeout.

    :param timeout_seconds: Maximum time to wait for the download to complete.
    :return: The download object or None if download fails.
    """
    try:
        # Wait for the download event
        download = self._page.wait_for_event('download', timeout=timeout_seconds * 1000)
        return download
    except PlaywrightTimeoutError:
        # Handle timeout exceptions when the download does not occur within the expected time
        assert_verify.verify_fail(f"Download did not complete within {timeout_seconds} seconds.")
        return None        

def file_download_implementation():
if dimension_type is not None and file_extension is not None:
self.get_element('Common_Report_Btn', *[dimension_type, dimension_type]).click_element()
elif dimension_type is None and link is not None:
self.get_element('Common_link', link).click_element()
else:
file_extension=dimension_type
self.get_element('Export_Btn').click_element()

    # Wait for the download to complete
    filedownload_waiting_time = ExecutionManager.filedownload_waiting_time
    download = self.download_file(timeout_seconds=filedownload_waiting_time)

    if download:
        # Get the suggested filename and save it to the custom folder
        last_modified_file_name = download.suggested_filename
        download_path = os.path.join(folder_path, last_modified_file_name)
        download.save_as(download_path)

Environment

System:
OS: Windows 10 10.0.19045
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
Memory: 2.46 GB / 15.84 GB
Binaries:
Node: 18.15.0 - C:\Program Files\nodejs\node.EXE
npm: 9.5.0 - C:\Program Files\nodejs\npm.CMD
IDEs:
VSCode: 1.94.2 - C:\Users\dhsu3001\AppData\Local\Programs\Microsoft VS Code\bin\code.CMD

@surbhiD
Copy link
Author

surbhiD commented Oct 16, 2024

Its working fine on mozilla browser

@dgozman
Copy link
Contributor

dgozman commented Oct 17, 2024

@surbhiD When you call download.save_as(download_path), the downloaded file should be saved at the path you've specified. However, that path is not connected to the browser UI in any means, so clicking in the UI will not open it.

If you think that download.save_as(download_path) did not work as expected, please provide a full self-contained repro so that we can reproduce locally and fix the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants