Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file upload #179

Open
keown opened this issue Aug 29, 2017 · 1 comment
Open

file upload #179

keown opened this issue Aug 29, 2017 · 1 comment

Comments

@keown
Copy link

keown commented Aug 29, 2017

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?

@RODJER200586
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants