I'm writing tests for my Django project using playwright and StaticLiveServerTestCase. In one test I need to choose two files using input[type=file] field and send them to the server.
file_input = page.locator('input[type="file"]')
file_input.set_input_files(["Input1.xlsx", "Input2.xlsx"])
But Playwright sending only first file and my test fails. I've tried to watch does input field has only one file, but it has both of them inside after choosing
file_info = page.evaluate("""
element => {
const files = Array.from(element.files);
return files.map(file => ({
name: file.name,
size: file.size,
type: file.type
}));
}
""", file_input.element_handle())
print("Files that JS sees:", file_info)
That is the output:
Files that JS sees: [{'name': 'Input1.xlsx', 'size': 5853, 'type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'}, {'name': 'Input2.xlsx', 'size': 5851, 'type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'}]
If you'll ask me I've tried absolute path for files and I've tried to change browsers. I've tried to test it manually and hadn't this problem.
Django version 5.1.6 Playwright version 1.51.0
The problem was on the server side. I forgot to create user for testing 'cause test system creates empty database, that's why I had only one file in the storage.