@@ -0,0 +1,88 @@
1+module Playwright
2+ ( Browser
3+ , Page
4+ , Locator
5+ , LaunchOptions
6+ , PageOptions
7+ , RoleOptions
8+ , ScreenshotOptions
9+ , ElementOperation(..)
10+ , launchChromium
11+ , close
12+ , newPage
13+ , goto
14+ , locator
15+ , getByRole
16+ , click
17+ , setChecked
18+ , selectOption
19+ , screenshot
20+ , waitForGlobalFunction
21+ , invokeGlobal
22+ , perform
23+ ) where
24+
25+import Prelude
26+
27+import Data.Nullable (Nullable)
28+import Effect (Effect)
29+import Foreign (Foreign, unsafeToForeign)
30+import Promise (Promise)
31+
32+type LaunchOptions =
33+ { executablePath :: Nullable String
34+ , args :: Array String
35+ }
36+
37+type PageOptions =
38+ { viewport :: { width :: Int, height :: Int }
39+ }
40+
41+type RoleOptions =
42+ { name :: String
43+ , exact :: Boolean
44+ }
45+
46+type ScreenshotOptions =
47+ { path :: String
48+ , fullPage :: Boolean
49+ }
50+
51+-- | Operations run synchronously, in order, in one locator evaluation.
52+-- | Native setters are resolved from the named browser-global constructor's
53+-- | prototype, bypassing instance overrides installed by UI frameworks.
54+data ElementOperation
55+ = SetNativeProperty String String Foreign
56+ | DispatchEvent String { bubbles :: Boolean }
57+
58+perform :: Locator -> Array ElementOperation -> Effect (Promise Unit)
59+perform target operations = performImpl target (map encode operations)
60+ where
61+ encode = case _ of
62+ SetNativeProperty prototypeName propertyName value -> unsafeToForeign
63+ { operation: "setNativeProperty", prototypeName, propertyName, value }
64+ DispatchEvent name options -> unsafeToForeign
65+ { operation: "dispatchEvent", name, options }
66+
67+foreign import data Browser :: Type
68+foreign import data Page :: Type
69+foreign import data Locator :: Type
70+
71+foreign import launchChromium :: LaunchOptions -> Effect (Promise Browser)
72+foreign import close :: Browser -> Effect (Promise Unit)
73+foreign import newPage :: Browser -> PageOptions -> Effect (Promise Page)
74+foreign import goto :: Page -> String -> Effect (Promise Unit)
75+foreign import locator :: Page -> String -> Locator
76+foreign import getByRole :: Page -> String -> RoleOptions -> Locator
77+foreign import click :: Locator -> Effect (Promise Unit)
78+foreign import setChecked :: Locator -> Boolean -> Effect (Promise Unit)
79+foreign import selectOption :: Locator -> String -> Effect (Promise Unit)
80+foreign import screenshot :: Page -> ScreenshotOptions -> Effect (Promise Unit)
81+foreign import waitForGlobalFunction :: Page -> String -> Effect (Promise Unit)
82+
83+-- | Apply a named window function, then each returned function, to successive
84+-- | argument lists. An empty list of arguments invokes a zero-argument thunk.
85+-- | The final promise is awaited; remote exceptions reject the operation.
86+foreign import invokeGlobal :: Page -> String -> Array (Array Foreign) -> Effect (Promise Unit)
87+
88+foreign import performImpl :: Locator -> Array Foreign -> Effect (Promise Unit)