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
    driver.navigate_to("https://images.google.com/")

    # Navigate to upload image view
    e(
        driver, "css", "div[aria-label='Search by image']"
    ).wait_until_visible().click()

    e(
        driver, "css", "a[href='about:invalid#zClosurez']"
    ).wait_until_visible().click()

    file_input_element = e(
        driver, "css", "input[name='encoded_image']"
    )
    file_input_element.wait_until_visible()

    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)

    e(driver, "css", "div#res").wait_until_visible()

    driver.save_screenshot("search_by_image_results.png")