mirror of
https://github.com/klntsky/purescript-playwright.git
synced 2024-11-22 13:23:01 +03:00
prettier, purs, explicit imports, format ci
This commit is contained in:
parent
6d0aba0f34
commit
eecec566f5
34
.github/workflows/ci.yml
vendored
34
.github/workflows/ci.yml
vendored
@ -11,11 +11,29 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Run tests
|
with:
|
||||||
run: |
|
ref: ${{ github.head_ref }}
|
||||||
PATH="$PATH:./node_modules/.bin/"
|
- uses: actions/setup-node@v3
|
||||||
npm install
|
with:
|
||||||
npm install spago@next purescript
|
node-version: "18.x"
|
||||||
npx playwright install --with-deps chromium
|
- run: npm install
|
||||||
spago test
|
- run: npm install purescript
|
||||||
|
- run: npx playwright install --with-deps chromium
|
||||||
|
- run: npx spago@next test
|
||||||
|
|
||||||
|
format:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
ref: ${{ github.head_ref }}
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: "18.x"
|
||||||
|
- run: npm run format
|
||||||
|
- name: Commit changes
|
||||||
|
uses: stefanzweifel/git-auto-commit-action@v4
|
||||||
|
with:
|
||||||
|
commit_message: Apply formatting changes
|
||||||
|
branch: ${{ github.head_ref }}
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
"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"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
/* 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)();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -47,11 +47,9 @@ module Playwright
|
|||||||
, 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,14 +58,14 @@ 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
|
||||||
@ -75,19 +73,28 @@ 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
|
||||||
|
|
||||||
@ -143,21 +143,27 @@ 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
|
||||||
|
-> o
|
||||||
|
-> Aff (Null |+| Response)
|
||||||
goBack =
|
goBack =
|
||||||
affCall "goBack" \_ -> goBack
|
affCall "goBack" \_ -> goBack
|
||||||
|
|
||||||
@ -165,7 +171,10 @@ 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
|
||||||
|
|
||||||
@ -189,7 +198,9 @@ 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
|
||||||
|
|
||||||
@ -197,7 +208,10 @@ 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
|
||||||
|
|
||||||
@ -228,7 +242,9 @@ name = effCall "name" \_ -> name
|
|||||||
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
|
||||||
|
|
||||||
@ -236,7 +252,9 @@ query =
|
|||||||
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
|
||||||
|
|
||||||
@ -244,14 +262,18 @@ 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
|
||||||
|
|
||||||
@ -413,11 +435,13 @@ setInputFiles
|
|||||||
=> Castable f
|
=> Castable f
|
||||||
( String
|
( String
|
||||||
|+| Array String
|
|+| Array String
|
||||||
|+| { name :: String
|
|+|
|
||||||
|
{ name :: String
|
||||||
, mimeType :: String
|
, mimeType :: String
|
||||||
, buffer :: Buffer
|
, buffer :: Buffer
|
||||||
}
|
}
|
||||||
|+| Array { name :: String
|
|+| Array
|
||||||
|
{ name :: String
|
||||||
, mimeType :: String
|
, mimeType :: String
|
||||||
, buffer :: Buffer
|
, buffer :: Buffer
|
||||||
}
|
}
|
||||||
@ -450,9 +474,7 @@ exposeBinding
|
|||||||
=> x
|
=> x
|
||||||
-> String
|
-> String
|
||||||
-- ^ Name of the function on the window object.
|
-- ^ Name of the function on the window object.
|
||||||
->
|
-> ( { browserContext :: BrowserContext
|
||||||
(
|
|
||||||
{ browserContext :: BrowserContext
|
|
||||||
, page :: Page
|
, page :: Page
|
||||||
, frame :: Frame
|
, frame :: Frame
|
||||||
}
|
}
|
||||||
@ -467,9 +489,7 @@ foreign import exposeBinding_
|
|||||||
:: forall x a b
|
:: forall x a b
|
||||||
. x
|
. x
|
||||||
-> String
|
-> String
|
||||||
->
|
-> ( { browserContext :: BrowserContext
|
||||||
(
|
|
||||||
{ browserContext :: BrowserContext
|
|
||||||
, page :: Page
|
, page :: Page
|
||||||
, frame :: Frame
|
, frame :: Frame
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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";
|
||||||
|
@ -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
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
@ -6,8 +6,7 @@ module Playwright.Download
|
|||||||
, 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(..))
|
||||||
|
@ -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)();
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
@ -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,112 +7,167 @@ 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
|
||||||
|
|
||||||
@ -124,6 +178,6 @@ on
|
|||||||
-> 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
|
||||||
|
@ -25,11 +25,13 @@ setFiles
|
|||||||
=> Castable f
|
=> Castable f
|
||||||
( String
|
( String
|
||||||
|+| Array String
|
|+| Array String
|
||||||
|+| { name :: String
|
|+|
|
||||||
|
{ name :: String
|
||||||
, mimeType :: String
|
, mimeType :: String
|
||||||
, buffer :: Buffer
|
, buffer :: Buffer
|
||||||
}
|
}
|
||||||
|+| Array { name :: String
|
|+| Array
|
||||||
|
{ name :: String
|
||||||
, mimeType :: String
|
, mimeType :: String
|
||||||
, buffer :: Buffer
|
, buffer :: Buffer
|
||||||
}
|
}
|
||||||
|
@ -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];
|
||||||
}
|
}
|
@ -4,15 +4,15 @@ module Playwright.Internal
|
|||||||
, 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,8 +25,8 @@ 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
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
/* 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;
|
||||||
|
@ -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
|
||||||
|
|
||||||
@ -21,14 +20,20 @@ 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'
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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)
|
||||||
@ -49,6 +49,9 @@ 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
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
@ -10,8 +10,7 @@ module Playwright.Response
|
|||||||
, 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)
|
||||||
|
@ -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)
|
||||||
@ -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
|
||||||
|
@ -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;
|
||||||
|
@ -5,8 +5,7 @@ module TestUtils
|
|||||||
, 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)
|
||||||
|
Loading…
Reference in New Issue
Block a user