Set File

Set file #

def set_file(driver: TestUIDriver, element: Elements, file_name: str) -> None

The element parameter specifies the input element where file name has to be set.

The file_name parameter specifies chosen file name. To use files names more safely in code it’s recommended to use predefined constants.

Available test files #

File name (file_name)TypeSize
loaderoSample100KB.pngPNG100KB
loaderoSample1MB.pngPNG1MB
loaderoSample5MB.pngPNG5MB
loaderoSample30MB.pngPNG30MB
loaderoSample100MB.txtTXT100MB

In case there is a need for other file format or size, feel free to contact us.

def test(driver: TestUIDriver):
    # Example of setting sample file into file input field using constants
    # Open DemoQA upload/download page
    driver.navigate_to("https://demoqa.com/upload-download")
    e(driver, "css", "#app").wait_until_visible()

    e(
        driver, "css", "#uploadFile"
    ).wait_until_visible()

    file_input_element = e(
        driver, "css", "#uploadFile"
    )

    driver.save_screenshot("before_file_is_set.png")

    # Upload Loadero sample image
    set_file(
        driver, file_input_element, LOADERO_CONSTANTS.sample_files.png_100KB
    )

    time.sleep(5)

    driver.save_screenshot("search_by_image_results.png")