File Upload and Download Creations
Qualiti supports file uploads through automated scripts by leveraging specific selectors and variables to manage the download and upload process. Below, we demonstrate a step-by-step example and provide reusable templates for implementing file uploads within Qualiti.
Step-by-Step Example
Here is the code example demonstrating how to download and upload a file in Qualiti:
page.goto("https://docs.google.com/spreadsheets/d/1tRRVKWJZiS2D_6QuBcDUlKSQyOI_Dv-E-m46-RZoo6A/edit?usp=sharing")
page.get_by_role("menuitem", name="File").click()
page.get_by_role("menuitem", name="Download d ►", exact=True).click()
with page.expect_download() as download_info:
page.get_by_label("Comma Separated Values (.csv").click()
variables.downloaded_file_path = download_info.value.path()
page.goto("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_file")
page.frame_locator("iframe[name=\"iframeResult\"]").get_by_label("Select a file:").set_input_files(downloaded_file_path)
Process Breakdown
Steps 1-3: Navigate to the Download
- Navigate to the desired URL where the file is located.
- Interact with the file menu to prepare for download.
Step 4: Download the File
In this step, the file is downloaded, and its path is stored for later use.
Code:
with page.expect_download() as download_info:
page.get_by_label("Comma Separated Values (.csv").click()
variables.downloaded_file_path = download_info.value.path()
- Line 1: The
with
statement sets up a listener to detect and capture the downloaded file. - Line 2:
page.get_by_label
locates the download button for the specified file type. - Line 3: The file path is saved in the
downloaded_file_path
variable for later use.
Mark this step as an ASSERTION step in Qualiti to prevent the AI from overwriting the code.
Step 5: Navigate to the Upload Page
Redirect to the page where the file will be uploaded. Ensure that the file upload field is accessible.
Step 6: Upload the File
The file is injected directly into the upload field, bypassing the file selection dialog.
Code:
page.frame_locator("iframe[name=\"iframeResult\"]").get_by_label("Select a file:").set_input_files(downloaded_file_path)
- Explanation: This line uses the stored file path (
downloaded_file_path
) to upload the file directly into the designated upload field.
Mark this step as an ASSERTION step in Qualiti to prevent the AI from overwriting the code.
Templates for File Upload Automation
File Download Template
Use this template to capture the download file path:
with page.expect_download() as download_info:
page.locator(####).get_by_#####.click()
variables.downloaded_file_path = download_info.value.path()
- Replace
####
and#####
with the appropriate selectors for your application. - Ensure this code is in the same step as the download action.
- Mark the step as an ASSERTION step.
File Upload Template
Use this template to upload the downloaded file:
page.locator(#####).get_by_#####().set_input_files(downloaded_file_path)
- Replace
#####
with the appropriate selectors for your application. - Ensure this code is in the same step as the upload action.
- Mark the step as an ASSERTION step.
Best Practices
- Always verify selectors and labels are correct for your application.
- Mark download and upload steps as ASSERTION steps to avoid overwriting by Qualiti's AI.
- Test each step individually to ensure reliability before combining into a full workflow.
By following these steps and using the provided templates, you can automate file uploads in Qualiti efficiently and effectively.