File tree 5 files changed +70
-0
lines changed
5 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -5,3 +5,4 @@ erl_crash.dump
5
5
.DS_Store
6
6
doc /
7
7
screenshot- * .png
8
+ /.idea
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ defmodule Hound.Helpers do
7
7
import Hound.Helpers.Cookie
8
8
import Hound.Helpers.Dialog
9
9
import Hound.Helpers.Element
10
+ import Hound.Helpers.File
10
11
import Hound.Helpers.Navigation
11
12
import Hound.Helpers.Orientation
12
13
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
+ local_file_name = local_file_path
24
+ |> Path . basename ( )
25
+ local_file_name <> ".zip"
26
+ |> to_charlist ( )
27
+ |> :zip . create (
28
+ [
29
+ {
30
+ local_file_name
31
+ |> to_charlist ( ) ,
32
+ local_file_path
33
+ |> File . read! ( )
34
+ }
35
+ ]
36
+ )
37
+ end
38
+
39
+ defp fail_if_webdriver_phantomjs ( function ) do
40
+ Hound.NotSupportedError . raise_for ( % { driver: "phantomjs" } , function )
41
+ end
42
+ 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 download 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