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