-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2723428
commit 1ecd697
Showing
5 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ erl_crash.dump | |
.DS_Store | ||
doc/ | ||
screenshot-*.png | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
defmodule Hound.Helpers.File do | ||
@moduledoc "Functions to work with an files" | ||
|
||
import Hound.RequestUtils | ||
|
||
@spec upload(String.t) :: String.t | ||
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() | ||
make_req(:post, "session/#{session_id}/file", %{file: zip_file_content}) | ||
end | ||
|
||
@spec zip(String.t) :: String.t | ||
def zip(local_file_path) do | ||
|
||
|
||
|
||
local_file_name = local_file_path | ||
|> Path.basename() | ||
local_file_name <> ".zip" | ||
|> to_char_list() | ||
|> :zip.create( | ||
[ | ||
{ | ||
local_file_name | ||
|> to_char_list(), | ||
local_file_path | ||
|> File.read!() | ||
} | ||
] | ||
) | ||
end | ||
|
||
defp fail_if_webdriver_phantomjs(function) do | ||
Hound.NotSupportedError.raise_for(%{driver: "phantomjs"}, function) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
defmodule FileTest do | ||
use ExUnit.Case | ||
use Hound.Helpers | ||
|
||
hound_session() | ||
|
||
test "must upload the file to a remote server" do | ||
local_file_path = "./test/sample_files/test.txt" | ||
if is_webdriver_phantomjs() do | ||
assert_raise Hound.NotSupportedError, "upload() is not supported by driver phantomjs with browser phantomjs", fn -> | ||
local_file_path | ||
|> upload() | ||
end | ||
else | ||
file_path_type = local_file_path | ||
|> upload() | ||
assert is_binary(file_path_type) | ||
end | ||
end | ||
|
||
defp is_webdriver_phantomjs() do | ||
match?({:ok, %{driver: "phantomjs"}}, Hound.driver_info) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test |