git.iko.soy/rowtype-yoga/purescript-lunapark
on main help sign in
...
commite93ce5b8a85a1dbdac5e46926b7e156a0346e09f authorMaxim Zimaliev <zimaliev@gmail.com> dateThu 19 Apr 2018, 00:05 (8 years ago) parentcb5ea72
2 files changed+25−11
src/Lunapark/.#Helpers.purs+1 src/Lunapark/API.purs+24−11
src/Lunapark/.#Helpers.pursnew file+1
@@ -0,0 +1 @@
1+User@DESKTOP-4VI4KLM.5216:1523467741
src/Lunapark/API.purs+24−11
@@ -122,7 +122,7 @@ data ElementF a
122122 | ClearEl a
123123 | SendKeys String a
124124 | ScreenshotEl String a
125− | IsVisible (Boolean → a)
125+ | IsDisplayed (Boolean → a)
126126 | Submit a
127127
128128derive instance functorLunaparkF ∷ Functor LunaparkF
@@ -289,8 +289,8 @@ clearElement el = liftLunapark $ OnElement el $ ClearEl unit
289289sendKeysElement ∷ ∀ e r. LT.Element → String → Lunapark e r Unit
290290sendKeysElement el txt = liftLunapark $ OnElement el $ SendKeys txt unit
291291
292−isVisible ∷ ∀ e r. LT.Element → Lunapark e r Boolean
293−isVisible el = liftLunapark $ OnElement el $ IsVisible id
292+isDisplayed ∷ ∀ e r. LT.Element → Lunapark e r Boolean
293+isDisplayed el = liftLunapark $ OnElement el $ IsDisplayed id
294294
295295submitElement ∷ ∀ e r. LT.Element → Lunapark e r Unit
296296submitElement el = liftLunapark $ OnElement el $ Submit unit
@@ -501,8 +501,6 @@ handleLunapark inp = case _ of
501501 map cont $ throwLeft $ J.decodeJson res
502502 GetProperty prop cont → do
503503 map cont $ get (inSession : inElement : LP.Property prop : Nil)
504−-- either RE.throw (pure <<< cont) res
505−-- map cont $ RE.rethrow res
506504 GetCss css cont → do
507505 res ← get (inSession : inElement : LP.CssValue css : Nil)
508506 map cont $ throwLeft $ J.decodeJson res
@@ -512,9 +510,16 @@ handleLunapark inp = case _ of
512510 GetTagName cont → do
513511 res ← get (inSession : inElement : LP.Name : Nil)
514512 map cont $ throwLeft $ J.decodeJson res
515− GetRectangle cont → do
516− res ← get (inSession : inElement : LP.Rect : Nil)
517− map cont $ throwLeft $ LT.decodeRectangle res
513+ GetRectangle cont →
514+ map cont $ withFallback "get element rectangle"
515+ { w3c: do
516+ res ← get (inSession : inElement : LP.Rect : Nil)
517+ throwLeft $ LT.decodeRectangle res
518+ , jsonWire: do
519+ position ← get (inSession : inElement : LP.Position : Nil)
520+ size ← get (inSession : inElement : LP.Size : Nil)
521+ throwLeft $ LT.decodeRectangleLegacy { position, size }
522+ }
518523 IsEnabled cont → do
519524 res ← get (inSession : inElement : LP.Enabled : Nil)
520525 map cont $ throwLeft $ J.decodeJson res
@@ -527,8 +532,16 @@ handleLunapark inp = case _ of
527532 SendKeys txt next → do
528533 _ ← post (inSession : inElement : LP.Value : Nil) (LT.encodeSendKeysRequest txt)
529534 pure next
530− IsVisible cont → do
531− res ← get (inSession : inElement : LP.Displayed : Nil)
535+ IsDisplayed cont → do
536+ res ← withFallback "is element displayed"
537+ { w3c: get (inSession : inElement : LP.Displayed : Nil)
538+ , jsonWire: do
539+ let script =
540+ { script: """var el = arguments[0]; return el.offsetHeight > 0 && el.offsetWidth > 0"""
541+ , args: [ LT.encodeElement el ]
542+ }
543+ handleLunapark inp $ ExecuteScript script id
544+ }
532545 map cont $ throwLeft $ J.decodeJson res
533546 Submit next → do
534547 _ ← post_ (inSession : inElement : LP.Submit : Nil)
@@ -544,7 +557,7 @@ handleLunapark inp = case _ of
544557 withFallback ∷ ∀ a. String → { w3c ∷ BaseRun r e a, jsonWire ∷ BaseRun r e a } → BaseRun r e a
545558 withFallback key { w3c: try, jsonWire: fallback } = do
546559 mp ← R.liftEff $ Ref.readRef inp.requestMapRef
547− case DT.spy $ Map.lookup key mp of
560+ case Map.lookup key mp of
548561 Just true → try
549562 Just false → fallback
550563 Nothing →