@@ -11,18 +11,21 @@ defmodule PhoenixTest.Playwright.Frame do
1111 import PhoenixTest.Playwright.Connection , only: [ post: 1 , post: 2 ]
1212
1313 alias PhoenixTest.Playwright.Config
14+ alias PhoenixTest.Playwright.Result
1415 alias PhoenixTest.Playwright.Serialization
1516
1617 def goto ( frame_id , url ) do
1718 params = % { url: url }
18- post ( guid: frame_id , method: :goto , params: params )
19- :ok
19+
20+ [ guid: frame_id , method: :goto , params: params ]
21+ |> post ( )
22+ |> Result . from_response ( & & 1 )
2023 end
2124
2225 def url ( frame_id ) do
2326 [ guid: frame_id , method: :url , params: % { } ]
2427 |> post ( )
25- |> unwrap_response ( & & 1 . result . value )
28+ |> Result . from_response ( & & 1 . result . value )
2629 end
2730
2831 def evaluate ( frame_id , js , opts \\ [ ] ) do
@@ -33,8 +36,8 @@ defmodule PhoenixTest.Playwright.Frame do
3336
3437 [ guid: frame_id , method: :evaluate_expression , params: params ]
3538 |> post ( )
36- |> unwrap_response ( & & 1 . result . value )
37- |> Serialization . deserialize_arg ( )
39+ |> Result . from_response ( & & 1 . result . value )
40+ |> Result . map ( & Serialization . deserialize_arg / 1 )
3841 end
3942
4043 def press ( frame_id , selector , key , opts \\ [ ] ) do
@@ -45,7 +48,7 @@ defmodule PhoenixTest.Playwright.Frame do
4548
4649 [ guid: frame_id , method: :press , params: params ]
4750 |> post ( timeout )
48- |> unwrap_response ( & & 1 )
51+ |> Result . from_response ( & & 1 )
4952 end
5053
5154 def type ( frame_id , selector , text , opts \\ [ ] ) do
@@ -56,41 +59,41 @@ defmodule PhoenixTest.Playwright.Frame do
5659
5760 [ guid: frame_id , method: :type , params: params ]
5861 |> post ( timeout )
59- |> unwrap_response ( & & 1 )
62+ |> Result . from_response ( & & 1 )
6063 end
6164
6265 def title ( frame_id ) do
6366 [ guid: frame_id , method: :title ]
6467 |> post ( )
65- |> unwrap_response ( & & 1 . result . value )
68+ |> Result . from_response ( & & 1 . result . value )
6669 end
6770
6871 def expect ( frame_id , params ) do
6972 params = Enum . into ( params , % { is_not: false } )
7073
7174 [ guid: frame_id , method: :expect , params: params ]
7275 |> post ( )
73- |> unwrap_response ( & & 1 . result . matches )
76+ |> Result . from_response ( & & 1 . result . matches )
7477 end
7578
7679 def wait_for_selector ( frame_id , params ) do
7780 [ guid: frame_id , method: :wait_for_selector , params: params ]
7881 |> post ( )
79- |> unwrap_response ( & & 1 . result . element )
82+ |> Result . from_response ( & & 1 . result . element )
8083 end
8184
8285 def inner_html ( frame_id , selector ) do
8386 params = % { selector: selector }
8487
8588 [ guid: frame_id , method: "innerHTML" , params: params ]
8689 |> post ( )
87- |> unwrap_response ( & & 1 . result . value )
90+ |> Result . from_response ( & & 1 . result . value )
8891 end
8992
9093 def content ( frame_id ) do
9194 [ guid: frame_id , method: :content ]
9295 |> post ( )
93- |> unwrap_response ( & & 1 . result . value )
96+ |> Result . from_response ( & & 1 . result . value )
9497 end
9598
9699 def fill ( frame_id , selector , value , opts \\ [ ] ) do
@@ -99,7 +102,7 @@ defmodule PhoenixTest.Playwright.Frame do
99102
100103 [ guid: frame_id , method: :fill , params: params ]
101104 |> post ( )
102- |> unwrap_response ( & & 1 )
105+ |> Result . from_response ( & & 1 )
103106 end
104107
105108 def select_option ( frame_id , selector , options , opts \\ [ ] ) do
@@ -108,7 +111,7 @@ defmodule PhoenixTest.Playwright.Frame do
108111
109112 [ guid: frame_id , method: :select_option , params: params ]
110113 |> post ( )
111- |> unwrap_response ( & & 1 )
114+ |> Result . from_response ( & & 1 )
112115 end
113116
114117 def check ( frame_id , selector , opts \\ [ ] ) do
@@ -117,7 +120,7 @@ defmodule PhoenixTest.Playwright.Frame do
117120
118121 [ guid: frame_id , method: :check , params: params ]
119122 |> post ( )
120- |> unwrap_response ( & & 1 )
123+ |> Result . from_response ( & & 1 )
121124 end
122125
123126 def uncheck ( frame_id , selector , opts \\ [ ] ) do
@@ -126,7 +129,7 @@ defmodule PhoenixTest.Playwright.Frame do
126129
127130 [ guid: frame_id , method: :uncheck , params: params ]
128131 |> post ( )
129- |> unwrap_response ( & & 1 )
132+ |> Result . from_response ( & & 1 )
130133 end
131134
132135 def set_input_files ( frame_id , selector , paths , opts \\ [ ] ) do
@@ -135,7 +138,7 @@ defmodule PhoenixTest.Playwright.Frame do
135138
136139 [ guid: frame_id , method: :set_input_files , params: params ]
137140 |> post ( )
138- |> unwrap_response ( & & 1 )
141+ |> Result . from_response ( & & 1 )
139142 end
140143
141144 def click ( frame_id , selector , opts \\ [ ] ) do
@@ -144,7 +147,7 @@ defmodule PhoenixTest.Playwright.Frame do
144147
145148 [ guid: frame_id , method: :click , params: params ]
146149 |> post ( )
147- |> unwrap_response ( & & 1 )
150+ |> Result . from_response ( & & 1 )
148151 end
149152
150153 def blur ( frame_id , selector , opts \\ [ ] ) do
@@ -153,13 +156,6 @@ defmodule PhoenixTest.Playwright.Frame do
153156
154157 [ guid: frame_id , method: :blur , params: params ]
155158 |> post ( )
156- |> unwrap_response ( & & 1 )
157- end
158-
159- defp unwrap_response ( response , fun ) do
160- case response do
161- % { error: _ } = error -> { :error , error }
162- _ -> { :ok , fun . ( response ) }
163- end
159+ |> Result . from_response ( & & 1 )
164160 end
165161end
0 commit comments