This commit is contained in:
fetsorn 2024-07-15 19:11:13 +00:00 committed by GitHub
commit 94d6ed4e79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 494 additions and 383 deletions

View File

@ -11,11 +11,20 @@ jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v4
- name: Run tests - uses: actions/setup-node@v4
run: | with:
PATH="$PATH:./node_modules/.bin/" node-version: 18
npm install - run: npm install
npm install spago@next purescript - run: npm install purescript
npx playwright install --with-deps chromium - run: npx playwright install --with-deps chromium
spago test - run: npx spago@next test
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- run: npm run check

View File

@ -10,7 +10,9 @@
"playwright": "^1.45.1" "playwright": "^1.45.1"
}, },
"scripts": { "scripts": {
"test": "pulp test" "test": "npx spago@next test",
"format": "npx prettier --write src/**/*.js test/**/*.js; npx purs-tidy format-in-place src/**/*.purs test/**/*.purs",
"check": "npx prettier --check src/**/*.js test/**/*.js; npx purs-tidy check src/**/*.purs test/**/*.purs"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View File

@ -1,21 +1,21 @@
/* global exports */ /* global exports */
export const exposeBinding_ = x => name => cb => opts => () => { export const exposeBinding_ = (x) => (name) => (cb) => (opts) => () => {
return x.exposeBinding( return x.exposeBinding(
name, name,
function (info, arg) { function (info, arg) {
return cb(info)(arg)() return cb(info)(arg)();
}, },
opts opts,
) );
} };
export const onResponse = function (page) { export const onResponse = function (page) {
return function (cb) { return function (cb) {
return function () { return function () {
page.on('response', function (response) { page.on("response", function (response) {
cb(response)(); cb(response)();
}); });
};
}; };
};
}; };

View File

@ -1,57 +1,55 @@
module Playwright module Playwright
( launch ( launch
, connect , connect
, connectOverCDP , connectOverCDP
, close , close
, contexts , contexts
, context , context
, isConnected , isConnected
, version , version
, newPage , newPage
, goForward , goForward
, goBack , goBack
, goto , goto
, addCookies , addCookies
, cookies , cookies
, hover , hover
, innerHTML , innerHTML
, innerText , innerText
, isClosed , isClosed
, keyboard , keyboard
, mainFrame , mainFrame
, name , name
, query , query
, queryMany , queryMany
, screenshot , screenshot
, textContent , textContent
, url , url
, addInitScript , addInitScript
, clearCookies , clearCookies
, click , click
, content , content
, dblclick , dblclick
, evaluate , evaluate
, evaluateHandle , evaluateHandle
, waitForNavigation , waitForNavigation
, waitForRequest , waitForRequest
, waitForResponse , waitForResponse
, waitForSelector , waitForSelector
, waitForFunction , waitForFunction
, waitForLoadState , waitForLoadState
, waitForTimeout , waitForTimeout
, pdf , pdf
, setInputFiles , setInputFiles
, setViewportSize , setViewportSize
, title , title
, exposeBinding , exposeBinding
, fill , fill
, focus , focus
, onResponse , onResponse
, connect , module Playwright.Data
, module Playwright.Data , module Playwright.Options
, module Playwright.Options ) where
)
where
import Playwright.Options import Playwright.Options
@ -60,34 +58,43 @@ import Data.String.Regex (Regex)
import Data.Unit (unit) import Data.Unit (unit)
import Effect (Effect) import Effect (Effect)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Foreign (Foreign, unsafeToForeign) import Foreign (Foreign)
import Literals.Null (Null) import Literals.Null (Null)
import Node.Buffer (Buffer) import Node.Buffer (Buffer)
import Playwright.Data (Browser, BrowserContext, BrowserType, ConsoleMessage, Dialog, Download, ElementHandle, ElementState, FileChooser, Frame, JSHandle, Keyboard, Modifier, Mouse, MouseButton, Page, Raf, Request, Response, Route, ScreenshotType, Selector(..), Selectors, URL(..), WaitUntil, Worker, alt, attached, chromium, control, detached, domcontentloaded, firefox, hidden, jpg, left, load, meta, middle, networkidle, png, raf, right, shift, visible, webkit) import Playwright.Data (Browser, BrowserContext, BrowserType, ConsoleMessage, Dialog, Download, ElementHandle, ElementState, FileChooser, Frame, JSHandle, Keyboard, Modifier, Mouse, MouseButton, Page, Raf, Request, Response, Route, ScreenshotType, Selector(..), Selectors, URL(..), WaitUntil, Worker, alt, attached, chromium, control, detached, domcontentloaded, firefox, hidden, jpg, left, load, meta, middle, networkidle, png, raf, right, shift, visible, webkit)
import Playwright.Internal (effCall, effProp, affCall) import Playwright.Internal (effCall, effProp, affCall)
import Prelude (Unit, ($)) import Prelude (Unit, ($))
import Untagged.Castable (class Castable) import Untagged.Castable (class Castable)
import Untagged.Union (type (|+|), UndefinedOr) import Untagged.Union (type (|+|))
import Playwright.Types (Cookie) import Playwright.Types (Cookie)
foreign import onResponse :: Page -> (Response -> Effect Unit) -> Effect Unit foreign import onResponse :: Page -> (Response -> Effect Unit) -> Effect Unit
fill fill
:: forall o :: forall o
. Castable o FillOptions . Castable o FillOptions
=> Page -> Selector -> String -> o -> Aff Unit => Page
-> Selector
-> String
-> o
-> Aff Unit
fill = affCall "fill" \_ -> fill fill = affCall "fill" \_ -> fill
focus focus
:: forall o :: forall o
. Castable o FocusOptions . Castable o FocusOptions
=> Page -> Selector -> o -> Aff Unit => Page
-> Selector
-> o
-> Aff Unit
focus = affCall "focus" \_ -> focus focus = affCall "focus" \_ -> focus
launch launch
:: forall o :: forall o
. Castable o LaunchOptions . Castable o LaunchOptions
=> BrowserType -> o -> Aff Browser => BrowserType
-> o
-> Aff Browser
launch = launch =
affCall "launch" \_ -> launch affCall "launch" \_ -> launch
@ -102,10 +109,6 @@ connect
-> Aff Browser -> Aff Browser
connect = affCall "connect" \_ -> connect connect = affCall "connect" \_ -> connect
type ConnectOptions =
{ timeout :: UndefinedOr Number
}
connectOverCDP connectOverCDP
:: forall o :: forall o
. Castable o ConnectOverCDPOptions . Castable o ConnectOverCDPOptions
@ -116,14 +119,11 @@ connectOverCDP
connectOverCDP = connectOverCDP =
affCall "connectOverCDP" \_ -> connectOverCDP affCall "connectOverCDP" \_ -> connectOverCDP
type ConnectOverCDPOptions =
{ timeout :: UndefinedOr Number
}
close close
:: forall x :: forall x
. Castable x (Browser |+| BrowserContext |+| Page) . Castable x (Browser |+| BrowserContext |+| Page)
=> x -> Aff Unit => x
-> Aff Unit
close = close =
affCall "close" \_ -> close affCall "close" \_ -> close
@ -141,31 +141,40 @@ version =
newPage newPage
:: forall x o :: forall x o
. Castable x (Browser |+| BrowserContext) . Castable x (Browser |+| BrowserContext)
=> Castable o NewpageOptions => Castable o NewpageOptions
=> x -> o -> Aff Page => x
-> o
-> Aff Page
newPage = newPage =
affCall "newPage" \_ -> newPage affCall "newPage" \_ -> newPage
goForward goForward
:: forall o :: forall o
. Castable o GoOptions . Castable o GoOptions
=> Page -> o -> Aff (Null |+| Response) => Page
-> o
-> Aff (Null |+| Response)
goForward = goForward =
affCall "goForward" \_ -> goForward affCall "goForward" \_ -> goForward
goBack goBack
:: forall o :: forall o
. Castable o GoOptions . Castable o GoOptions
=> Page -> o -> Aff (Null |+| Response) => Page
goBack = -> o
-> Aff (Null |+| Response)
goBack =
affCall "goBack" \_ -> goBack affCall "goBack" \_ -> goBack
goto goto
:: forall x o :: forall x o
. Castable x (Page |+| Frame) . Castable x (Page |+| Frame)
=> Castable o GotoOptions => Castable o GotoOptions
=> x -> URL -> o -> Aff (Null |+| Response) => x
-> URL
-> o
-> Aff (Null |+| Response)
goto = goto =
affCall "goto" \_ -> goto affCall "goto" \_ -> goto
@ -177,7 +186,7 @@ cookies
-> Aff (Array Cookie) -> Aff (Array Cookie)
cookies = cookies =
affCall "cookies" \_ -> cookies affCall "cookies" \_ -> cookies
addCookies addCookies
:: BrowserContext :: BrowserContext
-> Array Cookie -> Array Cookie
@ -187,29 +196,34 @@ addCookies =
hover hover
:: forall x o :: forall x o
. Castable x (Page |+| Frame |+| ElementHandle) . Castable x (Page |+| Frame |+| ElementHandle)
=> Castable o HoverOptions => Castable o HoverOptions
=> x -> o -> Aff Unit => x
-> o
-> Aff Unit
hover = hover =
affCall "hover" \_ -> hover affCall "hover" \_ -> hover
innerHTML innerHTML
:: forall x o :: forall x o
. Castable x (Page |+| Frame) . Castable x (Page |+| Frame)
=> Castable o InnerHTMLOptions => Castable o InnerHTMLOptions
=> x -> Selector -> o -> Aff String => x
-> Selector
-> o
-> Aff String
innerHTML = innerHTML =
affCall "innerHTML" \_ -> innerHTML affCall "innerHTML" \_ -> innerHTML
innerText innerText
:: forall x o :: forall x o
. Castable o InnerTextOptions . Castable o InnerTextOptions
=> Castable x (Page |+| Frame |+| ElementHandle) => Castable x (Page |+| Frame |+| ElementHandle)
=> x => x
-> Selector -> Selector
-> o -> o
-> Aff String -> Aff String
innerText = innerText =
affCall "innerText" \_ -> innerText affCall "innerText" \_ -> innerText
isClosed :: Page -> Effect Boolean isClosed :: Page -> Effect Boolean
@ -227,37 +241,45 @@ name = effCall "name" \_ -> name
-- | `sth.$(selector)` -- | `sth.$(selector)`
query query
:: forall x :: forall x
. Castable x (ElementHandle |+| Page |+| Frame) . Castable x (ElementHandle |+| Page |+| Frame)
=> x -> Selector -> Aff (Null |+| ElementHandle) => x
-> Selector
-> Aff (Null |+| ElementHandle)
query = query =
affCall "$" \_ -> query affCall "$" \_ -> query
-- | `sth.$$(selector)` -- | `sth.$$(selector)`
queryMany queryMany
:: forall x :: forall x
. Castable x (ElementHandle |+| Page |+| Frame) . Castable x (ElementHandle |+| Page |+| Frame)
=> x -> Selector -> Aff (Array ElementHandle) => x
-> Selector
-> Aff (Array ElementHandle)
queryMany = queryMany =
affCall "$$" \_ -> queryMany affCall "$$" \_ -> queryMany
screenshot screenshot
:: forall x o :: forall x o
. Castable x (ElementHandle |+| Page) . Castable x (ElementHandle |+| Page)
=> Castable o ScreenshotOptions => Castable o ScreenshotOptions
=> x -> o -> Aff Buffer => x
-> o
-> Aff Buffer
screenshot = screenshot =
affCall "screenshot" \_ -> screenshot affCall "screenshot" \_ -> screenshot
textContent textContent
:: forall x :: forall x
. Castable x (Page |+| Frame |+| ElementHandle) . Castable x (Page |+| Frame |+| ElementHandle)
=> x -> Selector -> Aff (Null |+| String) => x
-> Selector
-> Aff (Null |+| String)
textContent = textContent =
affCall "textContent" \_ -> textContent affCall "textContent" \_ -> textContent
url url
:: forall x :: forall x
. Castable x (Page |+| Frame |+| Download |+| Request |+| Response |+| Worker) . Castable x (Page |+| Frame |+| Download |+| Request |+| Response |+| Worker)
=> x => x
-> Effect URL -> Effect URL
url = url =
@ -265,7 +287,7 @@ url =
addInitScript addInitScript
:: forall x o :: forall x o
. Castable x (Page |+| BrowserContext) . Castable x (Page |+| BrowserContext)
=> Castable o AddInitScriptOptions => Castable o AddInitScriptOptions
=> x => x
-> o -> o
@ -279,7 +301,7 @@ clearCookies =
click click
:: forall x o :: forall x o
. Castable x (Page |+| Frame) . Castable x (Page |+| Frame)
=> Castable o ClickOptions => Castable o ClickOptions
=> x => x
-> Selector -> Selector
@ -290,7 +312,7 @@ click =
content content
:: forall x :: forall x
. Castable x (Page |+| Frame) . Castable x (Page |+| Frame)
=> x => x
-> Aff String -> Aff String
content = content =
@ -298,7 +320,7 @@ content =
dblclick dblclick
:: forall x o :: forall x o
. Castable x (Page |+| Frame |+| ElementHandle) . Castable x (Page |+| Frame |+| ElementHandle)
=> Castable o ClickOptions => Castable o ClickOptions
=> x => x
-> Selector -> Selector
@ -309,7 +331,7 @@ dblclick =
evaluate evaluate
:: forall x :: forall x
. Castable x (Page |+| Frame |+| Worker |+| JSHandle) . Castable x (Page |+| Frame |+| Worker |+| JSHandle)
=> x => x
-> String -> String
-- ^ Function to be evaluated in browser context -- ^ Function to be evaluated in browser context
@ -319,7 +341,7 @@ evaluate =
evaluateHandle evaluateHandle
:: forall x :: forall x
. Castable x (Page |+| Frame |+| Worker |+| JSHandle) . Castable x (Page |+| Frame |+| Worker |+| JSHandle)
=> x => x
-> String -> String
-- ^ Function to be evaluated in browser context -- ^ Function to be evaluated in browser context
@ -329,7 +351,7 @@ evaluateHandle =
waitForNavigation waitForNavigation
:: forall x o :: forall x o
. Castable x (Page |+| Frame) . Castable x (Page |+| Frame)
=> Castable o WaitForNavigationOptions => Castable o WaitForNavigationOptions
=> x => x
-> o -> o
@ -339,7 +361,7 @@ waitForNavigation =
waitForRequest waitForRequest
:: forall url o :: forall url o
. Castable url (URL |+| Regex |+| URL -> Boolean) . Castable url (URL |+| Regex |+| URL -> Boolean)
=> Castable o WaitForRequestOptions => Castable o WaitForRequestOptions
=> Page => Page
-> url -> url
@ -349,7 +371,7 @@ waitForRequest = affCall "waitForRequest" \_ -> waitForRequest
waitForResponse waitForResponse
:: forall url o :: forall url o
. Castable url (URL |+| Regex |+| URL -> Boolean) . Castable url (URL |+| Regex |+| URL -> Boolean)
=> Castable o WaitForResponseOptions => Castable o WaitForResponseOptions
=> Page => Page
-> url -> url
@ -359,7 +381,7 @@ waitForResponse = affCall "waitForResponse" \_ -> waitForResponse
waitForSelector waitForSelector
:: forall x o :: forall x o
. Castable x (Page |+| Frame |+| ElementHandle) . Castable x (Page |+| Frame |+| ElementHandle)
=> Castable o WaitForSelectorOptions => Castable o WaitForSelectorOptions
=> x => x
-> Selector -> Selector
@ -369,7 +391,7 @@ waitForSelector = affCall "waitForSelector" \_ -> waitForSelector
waitForFunction waitForFunction
:: forall x o :: forall x o
. Castable x (Page |+| Frame) . Castable x (Page |+| Frame)
=> Castable o WaitForFunctionOptions => Castable o WaitForFunctionOptions
=> x => x
-> String -> String
@ -378,11 +400,11 @@ waitForFunction
-> Aff JSHandle -> Aff JSHandle
waitForFunction x s o = waitForFunction' x s unit o waitForFunction x s o = waitForFunction' x s unit o
where where
waitForFunction' = affCall "waitForFunction" \_ -> waitForFunction' waitForFunction' = affCall "waitForFunction" \_ -> waitForFunction'
waitForLoadState waitForLoadState
:: forall x o :: forall x o
. Castable x (Page |+| Frame) . Castable x (Page |+| Frame)
=> Castable o WaitForLoadStateOptions => Castable o WaitForLoadStateOptions
=> x => x
-> WaitUntil -> WaitUntil
@ -392,7 +414,7 @@ waitForLoadState = affCall "waitForLoadState" \_ -> waitForLoadState
waitForTimeout waitForTimeout
:: forall x :: forall x
. Castable x (Page |+| Frame) . Castable x (Page |+| Frame)
=> x => x
-> Int -> Int
-> Aff Unit -> Aff Unit
@ -400,7 +422,7 @@ waitForTimeout = affCall "waitForTimeout" \_ -> waitForTimeout
pdf pdf
:: forall o :: forall o
. Castable o PdfOptions . Castable o PdfOptions
=> Page => Page
-> o -> o
-> Aff Buffer -> Aff Buffer
@ -408,20 +430,22 @@ pdf = affCall "pdf" \_ -> pdf
setInputFiles setInputFiles
:: forall x o f :: forall x o f
. Castable x (Page |+| Frame |+| ElementHandle) . Castable x (Page |+| Frame |+| ElementHandle)
=> Castable o SetFilesOptions => Castable o SetFilesOptions
=> Castable f => Castable f
( String ( String
|+| Array String |+| Array String
|+| { name :: String |+|
, mimeType :: String { name :: String
, buffer :: Buffer
}
|+| Array { name :: String
, mimeType :: String , mimeType :: String
, buffer :: Buffer , buffer :: Buffer
} }
) |+| Array
{ name :: String
, mimeType :: String
, buffer :: Buffer
}
)
=> x => x
-> Selector -> Selector
-> f -> f
@ -431,50 +455,46 @@ setInputFiles = affCall "setInputFiles" \_ -> setInputFiles
setViewportSize setViewportSize
:: Page :: Page
-> { width :: Number -> { width :: Number
, height :: Number , height :: Number
} }
-> Aff Unit -> Aff Unit
setViewportSize = affCall "setViewportSize" \_ -> setViewportSize setViewportSize = affCall "setViewportSize" \_ -> setViewportSize
title title
:: forall x :: forall x
. Castable x (Page |+| Frame) . Castable x (Page |+| Frame)
=> x => x
-> Aff String -> Aff String
title = affCall "title" \_ -> title title = affCall "title" \_ -> title
exposeBinding exposeBinding
:: forall x b :: forall x b
. Castable x (Page |+| BrowserContext) . Castable x (Page |+| BrowserContext)
=> x => x
-> String -> String
-- ^ Name of the function on the window object. -- ^ Name of the function on the window object.
-> -> ( { browserContext :: BrowserContext
( , page :: Page
{ browserContext :: BrowserContext , frame :: Frame
, page :: Page }
, frame :: Frame -> Foreign
} -> Aff b
-> Foreign )
-> Aff b
)
-> Aff Unit -> Aff Unit
exposeBinding x binding f = exposeBinding x binding f =
toAffE $ exposeBinding_ x binding (\d a -> fromAff $ f d a) { handle: false } toAffE $ exposeBinding_ x binding (\d a -> fromAff $ f d a) { handle: false }
foreign import exposeBinding_ foreign import exposeBinding_
:: forall x a b :: forall x a b
. x . x
-> String -> String
-> -> ( { browserContext :: BrowserContext
( , page :: Page
{ browserContext :: BrowserContext , frame :: Frame
, page :: Page }
, frame :: Frame -> a
} -> Effect (Promise b)
-> a )
-> Effect (Promise b)
)
-> { handle :: Boolean } -> { handle :: Boolean }
-> Effect (Promise Unit) -> Effect (Promise Unit)

View File

@ -15,9 +15,24 @@ type ConsoleMessageLocation =
} }
data ConsoleMessageType data ConsoleMessageType
= Log | Debug | Info | Error | Warning | Dir | Dirxml | Table | Trace | Clear = Log
| StartGroup | StartGroupCollapsed | EndGroup | Assert | Profile | ProfileEnd | Debug
| Count | TimeEnd | Info
| Error
| Warning
| Dir
| Dirxml
| Table
| Trace
| Clear
| StartGroup
| StartGroupCollapsed
| EndGroup
| Assert
| Profile
| ProfileEnd
| Count
| TimeEnd
derive instance genericConsoleMessageType :: Generic ConsoleMessageType _ derive instance genericConsoleMessageType :: Generic ConsoleMessageType _
derive instance eqConsoleMessageType :: Eq ConsoleMessageType derive instance eqConsoleMessageType :: Eq ConsoleMessageType
@ -37,25 +52,25 @@ text = effCall "text" \_ -> text
type' :: ConsoleMessage -> Effect ConsoleMessageType type' :: ConsoleMessage -> Effect ConsoleMessageType
type' = map convert <<< type'' type' = map convert <<< type''
where where
type'' :: ConsoleMessage -> Effect String type'' :: ConsoleMessage -> Effect String
type'' = effCall "type" \_ -> type'' type'' = effCall "type" \_ -> type''
convert = case _ of convert = case _ of
"log" -> Log "log" -> Log
"debug" -> Debug "debug" -> Debug
"info" -> Info "info" -> Info
"error" -> Error "error" -> Error
"warning" -> Warning "warning" -> Warning
"dir" -> Dir "dir" -> Dir
"dirxml" -> Dirxml "dirxml" -> Dirxml
"table" -> Table "table" -> Table
"trace" -> Trace "trace" -> Trace
"clear" -> Clear "clear" -> Clear
"startGroup" -> StartGroup "startGroup" -> StartGroup
"startGroupCollapsed" -> StartGroupCollapsed "startGroupCollapsed" -> StartGroupCollapsed
"endGroup" -> EndGroup "endGroup" -> EndGroup
"assert" -> Assert "assert" -> Assert
"profile" -> Profile "profile" -> Profile
"profileEnd" -> ProfileEnd "profileEnd" -> ProfileEnd
"count" -> Count "count" -> Count
"timeEnd" -> TimeEnd "timeEnd" -> TimeEnd
_ -> Log -- impossible _ -> Log -- impossible

View File

@ -1,5 +1,9 @@
/* global require exports */ /* global require exports */
import { chromium as pwChromium, firefox as pwFirefox, webkit as pwWebkit } from 'playwright'; import {
chromium as pwChromium,
firefox as pwFirefox,
webkit as pwWebkit,
} from "playwright";
export const png = "png"; export const png = "png";
export const jpg = "jpg"; export const jpg = "jpg";

View File

@ -1,8 +1,6 @@
module Playwright.Data where module Playwright.Data where
import Prelude import Prelude
import Untagged.TypeCheck (class HasRuntimeType)
import Foreign (Foreign)
foreign import data BrowserType :: Type foreign import data BrowserType :: Type
foreign import data Browser :: Type foreign import data Browser :: Type
@ -29,11 +27,13 @@ foreign import png :: ScreenshotType
foreign import jpg :: ScreenshotType foreign import jpg :: ScreenshotType
newtype Selector = Selector String newtype Selector = Selector String
derive newtype instance eqSelector :: Eq Selector derive newtype instance eqSelector :: Eq Selector
derive newtype instance showSelector :: Show Selector derive newtype instance showSelector :: Show Selector
derive newtype instance ordSelector :: Ord Selector derive newtype instance ordSelector :: Ord Selector
newtype URL = URL String newtype URL = URL String
derive newtype instance eqURL :: Eq URL derive newtype instance eqURL :: Eq URL
derive newtype instance showURL :: Show URL derive newtype instance showURL :: Show URL
derive newtype instance ordURL :: Ord URL derive newtype instance ordURL :: Ord URL

View File

@ -23,10 +23,10 @@ data DialogType = Alert | Beforeunload | Confirm | Prompt
type' :: Dialog -> Effect DialogType type' :: Dialog -> Effect DialogType
type' = map convert <<< type'' type' = map convert <<< type''
where where
type'' = effCall "type" \_ -> type'' type'' = effCall "type" \_ -> type''
convert = case _ of convert = case _ of
"alert" -> Alert "alert" -> Alert
"beforeunload" -> Beforeunload "beforeunload" -> Beforeunload
"confirm" -> Confirm "confirm" -> Confirm
"prompt" -> Prompt "prompt" -> Prompt
_ -> Alert -- impossible _ -> Alert -- impossible

View File

@ -1,10 +1,10 @@
/* global exports */ /* global exports */
export const createReadStream_ = Nothing => Just => Download => () => export const createReadStream_ = (Nothing) => (Just) => (Download) => () =>
Download.createReadStream().then(result => { Download.createReadStream().then((result) => {
if (result === null) { if (result === null) {
return Nothing return Nothing;
} else { } else {
return Just(result) return Just(result);
} }
}) });

View File

@ -1,13 +1,12 @@
module Playwright.Download module Playwright.Download
( createReadStream ( createReadStream
, suggestedFilename , suggestedFilename
, saveAs , saveAs
, path , path
, url , url
, failure , failure
, delete , delete
) ) where
where
import Control.Promise (Promise, toAffE) import Control.Promise (Promise, toAffE)
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))

View File

@ -2,6 +2,6 @@
export const onForeign = (obj) => (eventName) => (effCallback) => () => { export const onForeign = (obj) => (eventName) => (effCallback) => () => {
obj.on(eventName, (argument) => { obj.on(eventName, (argument) => {
effCallback(argument)() effCallback(argument)();
}) });
} };

View File

@ -1,5 +1,4 @@
module Playwright.Event module Playwright.Event where
where
import Type.Proxy (Proxy(..)) import Type.Proxy (Proxy(..))
import Effect (Effect) import Effect (Effect)
@ -8,122 +7,177 @@ import Playwright.Data (Browser, BrowserContext, ConsoleMessage)
import Playwright.Data as Data import Playwright.Data as Data
import Effect.Exception (Error) import Effect.Exception (Error)
class Event :: forall k. k -> Constraint
class Event e where class Event e where
getEventName :: Proxy e -> String getEventName :: Proxy e -> String
class OnEvent :: forall k1 k2 k3. k1 -> k2 -> k3 -> Constraint
class Event e <= OnEvent x e a | x e -> a class Event e <= OnEvent x e a | x e -> a
-- | Our own `Proxy` for event names. -- | Our own `Proxy` for event names.
data EventName :: forall k. k -> Type
data EventName a = EventName data EventName a = EventName
foreign import data Close :: Type foreign import data Close :: Type
instance eventClose :: Event Close where getEventName _ = "close"
instance eventClose :: Event Close where
getEventName _ = "close"
instance eventPageClose :: OnEvent Data.Page Close Unit instance eventPageClose :: OnEvent Data.Page Close Unit
instance eventBrowserContextClose :: OnEvent BrowserContext Close Unit instance eventBrowserContextClose :: OnEvent BrowserContext Close Unit
instance eventBrowserClose :: OnEvent Browser Close Unit instance eventBrowserClose :: OnEvent Browser Close Unit
instance eventWorkerClose :: OnEvent Worker Close Unit instance eventWorkerClose :: OnEvent Worker Close Unit
close :: EventName Close close :: EventName Close
close = EventName close = EventName
foreign import data Console :: Type foreign import data Console :: Type
instance eventConsole :: Event Console where getEventName _ = "console"
instance eventConsole :: Event Console where
getEventName _ = "console"
instance eventPageConsole :: OnEvent Data.Page Console ConsoleMessage instance eventPageConsole :: OnEvent Data.Page Console ConsoleMessage
console :: EventName Console console :: EventName Console
console = EventName console = EventName
foreign import data Crash :: Type foreign import data Crash :: Type
instance eventCrash :: Event Crash where getEventName _ = "crash"
instance eventCrash :: Event Crash where
getEventName _ = "crash"
instance eventPageCrash :: OnEvent Data.Page Crash Unit instance eventPageCrash :: OnEvent Data.Page Crash Unit
crash :: EventName Crash crash :: EventName Crash
crash = EventName crash = EventName
foreign import data Dialog :: Type foreign import data Dialog :: Type
instance eventDialog :: Event Dialog where getEventName _ = "dialog"
instance eventDialog :: Event Dialog where
getEventName _ = "dialog"
instance eventPageDialog :: OnEvent Data.Page Dialog Data.Dialog instance eventPageDialog :: OnEvent Data.Page Dialog Data.Dialog
dialog :: EventName Dialog dialog :: EventName Dialog
dialog = EventName dialog = EventName
foreign import data DomContentLoaded :: Type foreign import data DomContentLoaded :: Type
instance eventDomContentLoaded :: Event DomContentLoaded where instance eventDomContentLoaded :: Event DomContentLoaded where
getEventName _ = "domcontentloaded" getEventName _ = "domcontentloaded"
instance eventPageDomContentLoaded :: OnEvent Data.Page DomContentLoaded Unit instance eventPageDomContentLoaded :: OnEvent Data.Page DomContentLoaded Unit
domcontentloaded :: EventName DomContentLoaded domcontentloaded :: EventName DomContentLoaded
domcontentloaded = EventName domcontentloaded = EventName
foreign import data Download :: Type foreign import data Download :: Type
instance eventDownload :: Event Download where instance eventDownload :: Event Download where
getEventName _ = "download" getEventName _ = "download"
instance eventPageDownload :: OnEvent Data.Page Download Data.Download instance eventPageDownload :: OnEvent Data.Page Download Data.Download
download :: EventName Download download :: EventName Download
download = EventName download = EventName
foreign import data FileChooser :: Type foreign import data FileChooser :: Type
instance eventFileChooser :: Event FileChooser where instance eventFileChooser :: Event FileChooser where
getEventName _ = "filechooser" getEventName _ = "filechooser"
instance eventPageFileChooser :: OnEvent Data.Page FileChooser Data.FileChooser instance eventPageFileChooser :: OnEvent Data.Page FileChooser Data.FileChooser
filechooser :: EventName FileChooser filechooser :: EventName FileChooser
filechooser = EventName filechooser = EventName
foreign import data PageError :: Type foreign import data PageError :: Type
instance eventPageError :: Event PageError where getEventName _ = "pageerror"
instance eventPageError :: Event PageError where
getEventName _ = "pageerror"
instance eventPagePageError :: OnEvent Data.Page PageError Error instance eventPagePageError :: OnEvent Data.Page PageError Error
pageerror :: EventName PageError pageerror :: EventName PageError
pageerror = EventName pageerror = EventName
foreign import data Popup :: Type foreign import data Popup :: Type
instance eventPopup :: Event Popup where getEventName _ = "popup"
instance eventPopup :: Event Popup where
getEventName _ = "popup"
instance eventPagePopup :: OnEvent Data.Page Popup Page instance eventPagePopup :: OnEvent Data.Page Popup Page
popup :: EventName Popup popup :: EventName Popup
popup = EventName popup = EventName
foreign import data Request :: Type foreign import data Request :: Type
instance eventRequest :: Event Request where getEventName _ = "request"
instance eventRequest :: Event Request where
getEventName _ = "request"
instance eventPageRequest :: OnEvent Data.Page Request Data.Request instance eventPageRequest :: OnEvent Data.Page Request Data.Request
request :: EventName Request request :: EventName Request
request = EventName request = EventName
foreign import data RequestFailed :: Type foreign import data RequestFailed :: Type
instance eventRequestFailed :: Event RequestFailed where instance eventRequestFailed :: Event RequestFailed where
getEventName _ = "requestfailed" getEventName _ = "requestfailed"
instance eventPageRequestFailed :: OnEvent Data.Page RequestFailed Data.Request instance eventPageRequestFailed :: OnEvent Data.Page RequestFailed Data.Request
requestfailed :: EventName RequestFailed requestfailed :: EventName RequestFailed
requestfailed = EventName requestfailed = EventName
foreign import data RequestFinished :: Type foreign import data RequestFinished :: Type
instance eventRequestFinished :: Event RequestFinished where instance eventRequestFinished :: Event RequestFinished where
getEventName _ = "requestfinished" getEventName _ = "requestfinished"
instance eventPageRequestFinished :: OnEvent Data.Page RequestFinished Data.Request instance eventPageRequestFinished :: OnEvent Data.Page RequestFinished Data.Request
requestfinished :: EventName RequestFinished requestfinished :: EventName RequestFinished
requestfinished = EventName requestfinished = EventName
foreign import data Response :: Type foreign import data Response :: Type
instance eventResponse :: Event Response where instance eventResponse :: Event Response where
getEventName _ = "response" getEventName _ = "response"
instance eventPageResponse :: OnEvent Data.Page Response Data.Response instance eventPageResponse :: OnEvent Data.Page Response Data.Response
response :: EventName Response response :: EventName Response
response = EventName response = EventName
foreign import data Worker :: Type foreign import data Worker :: Type
instance eventWorker :: Event Worker where instance eventWorker :: Event Worker where
getEventName _ = "worker" getEventName _ = "worker"
instance eventPageWorker :: OnEvent Data.Page Worker Data.Worker instance eventPageWorker :: OnEvent Data.Page Worker Data.Worker
worker :: EventName Worker worker :: EventName Worker
worker = EventName worker = EventName
foreign import data Page :: Type foreign import data Page :: Type
instance eventPage :: Event Page where instance eventPage :: Event Page where
getEventName _ = "page" getEventName _ = "page"
instance eventPagePage :: OnEvent BrowserContext Page Data.Page instance eventPagePage :: OnEvent BrowserContext Page Data.Page
page :: EventName Page page :: EventName Page
page = EventName page = EventName
on on
:: forall x e a r :: forall x e a r
. OnEvent x e a . OnEvent x e a
=> EventName e => EventName e
-> x -> x
-> (a -> Effect r) -> (a -> Effect r)
-> Effect Unit -> Effect Unit
on event obj callback = onForeign obj (getEventName (Proxy :: Proxy e)) callback on _ obj callback = onForeign obj (getEventName (Proxy :: Proxy e)) callback
foreign import onForeign :: forall x a r. x -> String -> (a -> Effect r) -> Effect Unit foreign import onForeign :: forall x a r. x -> String -> (a -> Effect r) -> Effect Unit

View File

@ -21,19 +21,21 @@ page = effCall "page" \_ -> page
setFiles setFiles
:: forall o f :: forall o f
. Castable o SetFilesOptions . Castable o SetFilesOptions
=> Castable f => Castable f
( String ( String
|+| Array String |+| Array String
|+| { name :: String |+|
, mimeType :: String { name :: String
, buffer :: Buffer
}
|+| Array { name :: String
, mimeType :: String , mimeType :: String
, buffer :: Buffer , buffer :: Buffer
} }
) |+| Array
{ name :: String
, mimeType :: String
, buffer :: Buffer
}
)
=> FileChooser => FileChooser
-> f -> f
-> o -> o

View File

@ -18,34 +18,34 @@
* *
* effectfulGetter('close', 0, identity); * effectfulGetter('close', 0, identity);
*/ */
function effectfulGetter (property, argsCount, effectRunnerWrapper) { function effectfulGetter(property, argsCount, effectRunnerWrapper) {
function consume(arg, args, counter) { function consume(arg, args, counter) {
const argsNew = [ ...args, arg ]; const argsNew = [...args, arg];
if (counter === 0) { if (counter === 0) {
const [ object, ...rest ] = argsNew; const [object, ...rest] = argsNew;
return effectRunnerWrapper(() => object[property].apply(object, rest)) return effectRunnerWrapper(() => object[property].apply(object, rest));
} else { } else {
return (a) => consume(a, argsNew, counter - 1) return (a) => consume(a, argsNew, counter - 1);
}
} }
}
return (object) => consume(object, [], argsCount) return (object) => consume(object, [], argsCount);
} }
function identity (x) { function identity(x) {
return x; return x;
} }
export function unsafeEffCall(method) { export function unsafeEffCall(method) {
return argsCount => effectfulGetter(method, argsCount, identity); return (argsCount) => effectfulGetter(method, argsCount, identity);
} }
export function unsafeAffCall(toAffE) { export function unsafeAffCall(toAffE) {
return method => argsCount => effectfulGetter(method, argsCount, toAffE); return (method) => (argsCount) => effectfulGetter(method, argsCount, toAffE);
} }
export function effProp(prop) { export function effProp(prop) {
return object => () => object[prop]; return (object) => () => object[prop];
} }

View File

@ -1,18 +1,18 @@
module Playwright.Internal module Playwright.Internal
( class NumberOfArgs ( class NumberOfArgs
, numberOfArgs , numberOfArgs
, effCall , effCall
, effProp , effProp
, affCall , affCall
) ) where
where
import Type.Proxy import Type.Proxy (Proxy(..))
import Prelude import Prelude ((+), (-))
import Effect import Effect (Effect)
import Effect.Aff import Effect.Aff (Aff)
import Control.Promise import Control.Promise (Promise, toAffE)
class NumberOfArgs :: forall k. k -> Constraint
class NumberOfArgs x where class NumberOfArgs x where
numberOfArgs :: Proxy x -> Int numberOfArgs :: Proxy x -> Int
@ -25,18 +25,18 @@ else instance numberOfArgsFunction0 :: NumberOfArgs a where
countArgs :: forall a. NumberOfArgs a => (forall x. x -> a) -> Int countArgs :: forall a. NumberOfArgs a => (forall x. x -> a) -> Int
countArgs f = numberOfArgs (proxyOf f) - 2 countArgs f = numberOfArgs (proxyOf f) - 2
where where
proxyOf :: forall a. a -> Proxy a proxyOf :: forall b. b -> Proxy b
proxyOf _ = Proxy :: Proxy a proxyOf _ = Proxy :: Proxy b
foreign import unsafeEffCall foreign import unsafeEffCall
:: forall r :: forall r
. String . String
-> Int -> Int
-> r -> r
foreign import unsafeAffCall foreign import unsafeAffCall
:: forall r :: forall r
. (forall a. Effect (Promise a) -> Aff a) . (forall a. Effect (Promise a) -> Aff a)
-> String -> String
-> Int -> Int
-> r -> r

View File

@ -1,11 +1,12 @@
/* global exports */ /* global exports */
export function getProperties_(insert) { export function getProperties_(insert) {
return emptyMap => jsHandle => () => jsHandle.getProperties().then(props => { return (emptyMap) => (jsHandle) => () =>
jsHandle.getProperties().then((props) => {
let acc = emptyMap; let acc = emptyMap;
props.entries().forEach(pair => { props.entries().forEach((pair) => {
acc = insert(pair[0])(pair[1])(acc); acc = insert(pair[0])(pair[1])(acc);
}); });
return acc; return acc;
}); });
} }

View File

@ -1,12 +1,11 @@
module Playwright.Keyboard where module Playwright.Keyboard where
import Prelude import Prelude (Unit)
import Playwright.Internal (effCall, affCall) import Playwright.Internal (affCall)
import Playwright.Data (Keyboard) import Playwright.Data (Keyboard)
import Playwright.Options (KeyboardPressOptions) import Playwright.Options (KeyboardPressOptions)
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Control.Promise (toAffE) import Untagged.Castable (class Castable)
import Untagged.Castable (class Castable, cast)
type Key = String type Key = String
@ -20,15 +19,21 @@ insertText =
press press
:: forall o :: forall o
. Castable o KeyboardPressOptions . Castable o KeyboardPressOptions
=> Keyboard -> Key -> o -> Aff Unit => Keyboard
-> Key
-> o
-> Aff Unit
press = press =
affCall "press" \_ -> press affCall "press" \_ -> press
type' type'
:: forall o :: forall o
. Castable o KeyboardPressOptions . Castable o KeyboardPressOptions
=> Keyboard -> String -> o -> Aff Unit => Keyboard
-> String
-> o
-> Aff Unit
type' = type' =
affCall "type" \_ -> type' affCall "type" \_ -> type'

View File

@ -1,12 +1,11 @@
module Playwright.Mouse where module Playwright.Mouse where
import Effect.Aff import Effect.Aff (Aff)
import Playwright.Data import Playwright.Data (Mouse)
import Playwright.Internal import Playwright.Internal (affCall)
import Playwright.Options import Playwright.Options (MouseClickOptions, MouseDblClickOptions, MouseMoveOptions, MouseUpDownOptions)
import Prelude import Prelude (Unit)
import Untagged.Castable (class Castable) import Untagged.Castable (class Castable)
import Untagged.Union
click click
:: Mouse :: Mouse
@ -26,7 +25,7 @@ dblclick = affCall "dblclick" \_ -> dblclick
down down
:: forall o :: forall o
. Castable o MouseUpDownOptions . Castable o MouseUpDownOptions
=> Mouse => Mouse
-> o -> o
-> Aff Unit -> Aff Unit
@ -34,7 +33,7 @@ down = affCall "down" \_ -> down
move move
:: forall o :: forall o
. Castable o MouseMoveOptions . Castable o MouseMoveOptions
=> Mouse => Mouse
-> o -> o
-> Aff Unit -> Aff Unit
@ -42,7 +41,7 @@ move = affCall "move" \_ -> move
up up
:: forall o :: forall o
. Castable o MouseUpDownOptions . Castable o MouseUpDownOptions
=> Mouse => Mouse
-> o -> o
-> Aff Unit -> Aff Unit

View File

@ -3,7 +3,7 @@ module Playwright.Options where
import Playwright.Data import Playwright.Data
import Data.String.Regex (Regex) import Data.String.Regex (Regex)
import Data.Time.Duration (Milliseconds(..)) import Data.Time.Duration (Milliseconds)
import Foreign (Foreign) import Foreign (Foreign)
import Foreign.Object (Object) import Foreign.Object (Object)
import Literals.Null (Null) import Literals.Null (Null)
@ -25,22 +25,22 @@ type FillOptions =
} }
type LaunchOptions = type LaunchOptions =
{ headless :: Opt Boolean { headless :: Opt Boolean
, executablePath :: Opt String , executablePath :: Opt String
, args :: Opt String , args :: Opt String
, ignoreDefaultArgs :: Opt (Array String) , ignoreDefaultArgs :: Opt (Array String)
, proxy :: Opt ProxyOptions , proxy :: Opt ProxyOptions
, downloadsPath :: Opt String , downloadsPath :: Opt String
, chromiumSandbox :: Opt Boolean , chromiumSandbox :: Opt Boolean
, firefoxUserPrefs :: Opt Foreign , firefoxUserPrefs :: Opt Foreign
, handleSIGINT :: Opt Boolean , handleSIGINT :: Opt Boolean
, handleSIGTERM :: Opt Boolean , handleSIGTERM :: Opt Boolean
, handleSIGHUP :: Opt Boolean , handleSIGHUP :: Opt Boolean
, timeout :: Opt Milliseconds , timeout :: Opt Milliseconds
, env :: Opt (Object String) , env :: Opt (Object String)
, devtools :: Opt Boolean , devtools :: Opt Boolean
, slowMo :: Opt Number , slowMo :: Opt Number
, storageState :: Opt { cookies :: Array Cookie } , storageState :: Opt { cookies :: Array Cookie }
} }
type ConnectOptions = type ConnectOptions =
@ -49,43 +49,46 @@ type ConnectOptions =
, timeout :: Opt Number , timeout :: Opt Number
} }
type ConnectOverCDPOptions =
{ timeout :: UndefinedOr Number }
type ProxyOptions = type ProxyOptions =
{ server :: Opt String { server :: Opt String
, bypass :: Opt String , bypass :: Opt String
, username :: Opt String , username :: Opt String
, password :: Opt String , password :: Opt String
} }
type ScreenshotOptions = type ScreenshotOptions =
{ path :: Opt String { path :: Opt String
, "type" :: Opt ScreenshotType , "type" :: Opt ScreenshotType
, quality :: Opt Number , quality :: Opt Number
, omitBackground :: Opt Boolean , omitBackground :: Opt Boolean
, timeout :: Opt Milliseconds , timeout :: Opt Milliseconds
} }
type GotoOptions = type GotoOptions =
{ timeout :: Opt Milliseconds { timeout :: Opt Milliseconds
, waitUntil :: Opt WaitUntil , waitUntil :: Opt WaitUntil
, referer :: Opt String , referer :: Opt String
} }
type NewpageOptions = type NewpageOptions =
{ acceptDownloads :: Opt Boolean { acceptDownloads :: Opt Boolean
, ignoreHTTPSErrors :: Opt Boolean , ignoreHTTPSErrors :: Opt Boolean
, bypassCSP :: Opt Boolean , bypassCSP :: Opt Boolean
, viewport :: Opt (Null |+| { width :: Int, height :: Int }) , viewport :: Opt (Null |+| { width :: Int, height :: Int })
} }
type GoOptions = type GoOptions =
{ timeout :: Opt Milliseconds { timeout :: Opt Milliseconds
, waitUntil :: Opt WaitUntil , waitUntil :: Opt WaitUntil
} }
type HoverOptions = type HoverOptions =
{ position :: Opt Position { position :: Opt Position
, modifier :: Opt (Array Modifier) , modifier :: Opt (Array Modifier)
, force :: Opt Boolean , force :: Opt Boolean
} }
type InnerHTMLOptions = type InnerHTMLOptions =
@ -106,29 +109,29 @@ type AddInitScriptOptions =
type Position = { x :: Int, y :: Int } type Position = { x :: Int, y :: Int }
type ClickOptions = type ClickOptions =
{ button :: Opt MouseButton { button :: Opt MouseButton
, clickCount :: Opt Int , clickCount :: Opt Int
, delay :: Opt Int , delay :: Opt Int
, position :: Opt Position , position :: Opt Position
, modifiers :: Opt (Array Modifier) , modifiers :: Opt (Array Modifier)
, force :: Opt Boolean , force :: Opt Boolean
, noWaitAfter :: Opt Boolean , noWaitAfter :: Opt Boolean
, timeout :: Opt Milliseconds , timeout :: Opt Milliseconds
} }
type MouseClickOptions = type MouseClickOptions =
{ button :: Opt MouseButton { button :: Opt MouseButton
, clickCount :: Opt Int , clickCount :: Opt Int
, delay :: Opt Int , delay :: Opt Int
} }
type MouseDblClickOptions = type MouseDblClickOptions =
{ button :: Opt MouseButton { button :: Opt MouseButton
, delay :: Opt Int , delay :: Opt Int
} }
type MouseUpDownOptions = type MouseUpDownOptions =
{ button :: Opt MouseButton { button :: Opt MouseButton
, clickCount :: Opt Int , clickCount :: Opt Int
} }
@ -137,8 +140,8 @@ type MouseMoveOptions =
} }
type WaitForNavigationOptions = type WaitForNavigationOptions =
{ timeout :: Opt Milliseconds { timeout :: Opt Milliseconds
, url :: Opt (String |+| Regex |+| URL -> Boolean) , url :: Opt (String |+| Regex |+| URL -> Boolean)
, waitUntil :: Opt WaitUntil , waitUntil :: Opt WaitUntil
} }
@ -151,7 +154,7 @@ type WaitForResponseOptions =
} }
type WaitForSelectorOptions = type WaitForSelectorOptions =
{ state :: Opt ElementState { state :: Opt ElementState
, timeout :: Opt Milliseconds , timeout :: Opt Milliseconds
} }
@ -165,29 +168,29 @@ type WaitForLoadStateOptions =
} }
type Margin = type Margin =
{ top :: Opt (String |+| Number) { top :: Opt (String |+| Number)
, right :: Opt (String |+| Number) , right :: Opt (String |+| Number)
, bottom :: Opt (String |+| Number) , bottom :: Opt (String |+| Number)
, left :: Opt (String |+| Number) , left :: Opt (String |+| Number)
} }
type PdfOptions = type PdfOptions =
{ path :: String { path :: String
, scale :: Opt Number , scale :: Opt Number
, displayHeaderFooter :: Opt Boolean , displayHeaderFooter :: Opt Boolean
, headerTemplate :: Opt String , headerTemplate :: Opt String
, footerTemplate :: Opt String , footerTemplate :: Opt String
, printBackground :: Opt Boolean , printBackground :: Opt Boolean
, landscape :: Opt Boolean , landscape :: Opt Boolean
, pageRanges :: Opt String , pageRanges :: Opt String
, format :: Opt String , format :: Opt String
, width :: Opt (String |+| Number) , width :: Opt (String |+| Number)
, height :: Opt (String |+| Number) , height :: Opt (String |+| Number)
, margin :: Opt Margin , margin :: Opt Margin
, preferCSSPageSize :: Opt Boolean , preferCSSPageSize :: Opt Boolean
} }
type SetFilesOptions = type SetFilesOptions =
{ noWaitAfter :: Opt Boolean { noWaitAfter :: Opt Boolean
, timeout :: Opt Milliseconds , timeout :: Opt Milliseconds
} }

View File

@ -1,10 +1,10 @@
/* global exports */ /* global exports */
export const finished_ = Nothing => Just => Response => () => export const finished_ = (Nothing) => (Just) => (Response) => () =>
Response.finished().then((result) => { Response.finished().then((result) => {
if (result === null) { if (result === null) {
return Nothing return Nothing;
} else { } else {
return Just(result) return Just(result);
} }
}) });

View File

@ -1,17 +1,16 @@
module Playwright.Response module Playwright.Response
( body ( body
, finished , finished
, frame , frame
, headers , headers
, json , json
, ok , ok
, request , request
, status , status
, statusText , statusText
, text , text
, url , url
) ) where
where
import Control.Promise (Promise, toAffE) import Control.Promise (Promise, toAffE)
import Data.Argonaut.Core (Json) import Data.Argonaut.Core (Json)

View File

@ -13,14 +13,14 @@ import Foreign as Foreign
import Node.Encoding as Encoding import Node.Encoding as Encoding
import Node.FS.Aff as FS import Node.FS.Aff as FS
import Node.Stream as Stream import Node.Stream as Stream
import Playwright import Playwright (Selector(..), URL(..), chromium, click, close, dblclick, evaluate, exposeBinding, isClosed, launch, mainFrame, name, screenshot, textContent, url, version, waitForFunction, waitForSelector, waitForTimeout)
import Node.EventEmitter (on_) import Node.EventEmitter (on_)
import Playwright.ConsoleMessage as ConsoleMessage import Playwright.ConsoleMessage as ConsoleMessage
import Playwright.Dialog as Dialog import Playwright.Dialog as Dialog
import Playwright.Download as Download import Playwright.Download as Download
import Playwright.Event (on) import Playwright.Event (on)
import Playwright.Event as Event import Playwright.Event as Event
import Prelude import Prelude (Unit, bind, discard, pure, void, (#), ($), (/=), (<$>), (<<<), (<>), (=<<), (==))
import Test.Unit (suite, test) import Test.Unit (suite, test)
import Test.Unit.Assert as Assert import Test.Unit.Assert as Assert
import Test.Unit.Main (runTest) import Test.Unit.Main (runTest)
@ -34,8 +34,8 @@ static file =
main :: Effect Unit main :: Effect Unit
main = runTest do main = runTest do
let let
hello = static "hello.html" hello = static "hello.html"
index = static "index.html" index = static "index.html"
suite "browser" do suite "browser" do
test "launch, close" do test "launch, close" do
browser <- launch chromium {} browser <- launch chromium {}
@ -98,8 +98,7 @@ main = runTest do
ref <- liftEffect $ Ref.new Nothing ref <- liftEffect $ Ref.new Nothing
frgnRef <- liftEffect $ Ref.new Nothing frgnRef <- liftEffect $ Ref.new Nothing
exposeBinding page "hi_ffi" exposeBinding page "hi_ffi"
( ( \({ frame }) frgn -> do
\({frame}) frgn -> do
url <- liftEffect $ url frame url <- liftEffect $ url frame
liftEffect do liftEffect do
Console.log "hi" Console.log "hi"
@ -111,8 +110,9 @@ main = runTest do
mbUrl <- liftEffect $ Ref.read ref mbUrl <- liftEffect $ Ref.read ref
mbForeign <- liftEffect $ Ref.read frgnRef mbForeign <- liftEffect $ Ref.read frgnRef
Assert.equal (Just hello) mbUrl Assert.equal (Just hello) mbUrl
Assert.assert "exposeBinding is not able to accept an argument" $ Assert.assert "exposeBinding is not able to accept an argument"
pure (pure 12) == (runExcept <<< Foreign.readInt <$> mbForeign) $ pure (pure 12)
== (runExcept <<< Foreign.readInt <$> mbForeign)
suite "events" do suite "events" do
test "console" do test "console" do
withBrowserPage hello withBrowserPage hello

View File

@ -2,4 +2,4 @@
export const cwd = process.cwd(); export const cwd = process.cwd();
export const isNull = sth => sth === null; export const isNull = (sth) => sth === null;

View File

@ -1,12 +1,11 @@
module TestUtils module TestUtils
( assertForeignTrue ( assertForeignTrue
, withBrowser , withBrowser
, withBrowserPage , withBrowserPage
, testClickEvent , testClickEvent
, cwd , cwd
, isNull , isNull
) ) where
where
import Test.Unit.Assert as Assert import Test.Unit.Assert as Assert
import Foreign (Foreign, readBoolean) import Foreign (Foreign, readBoolean)
@ -26,8 +25,8 @@ assertForeignTrue value = do
withBrowser :: forall a. (Browser -> Aff a) -> Aff a withBrowser :: forall a. (Browser -> Aff a) -> Aff a
withBrowser = withResource acquire release withBrowser = withResource acquire release
where where
acquire = launch chromium {} acquire = launch chromium {}
release = close release = close
withBrowserPage :: forall a. URL -> (Page -> Aff a) -> Aff a withBrowserPage :: forall a. URL -> (Page -> Aff a) -> Aff a
withBrowserPage url action = do withBrowserPage url action = do