hound
hound copied to clipboard
file upload
Hi,
Is there anyone who has successfully written a test that interacts with file upload windows? Of course, I can open the dialog but when I try to select the file with send_text (filename)
, nothing seems to happen on the dialog. I've also tried to use Hound.Helpers.Dialog
without success. Any tips?
Add two functions
def zip(local_file_path) do
local_file_name = local_file_path
|> Path.basename()
local_file_name <> ".zip"
|> to_charlist()
|> :zip.create(
[
{
local_file_name
|> to_charlist(),
local_file_path
|> File.read!()
}
]
)
end
def upload(local_file_path) do
fail_if_webdriver_phantomjs("upload()")
session_id = Hound.current_session_id
{:ok, zip_file_path} = local_file_path
|> zip()
zip_file_content = zip_file_path
|> File.read!()
|> :base64.encode()
zip_file_path
|> File.rm()
Hound.RequestUtils.make_req(:post, "session/#{session_id}/file", %{file: zip_file_content})
end
Next
local_file = "./file_path/file_name"
remote_file = upload(local_file)
file_upload = find_element(:id, "file_upload")
clear_field(file_upload)
fill_field(file_upload, remote_file)
Create pull request https://github.com/HashNuke/hound/pull/181/files