playwright-rust icon indicating copy to clipboard operation
playwright-rust copied to clipboard

Is it possible to use just a filepath for file upload with set_input_files_builder()?

Open randall-coding opened this issue 3 years ago • 1 comments

I see that for other languages using playwright it is possible to just provide an element and a filepath to perform file upload https://stackoverflow.com/questions/66132097/playwright-upload-files-from-non-input-element-that-cannot-be-used-page-setinpu

But looking at the source for playwright-rust it appears that I need a File struct which consists of

pub struct File { pub name: String, pub mime: String, pub buffer: String, }

https://docs.rs/playwright/0.0.19/playwright/api/struct.File.html https://docs.rs/playwright/0.0.19/playwright/api/element_handle/struct.ElementHandle.html#method.set_input_files_builder

Is there any way I can call this like those other examples using just the filepath instead of having to provide buffer and mime type?

If I do have to provide buffer can you point me in the right direction of how to produce that in the correct format?

My current test code looks like this:

let f:File = File {
                        name: "../Downloads/video.mp4".to_string(), 
                        mime: "video/mp4".to_string(), 
                        buffer: "".to_string()
                 };
videoInput.set_input_files_builder(f).set_input_files().await.unwrap();

Though for some reason respite setting the mime type I still get the following error:

files[0].mimeType: expected string, got undefined

randall-coding avatar Jan 19 '22 17:01 randall-coding

This issue was addressed on playwright recently, this pull request adds that functionality https://github.com/microsoft/playwright/pull/12937.

But before we can use it in rust, the rust bindings code will need to be updated similarly as they did for java

randall-coding avatar Apr 22 '22 04:04 randall-coding