@@ -12,17 +12,18 @@ import Data.Argonaut (Json, (.?))
1212import Data.Argonaut as J
1313import Data.Array as A
1414import Data.Either (Either(..))
15−import Data.Traversable as F
1615import Data.Map as Map
1716import Data.Maybe (Maybe(..))
1817import Data.Newtype (class Newtype, un)
19−import Data.StrMap as SM
2018import Data.String as Str
2119import Data.Symbol (SProxy(..))
2220import Data.Time.Duration (Milliseconds(..))
21+import Data.Traversable as F
2322import Data.Tuple (Tuple(..))
2423import Data.Variant as V
25−import Data.XPath.Types as X
24+import Data.XPath.AST as XA
25+import Data.XPath.Printer (printPath)
26+import Foreign.Object as FO
2627import Node.Encoding as NE
2728import Node.Path (FilePath)
2829
@@ -45,7 +46,7 @@ decodeElement = J.decodeJson >=> \obj →
4546 map Element $ obj .? "element-6066-11e4-a52e-4f735466cecf" <|> obj .? "ELEMENT"
4647
4748encodeElement ∷ Element → Json
48−encodeElement (Element eid) = J.encodeJson $ SM.fromFoldable
49+encodeElement (Element eid) = J.encodeJson $ FO.fromFoldable
4950 [ Tuple "element-6066-11e4-a52e-4f735466cecf" eid
5051 , Tuple "ELEMENT" eid
5152 ]
@@ -86,7 +87,7 @@ decodeTimeouts = J.decodeJson >=> \obj → do
8687 pure { script, pageLoad, implicit }
8788
8889encodeTimeouts ∷ Timeouts → Json
89−encodeTimeouts r = J.encodeJson $ SM.fromFoldable
90+encodeTimeouts r = J.encodeJson $ FO.fromFoldable
9091 [ Tuple "script" (un Milliseconds r.script)
9192 , Tuple "pageLoad" (un Milliseconds r.pageLoad)
9293 , Tuple "implicit" (un Milliseconds r.implicit)
@@ -94,22 +95,22 @@ encodeTimeouts r = J.encodeJson $ SM.fromFoldable
9495
9596encodeLegacyTimeouts ∷ Timeouts → Array Json
9697encodeLegacyTimeouts r =
97− [ J.encodeJson $ SM.singleton "script" $ un Milliseconds r.script
98− , J.encodeJson $ SM.singleton "implicit" $ un Milliseconds r.implicit
99− , J.encodeJson $ SM.singleton "page load" $ un Milliseconds r.pageLoad
98+ [ J.encodeJson $ FO.singleton "script" $ un Milliseconds r.script
99+ , J.encodeJson $ FO.singleton "implicit" $ un Milliseconds r.implicit
100+ , J.encodeJson $ FO.singleton "page load" $ un Milliseconds r.pageLoad
100101 ]
101102
102103encodeGoRequest ∷ String → Json
103−encodeGoRequest url = J.encodeJson $ SM.fromFoldable [ Tuple "url" url ]
104+encodeGoRequest url = J.encodeJson $ FO.fromFoldable [ Tuple "url" url ]
104105
105106decodeWindowHandle ∷ Json → Either String WindowHandle
106107decodeWindowHandle = map WindowHandle <<< J.decodeJson
107108
108109encodeSwitchToWindowRequest ∷ WindowHandle → Json
109−encodeSwitchToWindowRequest w = J.encodeJson $ SM.fromFoldable [ Tuple "handle" $ un WindowHandle w ]
110+encodeSwitchToWindowRequest w = J.encodeJson $ FO.fromFoldable [ Tuple "handle" $ un WindowHandle w ]
110111
111112encodeFrameId ∷ FrameId → Json
112−encodeFrameId fid = J.encodeJson $ SM.fromFoldable [ Tuple "id" encoded ]
113+encodeFrameId fid = J.encodeJson $ FO.fromFoldable [ Tuple "id" encoded ]
113114 where
114115 encoded = case fid of
115116 TopFrame → J.jsonNull
@@ -143,12 +144,12 @@ decodeRectangleLegacy { size, position } = do
143144
144145encodeRectangleLegacy ∷ Rectangle → { size ∷ Json, position ∷ Json }
145146encodeRectangleLegacy r =
146− { size: J.encodeJson $ SM.fromFoldable [ Tuple "width" r.width, Tuple "height" r.height ]
147− , position: J.encodeJson $ SM.fromFoldable [ Tuple "x" r.x, Tuple "y" r.y ]
147+ { size: J.encodeJson $ FO.fromFoldable [ Tuple "width" r.width, Tuple "height" r.height ]
148+ , position: J.encodeJson $ FO.fromFoldable [ Tuple "x" r.x, Tuple "y" r.y ]
148149 }
149150
150151encodeRectangle ∷ Rectangle → Json
151−encodeRectangle r = J.encodeJson $ SM.fromFoldable
152+encodeRectangle r = J.encodeJson $ FO.fromFoldable
152153 [ Tuple "width" r.width
153154 , Tuple "height" r.height
154155 , Tuple "x" r.x
@@ -157,7 +158,7 @@ encodeRectangle r = J.encodeJson $ SM.fromFoldable
157158
158159data Locator
159160 = ByCss CSS.Selector
160− | ByXPath X.XPath
161+ | ByXPath XA.Path
161162 | ByTagName String
162163 | ByLinkText String
163164 | ByPartialLinkText String
@@ -169,14 +170,14 @@ type RawLocator =
169170 }
170171
171172encodeLocator ∷ Locator → Json
172−encodeLocator l = J.encodeJson $ SM.fromFoldable case l of
173+encodeLocator l = J.encodeJson $ FO.fromFoldable case l of
173174 ByCss sel →
174175 [ Tuple "using" "css selector"
175176 , Tuple "value" $ CSSR.selector sel
176177 ]
177178 ByXPath sel →
178179 [ Tuple "using" "xpath"
179− , Tuple "value" $ X.printXPath sel
180+ , Tuple "value" $ printPath sel
180181 ]
181182 ByLinkText sel →
182183 [ Tuple "using" "link text"
@@ -196,7 +197,7 @@ encodeLocator l = J.encodeJson $ SM.fromFoldable case l of
196197 ]
197198
198199encodeSendKeysRequest ∷ String → Json
199−encodeSendKeysRequest txt = J.encodeJson $ SM.fromFoldable [ Tuple "text" txt ]
200+encodeSendKeysRequest txt = J.encodeJson $ FO.fromFoldable [ Tuple "text" txt ]
200201
201202type Script =
202203 { script ∷ String
@@ -204,7 +205,7 @@ type Script =
204205 }
205206
206207encodeScript ∷ Script → Json
207−encodeScript r = J.encodeJson $ SM.fromFoldable
208+encodeScript r = J.encodeJson $ FO.fromFoldable
208209 [ Tuple "script" $ J.encodeJson r.script
209210 , Tuple "args" $ J.encodeJson r.args
210211 ]
@@ -220,8 +221,8 @@ type Cookie =
220221 }
221222
222223encodeCookie ∷ Cookie → Json
223−encodeCookie r = J.encodeJson $ SM.fromFoldable
224− [ Tuple "cookie" $ SM.fromFoldable
224+encodeCookie r = J.encodeJson $ FO.fromFoldable
225+ [ Tuple "cookie" $ FO.fromFoldable
225226 $ [ Tuple "name" $ J.encodeJson r.name
226227 , Tuple "value" $ J.encodeJson r.value
227228 ]
@@ -293,8 +294,8 @@ type PointerMove =
293294 , y ∷ Int
294295 }
295296
296−encodePointerMove ∷ PointerMove → SM.StrMap Json
297−encodePointerMove r = SM.fromFoldable
297+encodePointerMove ∷ PointerMove → FO.Object Json
298+encodePointerMove r = FO.fromFoldable
298299 [ Tuple "x" $ J.encodeJson r.x
299300 , Tuple "y" $ J.encodeJson r.y
300301 , Tuple "duration" $ J.encodeJson $ un Milliseconds r.duration
@@ -332,32 +333,32 @@ pointerMove = V.inj (SProxy ∷ SProxy "pointerMove")
332333encodeAction ∷ Action → Json
333334encodeAction = V.match
334335 { pause: \ms →
335− J.encodeJson $ SM.fromFoldable
336+ J.encodeJson $ FO.fromFoldable
336337 [ Tuple "duration" $ J.encodeJson $ un Milliseconds ms
337338 , Tuple "type" $ J.encodeJson "pause"
338339 ]
339340 , keyDown: \ch →
340− J.encodeJson $ SM.fromFoldable
341+ J.encodeJson $ FO.fromFoldable
341342 [ Tuple "value" $ J.encodeJson ch
342343 , Tuple "type" $ J.encodeJson "keyDown"
343344 ]
344345 , keyUp: \ch →
345− J.encodeJson $ SM.fromFoldable
346+ J.encodeJson $ FO.fromFoldable
346347 [ Tuple "value" $ J.encodeJson ch
347348 , Tuple "type" $ J.encodeJson "keyUp"
348349 ]
349350 , pointerUp: \btn →
350− J.encodeJson $ SM.fromFoldable
351+ J.encodeJson $ FO.fromFoldable
351352 [ Tuple "button" $ encodeButton btn
352353 , Tuple "type" $ J.encodeJson "pointerUp"
353354 ]
354355 , pointerDown: \btn →
355− J.encodeJson $ SM.fromFoldable
356+ J.encodeJson $ FO.fromFoldable
356357 [ Tuple "button" $ encodeButton btn
357358 , Tuple "type" $ J.encodeJson "pointerDown"
358359 ]
359360 , pointerMove: \pm →
360− J.encodeJson $ SM.insert "type" (J.encodeJson "pointerMove") $ encodePointerMove pm
361+ J.encodeJson $ FO.insert "type" (J.encodeJson "pointerMove") $ encodePointerMove pm
361362 }
362363
363364
@@ -378,31 +379,31 @@ data ActionSequence
378379 (Array (V.Variant (pause ∷ Milliseconds, pointerUp ∷ Button, pointerDown ∷ Button, pointerMove ∷ PointerMove)))
379380
380381-- Right, this is not an `Array` but `StrMap` because all `ActionSequence`s are tagged with unique id's
381−type ActionRequest = SM.StrMap ActionSequence
382+type ActionRequest = FO.Object ActionSequence
382383
383384encodeActionRequest ∷ ActionRequest → Json
384−encodeActionRequest sm = J.encodeJson $ SM.singleton "actions" $ map encodePair arrayOfPairs
385+encodeActionRequest sm = J.encodeJson $ FO.singleton "actions" $ map encodePair arrayOfPairs
385386 where
386387 arrayOfPairs ∷ Array (Tuple String ActionSequence)
387− arrayOfPairs = SM.toUnfoldable sm
388+ arrayOfPairs = FO.toUnfoldable sm
388389
389390 encodePair ∷ Tuple String ActionSequence → Json
390391 encodePair (Tuple identifier sequence) =
391− J.encodeJson $ SM.insert "id" (J.encodeJson identifier) $ encodeSequence sequence
392+ J.encodeJson $ FO.insert "id" (J.encodeJson identifier) $ encodeSequence sequence
392393
393− encodeSequence ∷ ActionSequence → J.JObject
394+ encodeSequence ∷ ActionSequence → FO.Object Json
394395 encodeSequence = case _ of
395− NoSource as → SM.fromFoldable
396+ NoSource as → FO.fromFoldable
396397 [ Tuple "type" $ J.encodeJson "none"
397398 , Tuple "actions" $ J.encodeJson $ map (encodeAction <<< V.expand) as
398399 ]
399− Key as → SM.fromFoldable
400+ Key as → FO.fromFoldable
400401 [ Tuple "type" $ J.encodeJson "key"
401402 , Tuple "actions" $ J.encodeJson $ map (encodeAction <<< V.expand) as
402403 ]
403− Pointer ptype as → SM.fromFoldable
404+ Pointer ptype as → FO.fromFoldable
404405 [ Tuple "type" $ J.encodeJson "pointer"
405− , Tuple "parameters" $ J.encodeJson $ SM.singleton "pointerType" $ printPointerType ptype
406+ , Tuple "parameters" $ J.encodeJson $ FO.singleton "pointerType" $ printPointerType ptype
406407 , Tuple "actions" $ J.encodeJson $ map (encodeAction <<< V.expand) as
407408 ]
408409
@@ -479,7 +480,7 @@ encodeCapabilities = F.foldl (\b a → J.extend (encodeCapability a) b) J.jsonEm
479480
480481decodeCapabilities ∷ Json → Either String (Array Capability)
481482decodeCapabilities = J.decodeJson >=> \obj →
482− F.for (SM.toUnfoldable obj) \l@(Tuple key val) →
483+ F.for (FO.toUnfoldable obj) \l@(Tuple key val) →
483484 decodeCapability l <|> Right (CustomCapability key val)
484485 where
485486 decodeCapability ∷ Tuple String Json → Either String Capability
@@ -518,7 +519,7 @@ type CapabilitiesRequest =
518519 }
519520
520521encodeCapabilitiesRequest ∷ CapabilitiesRequest → Json
521−encodeCapabilitiesRequest r = J.encodeJson $ SM.singleton "capabilities" $ SM.fromFoldable
522+encodeCapabilitiesRequest r = J.encodeJson $ FO.singleton "capabilities" $ FO.fromFoldable
522523 [ Tuple "alwaysMatch" $ encodeCapabilities r.alwaysMatch
523524 , Tuple "firstMatch" $ J.encodeJson $ map encodeCapabilities r.firstMatch
524525 ]
@@ -530,7 +531,7 @@ type MoveToRequest =
530531 }
531532
532533encodeMoveToRequest ∷ MoveToRequest → Json
533−encodeMoveToRequest r = J.encodeJson $ SM.fromFoldable
534+encodeMoveToRequest r = J.encodeJson $ FO.fromFoldable
534535 [ Tuple "element" $ case r.element of
535536 Nothing → J.jsonNull
536537 Just el → J.encodeJson $ un Element el