File tree Expand file tree Collapse file tree 5 files changed +73
-0
lines changed Expand file tree Collapse file tree 5 files changed +73
-0
lines changed Original file line number Diff line number Diff line change @@ -5,3 +5,4 @@ erl_crash.dump
55.DS_Store
66doc /
77screenshot- * .png
8+ /.idea
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ defmodule Hound.Helpers do
77 import Hound.Helpers.Cookie
88 import Hound.Helpers.Dialog
99 import Hound.Helpers.Element
10+ import Hound.Helpers.File
1011 import Hound.Helpers.Navigation
1112 import Hound.Helpers.Orientation
1213 import Hound.Helpers.Page
Original file line number Diff line number Diff line change 1+ defmodule Hound.Helpers.File do
2+ @ moduledoc "Functions to work with an files"
3+
4+ import Hound.RequestUtils
5+
6+ @ spec upload ( String . t ) :: String . t
7+ def upload ( local_file_path ) do
8+ fail_if_webdriver_phantomjs ( "upload()" )
9+
10+ session_id = Hound . current_session_id
11+ { :ok , zip_file_path } = local_file_path
12+ |> zip ( )
13+ zip_file_content = zip_file_path
14+ |> File . read! ( )
15+ |> :base64 . encode ( )
16+ zip_file_path
17+ |> File . rm ( )
18+ make_req ( :post , "session/#{ session_id } /file" , % { file: zip_file_content } )
19+ end
20+
21+ @ spec zip ( String . t ) :: String . t
22+ def zip ( local_file_path ) do
23+
24+
25+
26+ local_file_name = local_file_path
27+ |> Path . basename ( )
28+ local_file_name <> ".zip"
29+ |> to_char_list ( )
30+ |> :zip . create (
31+ [
32+ {
33+ local_file_name
34+ |> to_char_list ( ) ,
35+ local_file_path
36+ |> File . read! ( )
37+ }
38+ ]
39+ )
40+ end
41+
42+ defp fail_if_webdriver_phantomjs ( function ) do
43+ Hound.NotSupportedError . raise_for ( % { driver: "phantomjs" } , function )
44+ end
45+ end
Original file line number Diff line number Diff line change 1+ defmodule FileTest do
2+ use ExUnit.Case
3+ use Hound.Helpers
4+
5+ hound_session ( )
6+
7+ test "must upload the file to a remote server" do
8+ local_file_path = "./test/sample_files/test.txt"
9+ if is_webdriver_phantomjs ( ) do
10+ assert_raise Hound.NotSupportedError , "upload() is not supported by driver phantomjs with browser phantomjs" , fn ->
11+ local_file_path
12+ |> upload ( )
13+ end
14+ else
15+ file_path_type = local_file_path
16+ |> upload ( )
17+ assert is_binary ( file_path_type )
18+ end
19+ end
20+
21+ defp is_webdriver_phantomjs ( ) do
22+ match? ( { :ok , % { driver: "phantomjs" } } , Hound . driver_info )
23+ end
24+
25+ end
Original file line number Diff line number Diff line change 1+ test
You can’t perform that action at this time.
0 commit comments