@@ -74,8 +74,9 @@ init uri caps = do
7474 actionsEnabled ←
7575 map isRight
7676 $ liftAff
77− $ LP.post uri (LP.InSession session : LP.Actions : Nil)
78− $ LT.encodeActionRequest $ FO.singleton "action-test"
77+ $ LP.post uri (LP.InSession session : LP.Actions : Nil)
78+ $ LT.encodeActionRequest
79+ $ FO.singleton "action-test"
7980 $ LT.NoSource [ LT.pause $ Milliseconds 0.0 ]
8081
8182 let
@@ -93,8 +94,8 @@ init uri caps = do
9394interpret
9495 ∷ ∀ r
9596 . HandleLunaparkInput
96− → Run (BASE_EFFECTS + LUNAPARK + LUNAPARK_ACTIONS + r )
97− ~> Run (BASE_EFFECTS r)
97+ → Run (BASE_EFFECTS + LUNAPARK + LUNAPARK_ACTIONS + r)
98+ ~> Run (BASE_EFFECTS r)
9899interpret input = runLunapark input <<< runLunaparkActions input
99100
100101type BASE_EFFECTS r = EXCEPT LE.Error + R.AFF + R.EFFECT + r
@@ -104,9 +105,10 @@ runLunapark input = do
104105 R.interpretRec (R.on _lunapark (handleLunapark input) R.send)
105106
106107runLunaparkActions
107− ∷ ∀ r. HandleLunaparkInput
108− → Run (BASE_EFFECTS + LUNAPARK + LUNAPARK_ACTIONS + r )
109− ~> Run (BASE_EFFECTS + LUNAPARK + r)
108+ ∷ ∀ r
109+ . HandleLunaparkInput
110+ → Run (BASE_EFFECTS + LUNAPARK + LUNAPARK_ACTIONS + r)
111+ ~> Run (BASE_EFFECTS + LUNAPARK + r)
110112runLunaparkActions input
111113 | input.actionsEnabled = interpretW3CActions Nil
112114 | otherwise = R.interpretRec (R.on _lunaparkActions (jsonWireActions input) R.send)
@@ -114,8 +116,8 @@ runLunaparkActions input
114116interpretW3CActions
115117 ∷ ∀ r
116118 . List LT.ActionSequence
117− → Run (BASE_EFFECTS + LUNAPARK + LUNAPARK_ACTIONS + r )
118− ~> Run (BASE_EFFECTS + LUNAPARK + r )
119+ → Run (BASE_EFFECTS + LUNAPARK + LUNAPARK_ACTIONS + r)
120+ ~> Run (BASE_EFFECTS + LUNAPARK + r)
119121interpretW3CActions acc as = case R.peel as of
120122 Left la → case tag la of
121123 Left a → w3cActions acc interpretW3CActions a
@@ -131,55 +133,83 @@ w3cActions
131133 ∷ ∀ r a
132134 . List LT.ActionSequence
133135 → ( List LT.ActionSequence
134− → Run (BASE_EFFECTS + LUNAPARK + LUNAPARK_ACTIONS + r )
135− ~> Run (BASE_EFFECTS + LUNAPARK + r)
136+ → Run (BASE_EFFECTS + LUNAPARK + LUNAPARK_ACTIONS + r)
137+ ~> Run (BASE_EFFECTS + LUNAPARK + r)
136138 )
137− → ActionF (Run (BASE_EFFECTS + LUNAPARK + LUNAPARK_ACTIONS + r ) a)
139+ → ActionF (Run (BASE_EFFECTS + LUNAPARK + LUNAPARK_ACTIONS + r) a)
138140 → Run (BASE_EFFECTS + LUNAPARK + r) a
139141w3cActions acc loop = case _ of
140142 Click btn next →
141− let seq = [ LT.pointerDown btn, LT.pointerUp btn ]
142− in loop (inMouse seq) next
143+ let
144+ seq = [ LT.pointerDown btn, LT.pointerUp btn ]
145+ in
146+ loop (inMouse seq) next
143147 ButtonDown btn next →
144− let seq = [ LT.pointerDown btn ]
145− in loop (inMouse seq) next
148+ let
149+ seq = [ LT.pointerDown btn ]
150+ in
151+ loop (inMouse seq) next
146152 ButtonUp btn next →
147− let seq = [ LT.pointerUp btn ]
148− in loop (inMouse seq) next
153+ let
154+ seq = [ LT.pointerUp btn ]
155+ in
156+ loop (inMouse seq) next
149157 DoubleClick btn next →
150− let seq = [ LT.pointerDown btn, LT.pointerUp btn, LT.pointerDown btn, LT.pointerUp btn ]
151− in loop (inMouse seq) next
158+ let
159+ seq = [ LT.pointerDown btn, LT.pointerUp btn, LT.pointerDown btn, LT.pointerUp btn ]
160+ in
161+ loop (inMouse seq) next
152162 MoveTo move next →
153− let seq = [ LT.pointerMove move ]
154− in loop (inPointer seq) next
163+ let
164+ seq = [ LT.pointerMove move ]
165+ in
166+ loop (inPointer seq) next
155167 SendKeys txt next →
156− let seq = T.foldMap (\ch → [ LT.keyDown ch, LT.keyUp ch ]) $ Str.toCharArray txt
157− in loop (inKeys seq) next
168+ let
169+ seq = T.foldMap (\ch → [ LT.keyDown ch, LT.keyUp ch ]) $ Str.toCharArray txt
170+ in
171+ loop (inKeys seq) next
158172 Pause ms next →
159− let seq = [ LT.pause ms ]
160− in loop (anywhere seq) next
173+ let
174+ seq = [ LT.pause ms ]
175+ in
176+ loop (anywhere seq) next
161177 InTouch tch → case tch of
162178 Tap next →
163− let seq = [ LT.pointerDown LT.LeftBtn, LT.pointerUp LT.LeftBtn ]
164− in loop (inTouch seq) next
179+ let
180+ seq = [ LT.pointerDown LT.LeftBtn, LT.pointerUp LT.LeftBtn ]
181+ in
182+ loop (inTouch seq) next
165183 TouchDown next →
166− let seq = [ LT.pointerDown LT.LeftBtn ]
167− in loop (inTouch seq) next
184+ let
185+ seq = [ LT.pointerDown LT.LeftBtn ]
186+ in
187+ loop (inTouch seq) next
168188 TouchUp next →
169− let seq = [ LT.pointerUp LT.LeftBtn ]
170− in loop (inTouch seq) next
189+ let
190+ seq = [ LT.pointerUp LT.LeftBtn ]
191+ in
192+ loop (inTouch seq) next
171193 LongClick next →
172− let seq = [ LT.pointerDown LT.LeftBtn, LT.pause (Milliseconds 3000.0), LT.pointerUp LT.LeftBtn ]
173− in loop (inTouch seq) next
194+ let
195+ seq = [ LT.pointerDown LT.LeftBtn, LT.pause (Milliseconds 3000.0), LT.pointerUp LT.LeftBtn ]
196+ in
197+ loop (inTouch seq) next
174198 Flick move next →
175− let seq = [ LT.pointerMove move ]
176− in loop (inTouch seq) next
199+ let
200+ seq = [ LT.pointerMove move ]
201+ in
202+ loop (inTouch seq) next
177203 Scroll move next →
178− let seq = [ LT.pointerMove move ]
179− in loop (inTouch seq) next
204+ let
205+ seq = [ LT.pointerMove move ]
206+ in
207+ loop (inTouch seq) next
180208 DoubleTap next →
181− let seq = [ LT.pointerDown LT.LeftBtn, LT.pointerUp LT.LeftBtn, LT.pointerDown LT.LeftBtn, LT.pointerUp LT.LeftBtn ]
182− in loop (inTouch seq) next
209+ let
210+ seq = [ LT.pointerDown LT.LeftBtn, LT.pointerUp LT.LeftBtn, LT.pointerDown LT.LeftBtn, LT.pointerUp LT.LeftBtn ]
211+ in
212+ loop (inTouch seq) next
183213 where
184214 unconsed = L.uncons acc
185215
@@ -354,19 +384,22 @@ handleLunapark inp = case _ of
354384 pure next
355385 GetWindowRectangle cont → do
356386 res ← tryAndCache "get window rectangle"
357− [ do res ← get (inSession : LP.Window : LP.Rect : Nil)
358− rethrowAsJsonDecodeError $ LT.decodeRectangle res
359− , do position ← get (inSession : LP.Window : LP.Position : Nil)
360− size ← get (inSession : LP.Window : LP.Size : Nil)
361− rethrowAsJsonDecodeError $ LT.decodeRectangleLegacy { position, size }
387+ [ do
388+ res ← get (inSession : LP.Window : LP.Rect : Nil)
389+ rethrowAsJsonDecodeError $ LT.decodeRectangle res
390+ , do
391+ position ← get (inSession : LP.Window : LP.Position : Nil)
392+ size ← get (inSession : LP.Window : LP.Size : Nil)
393+ rethrowAsJsonDecodeError $ LT.decodeRectangleLegacy { position, size }
362394 ]
363395 pure $ cont res
364396 SetWindowRectangle r next → do
365397 tryAndCache "set window rectangle"
366398 [ void $ post (inSession : LP.Window : LP.Rect : Nil) (LT.encodeRectangle r)
367− , do let js = LT.encodeRectangleLegacy r
368− _ ← post (inSession : LP.Window : LP.Size : Nil) js.size
369− void $ post (inSession : LP.Window : LP.Position : Nil) js.position
399+ , do
400+ let js = LT.encodeRectangleLegacy r
401+ _ ← post (inSession : LP.Window : LP.Size : Nil) js.size
402+ void $ post (inSession : LP.Window : LP.Position : Nil) js.position
370403 ]
371404 pure next
372405 MaximizeWindow next → do
@@ -444,91 +477,100 @@ handleLunapark inp = case _ of
444477 map cont $ rethrowAsJsonDecodeError $ LT.decodeElement res
445478 PerformActions req next → do
446479 when inp.actionsEnabled
447− $ void $ post
448− (inSession : LP.Actions : Nil)
449− (LT.encodeActionRequest req)
480+ $ void
481+ $ post
482+ (inSession : LP.Actions : Nil)
483+ (LT.encodeActionRequest req)
450484 pure next
451485 ReleaseActions next → do
452486 when inp.actionsEnabled $ void $ delete (inSession : LP.Actions : Nil)
453487 pure next
454488 OnElement el elF →
455− let inElement = LP.InElement el
456− in case elF of
457− ChildElement loc cont → do
458− res ← post (inSession : inElement : LP.Element : Nil) (LT.encodeLocator loc)
459− map cont $ rethrowAsJsonDecodeError $ LT.decodeElement res
460− ChildElements loc cont → do
461− res ← post (inSession : inElement : LP.Elements : Nil) (LT.encodeLocator loc)
462− map cont $ rethrowAsJsonDecodeError $ T.traverse LT.decodeElement =<< J.decodeJson res
463− ScreenshotEl fp next → do
464− res ← get (inSession : inElement : LP.Screenshot : Nil)
465− screenshotPack ← rethrowAsJsonDecodeError $ LT.decodeScreenshot res
466− buffer ← R.liftEffect $ B.fromString screenshotPack.content screenshotPack.encoding
467− R.liftAff $ FS.writeFile fp buffer
468− pure next
469− IsSelected cont → do
470− res ← get (inSession : inElement : LP.Selected : Nil)
471− map cont $ rethrowAsJsonDecodeError $ J.decodeJson res
472− GetAttribute attr cont → do
473− res ← get (inSession : inElement : LP.Attribute attr : Nil)
474− map cont $ rethrowAsJsonDecodeError $ J.decodeJson res
475− GetProperty prop cont → do
476− map cont $ get (inSession : inElement : LP.Property prop : Nil)
477− GetCss css cont → do
478− res ← get (inSession : inElement : LP.CssValue css : Nil)
479− map cont $ rethrowAsJsonDecodeError $ J.decodeJson res
480− GetText cont → do
481− res ← get (inSession : inElement : LP.Text : Nil)
482− map cont $ rethrowAsJsonDecodeError $ J.decodeJson res
483− GetTagName cont → do
484− res ← get (inSession : inElement : LP.Name : Nil)
485− map cont $ rethrowAsJsonDecodeError $ J.decodeJson res
486− GetRectangle cont →
487− map cont $ tryAndCache "get element rectangle"
488− [ do res ← get (inSession : inElement : LP.Rect : Nil)
489− rethrowAsJsonDecodeError $ LT.decodeRectangle res
490− , do position ← get (inSession : inElement : LP.Position : Nil)
491− size ← get (inSession : inElement : LP.Size : Nil)
492− rethrowAsJsonDecodeError $ LT.decodeRectangleLegacy { position, size }
493− ]
494− IsEnabled cont → do
495− res ← get (inSession : inElement : LP.Enabled : Nil)
496− map cont $ rethrowAsJsonDecodeError $ J.decodeJson res
497− ClickEl next → do
498− _ ← tryAndCache "chromedriver75 update clickElement"
499− [ post' (inSession : inElement : LP.Click : Nil)
500− , post (inSession : inElement : LP.Click : Nil) $ LT.encodeElement el
501− ]
502− pure next
503− ClearEl next → do
504− _ ← tryAndCache "chromedriver75 update clearElement"
505− [ post' (inSession : inElement : LP.Clear : Nil)
506− , post (inSession : inElement : LP.Click : Nil) $ LT.encodeElement el
507− ]
508− pure next
509− SendKeysEl txt next → do
510− _ ← tryAndCache "send keys chromedriver hack"
511− [ post (inSession : inElement : LP.Value : Nil) (LT.encodeSendKeysRequest txt)
512− , post (inSession : inElement : LP.Value : Nil)
513− $ J.encodeJson $ FO.singleton "value" $ Str.toCharArray txt
514− ]
515− pure next
516− IsDisplayed cont → do
517− res ← tryAndCache "is element displayed"
518− [ get (inSession : inElement : LP.Displayed : Nil)
519− , do let script =
520− { script: """var el = arguments[0]; return el.offsetHeight > 0 && el.offsetWidth > 0"""
521− , args: [ LT.encodeElement el ]
522− }
523− handleLunapark inp $ ExecuteScript script identity
524− ]
525− map cont $ rethrowAsJsonDecodeError $ J.decodeJson res
526− Submit next → do
527− _ ← tryAndCache "chromedriver75 update submit form"
528− [ post' (inSession : inElement : LP.Submit : Nil)
529− , post (inSession: inElement : LP.Submit : Nil) $ LT.encodeElement el
530− ]
531− pure next
489+ let
490+ inElement = LP.InElement el
491+ in
492+ case elF of
493+ ChildElement loc cont → do
494+ res ← post (inSession : inElement : LP.Element : Nil) (LT.encodeLocator loc)
495+ map cont $ rethrowAsJsonDecodeError $ LT.decodeElement res
496+ ChildElements loc cont → do
497+ res ← post (inSession : inElement : LP.Elements : Nil) (LT.encodeLocator loc)
498+ map cont $ rethrowAsJsonDecodeError $ T.traverse LT.decodeElement =<< J.decodeJson res
499+ ScreenshotEl fp next → do
500+ res ← get (inSession : inElement : LP.Screenshot : Nil)
501+ screenshotPack ← rethrowAsJsonDecodeError $ LT.decodeScreenshot res
502+ buffer ← R.liftEffect $ B.fromString screenshotPack.content screenshotPack.encoding
503+ R.liftAff $ FS.writeFile fp buffer
504+ pure next
505+ IsSelected cont → do
506+ res ← get (inSession : inElement : LP.Selected : Nil)
507+ map cont $ rethrowAsJsonDecodeError $ J.decodeJson res
508+ GetAttribute attr cont → do
509+ res ← get (inSession : inElement : LP.Attribute attr : Nil)
510+ map cont $ rethrowAsJsonDecodeError $ J.decodeJson res
511+ GetProperty prop cont → do
512+ map cont $ get (inSession : inElement : LP.Property prop : Nil)
513+ GetCss css cont → do
514+ res ← get (inSession : inElement : LP.CssValue css : Nil)
515+ map cont $ rethrowAsJsonDecodeError $ J.decodeJson res
516+ GetText cont → do
517+ res ← get (inSession : inElement : LP.Text : Nil)
518+ map cont $ rethrowAsJsonDecodeError $ J.decodeJson res
519+ GetTagName cont → do
520+ res ← get (inSession : inElement : LP.Name : Nil)
521+ map cont $ rethrowAsJsonDecodeError $ J.decodeJson res
522+ GetRectangle cont →
523+ map cont $ tryAndCache "get element rectangle"
524+ [ do
525+ res ← get (inSession : inElement : LP.Rect : Nil)
526+ rethrowAsJsonDecodeError $ LT.decodeRectangle res
527+ , do
528+ position ← get (inSession : inElement : LP.Position : Nil)
529+ size ← get (inSession : inElement : LP.Size : Nil)
530+ rethrowAsJsonDecodeError $ LT.decodeRectangleLegacy { position, size }
531+ ]
532+ IsEnabled cont → do
533+ res ← get (inSession : inElement : LP.Enabled : Nil)
534+ map cont $ rethrowAsJsonDecodeError $ J.decodeJson res
535+ ClickEl next → do
536+ _ ← tryAndCache "chromedriver75 update clickElement"
537+ [ post' (inSession : inElement : LP.Click : Nil)
538+ , post (inSession : inElement : LP.Click : Nil) $ LT.encodeElement el
539+ ]
540+ pure next
541+ ClearEl next → do
542+ _ ← tryAndCache "chromedriver75 update clearElement"
543+ [ post' (inSession : inElement : LP.Clear : Nil)
544+ , post (inSession : inElement : LP.Click : Nil) $ LT.encodeElement el
545+ ]
546+ pure next
547+ SendKeysEl txt next → do
548+ _ ← tryAndCache "send keys chromedriver hack"
549+ [ post (inSession : inElement : LP.Value : Nil) (LT.encodeSendKeysRequest txt)
550+ , post (inSession : inElement : LP.Value : Nil)
551+ $ J.encodeJson
552+ $ FO.singleton "value"
553+ $ Str.toCharArray txt
554+ ]
555+ pure next
556+ IsDisplayed cont → do
557+ res ← tryAndCache "is element displayed"
558+ [ get (inSession : inElement : LP.Displayed : Nil)
559+ , do
560+ let
561+ script =
562+ { script: """var el = arguments[0]; return el.offsetHeight > 0 && el.offsetWidth > 0"""
563+ , args: [ LT.encodeElement el ]
564+ }
565+ handleLunapark inp $ ExecuteScript script identity
566+ ]
567+ map cont $ rethrowAsJsonDecodeError $ J.decodeJson res
568+ Submit next → do
569+ _ ← tryAndCache "chromedriver75 update submit form"
570+ [ post' (inSession : inElement : LP.Submit : Nil)
571+ , post (inSession : inElement : LP.Submit : Nil) $ LT.encodeElement el
572+ ]
573+ pure next
532574
533575 where
534576 delete a = liftAndRethrow $ LP.delete inp.uri a
@@ -548,13 +590,15 @@ handleLunapark inp = case _ of
548590 Nothing →
549591 let
550592 go ix acc act =
551− let try' = do
552− a ← act
553− R.liftEffect $ Ref.modify_ (Map.insert key ix) inp.requestMapRef
554− pure a
555− in catch try' \_ → acc
593+ let
594+ try' = do
595+ a ← act
596+ R.liftEffect $ Ref.modify_ (Map.insert key ix) inp.requestMapRef
597+ pure a
598+ in
599+ catch try' \_ → acc
556600 in
557− FI.foldlWithIndex go (RE.throw $ LE.CachingError $ LE.EmptyCases key) actions
601+ FI.foldlWithIndex go (RE.throw $ LE.CachingError $ LE.EmptyCases key) actions
558602
559603 inSession ∷ LP.EndpointPart
560604 inSession = LP.InSession inp.session