File download on Headless Chrome Browser not working as expected. Unsure what the issue is

I have a Robot script that logs into a portal and downloads a report. Everything is working as expected, except that the Wait Until Created is failing. The file download should be instant, but I’ve also tried increasing the timeout with no luck.

At this point it’s not even clear if the file is downloading. Ideally I would like to search the entire Docker container for the expected file, but I am new to the Robot Framework so not clear how I do that. Any ideas? Also, any other suggestions on how to troubleshoot?

*** Settings ***
Library    SeleniumLibrary
Library    DateTime
Library    OperatingSystem  # Required to get environment variables

*** Variables ***
${URL}              https://portal.example.com/
${USERNAME}         ${None}
${PASSWORD}         ${None}
${DOWNLOAD_DIR}     ${CURDIR}
${CSV_FILE}         ${DOWNLOAD_DIR}/sessions.csv


*** Test Cases ***
Open Browser and Navigate to Login Page
    [Documentation]    This test case logs into the portal.

    
    Log To Console      .

    # Get the username and password from environment variables
    ${USERNAME}=        Get Environment Variable    CRED_USERNAME
    ${PASSWORD}=        Get Environment Variable    CRED_PASSWORD
    
    # Configure Chrome options for headless mode and enable file downloads
    ${chrome_prefs}    Create Dictionary    download.default_directory=${DOWNLOAD_DIR}    download.prompt_for_download=False    download.directory_upgrade=True    safebrowsing.enabled=True
    ${chrome_options}  Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    Call Method    ${chrome_options}    add_argument    headless
    Call Method    ${chrome_options}    add_argument    disable-gpu
    Call Method    ${chrome_options}    add_experimental_option    prefs    ${chrome_prefs}
    
    # Open browser with custom Chrome options to enable downloads
    Open Browser    ${URL} headlesschrome options=${chrome_options}
    Maximize Browser Window

    # Wait for Login Form to load then sign-in
    Wait Until Page Contains Element        //input[@name='username']    30s
    Input Text                              //input[@name='username']    ${USERNAME}
    Input Text                              //input[@name='password']    ${PASSWORD}
    Click Button                            //button[@type='submit']

    # Wait until the Dashboard loads (indicating a successful sign-in)
    Wait Until Page Contains                Daily Averages    30s

    Log To Console      Successfully logged in

Download Usage Report
    [Documentation]     Generate reports and downloading them.

    Log To Console      .
    Log To Console      Generating Sessions report...

    Click Element                       //div[text()='Usage']
    Wait Until Page Contains Element    //span[text()='Sessions']    30s

    # Get the first day of the previous month & set FROM
    ${first_day_previous_month}=        Evaluate    (datetime.datetime.today().replace(day=1) - datetime.timedelta(days=1)).replace(day=1).strftime('%m-%d-%Y')    datetime
    Input Text                          (//input[@matinput])[1]    ${first_day_previous_month}

    # Get the last day of the previous month & set TO
    ${last_day_previous_month}=     Evaluate    (datetime.datetime.today().replace(day=1) - datetime.timedelta(days=1)).strftime('%m-%d-%Y')    datetime
    Input Text                      (//input[@matinput])[2]    ${last_day_previous_month}

    # Click the "Generate Report" button
    Click Element   //button[@mattooltip='Generate report']
    
    # Wait until "No results" no longer shows on the page (i.e. when the page results load)
    Wait Until Page Does Not Contain    No results    120s

    # Click the "Download" button
    Log             Results returned from report. Downloading report to ${CSV_FILE}
    Click Button    //button[@mattooltip='Download report (*.csv)']


    # Wait for the file to be downloaded
    Wait Until Created              sessions.csv    120s

   

Exit and Close Browser
    Close Browser

4

I had the same issue and this helped me:

https://webdriver.io/docs/best-practices/file-download/

Specifically this part:

const page = await browser.getPuppeteer();
// Initiate a CDP Session:
const cdpSession = await page.target().createCDPSession();
// Set the Download Path:
await cdpSession.send('Browser.setDownloadBehavior', { behavior: 'allow', downloadPath: downloadPath });

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật