octaltree / playwright-rust

Playwright port to Rust
298 stars 31 forks source link

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

Open randall-coding opened 2 years ago

randall-coding commented 2 years ago

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 commented 2 years ago

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