Masquerade - file upload simulation

Hello, I am looking for a way to simulate file uploads in Jmix without triggering the native system file picker. Since the standard upload component opens a system dialog that cannot be controlled via Masquerade, I would like to programmatically set the file reference or bypass the dialog entirely. I haven’t found a documented solution for this—is there a recommended workaround?
the view contains:
<fileStorageUploadField id=“fileRefField” property=“fileRef”
clearButtonVisible=“true”
fileNameVisible=“true”
required=“true”

Hi!

Thank you for your question.

Unfortunately, there’s no ready-made wrapper component in Masquerade. I created an issue to support upload fields: Support upload fields in Msquerade · Issue #5149 · jmix-framework/jmix · GitHub

For now, you can use the following code in your tests:

    // define file storage upload as Unknown component in your test view class
    @TestComponent
    private Unknown fileStorageUploadField;
    @Test
    public void fileStorageUploadFieldTest() {
        // getting fileStorageUploadField selenide element
        SelenideElement delegate = openFieldsView().getFileStorageUploadField()
                .getDelegate();

        String hostSelector = "jmix-upload-field[%s='%s'] .jmix-upload-button".formatted(
                UI_TEST_ID,
                delegate.getDomAttribute(UI_TEST_ID));
        String inputSelector = "input#fileInput";

        // select the file input element using shadowCss selector because
        // it is in the shadow DOM of the original element
        SelenideElement element = $(shadowCss(inputSelector, hostSelector));

        // just upload your file
        File file = new File(FILE_PATH);
        element.shouldBe(EXIST)
                .uploadFile(file);
    }

Best regards,
Dmitriy

I truly appreciate your reply; the solution works perfectly. I will look forward to receiving the wrappers once the support ticket has been processed.

For others users I share how I implemented in Kotlin:
fun uploadFile(uploadField: Unknown, file: File) {
val delegate: SelenideElement = uploadField.delegate

    val hostSelector = "jmix-upload-field[%s='%s'] .jmix-upload-button".format(
        UI_TEST_ID,
        delegate.getDomAttribute(UI_TEST_ID)
    )
    val inputSelector = "input#fileInput"
    
    val element: SelenideElement = `$`(shadowCss(inputSelector, hostSelector))
    
    element.shouldBe(EXIST)
        .uploadFile(file)
}

in view:
val testFile = tempDir.resolve(“test-image.png”).toFile().apply {
val bytes = this@ResourceUITests.javaClass.classLoader.getResourceAsStream(resourcePath)?.readAllBytes()
?: throw IllegalStateException(“Resource not found: $resourcePath”)
writeBytes(bytes)
}
uploadFile(fileRefField, testFile)

@TestComponent(path = ["fileRefField"])
lateinit var fileRefField: Unknown