git.iko.soy/rowtype-yoga/purescript-playwright
on main help sign in
WIP
commit5ae5eb0dba00314fd70e6161e6d0ae49118286f2 authorVladimir Kalnitsky <klntsky@gmail.com> dateTue 3 Nov 2020, 00:07 (6 years ago) parentcbe9cc4
5 files changed+126−8
src/Playwright.purs+70−8 src/Playwright/Data.js+2 src/Playwright/Data.purs+6 src/Playwright/Options.purs+37 test/Main.purs+11
src/Playwright.purs+70−8
@@ -32,6 +32,11 @@ module Playwright
3232 , waitForRequest
3333 , waitForResponse
3434 , waitForSelector
35+ , waitForFunction
36+ , waitForLoadState
37+ , waitForTimeout
38+ , pdf
39+ , setInputFiles
3540 , module Playwright.Data
3641 , module Playwright.Options
3742 )
@@ -82,24 +87,21 @@ newPage
8287 => Coercible o NewpageOptions
8388 => x -> o -> Aff Page
8489newPage =
85− affCall "newPage" typeInfo
86− where typeInfo _ = newPage
90+ affCall "newPage" \_ -> newPage
8791
8892goForward
8993 :: forall o
9094 . Coercible o GoOptions
9195 => Page -> o -> Aff (Null |+| Response)
9296goForward =
93− affCall "goForward" typeInfo
94− where typeInfo _ = goForward
97+ affCall "goForward" \_ -> goForward
9598
9699goBack
97100 :: forall o
98101 . Coercible o GoOptions
99102 => Page -> o -> Aff (Null |+| Response)
100103goBack =
101− affCall "goBack" typeInfo
102− where typeInfo _ = goBack
104+ affCall "goBack" \_ -> goBack
103105
104106goto
105107 :: forall x o
@@ -107,8 +109,7 @@ goto
107109 => Coercible o GotoOptions
108110 => x -> URL -> o -> Aff (Null |+| Response)
109111goto =
110− affCall "goto" typeInfo
111− where typeInfo _ = goto
112+ affCall "goto" \_ -> goto
112113
113114type Cookie =
114115 { name :: String
@@ -304,3 +305,64 @@ waitForSelector
304305 -> o
305306 -> Aff (Null |+| ElementHandle)
306307waitForSelector = affCall "waitForSelector" \_ -> waitForSelector
308+
309+waitForFunction
310+ :: forall x o
311+ . Coercible x (Page |+| Frame)
312+ => Coercible o WaitForFunctionOptions
313+ => x
314+ -> String
315+ -- ^ Function to be evaluated in browser context
316+ -> EvaluationArgument
317+ -> o
318+ -> Aff JSHandle
319+waitForFunction = affCall "waitForFunction" \_ -> waitForFunction
320+
321+waitForLoadState
322+ :: forall x o
323+ . Coercible x (Page |+| Frame)
324+ => Coercible o WaitForLoadStateOptions
325+ => x
326+ -> WaitUntil
327+ -> o
328+ -> Aff Unit
329+waitForLoadState = affCall "waitForLoadState" \_ -> waitForLoadState
330+
331+waitForTimeout
332+ :: forall x
333+ . Coercible x (Page |+| Frame)
334+ => x
335+ -> Int
336+ -> Aff Unit
337+waitForTimeout = affCall "waitForTimeout" \_ -> waitForTimeout
338+
339+pdf
340+ :: forall o
341+ . Coercible o PdfOptions
342+ => Page
343+ -> o
344+ -> Aff Buffer
345+pdf = affCall "pdf" \_ -> pdf
346+
347+setInputFiles
348+ :: forall x o f
349+ . Coercible x (Page |+| Frame |+| ElementHandle)
350+ => Coercible o SetInputFilesOptions
351+ => Coercible f
352+ ( String
353+ |+| Array String
354+ |+| { name :: String
355+ , mimeType :: String
356+ , buffer :: Buffer
357+ }
358+ |+| Array { name :: String
359+ , mimeType :: String
360+ , buffer :: Buffer
361+ }
362+ )
363+ => x
364+ -> Selector
365+ -> f
366+ -> o
367+ -> Aff Unit
368+setInputFiles = affCall "setInputFiles" \_ -> setInputFiles
src/Playwright/Data.js+2
@@ -27,3 +27,5 @@ exports.attached = "attached";
2727exports.detached = "detached";
2828exports.visible = "visible";
2929exports.hidden = "hidden";
30+
31+exports.raf = "raf";
src/Playwright/Data.purs+6
@@ -2,6 +2,7 @@ module Playwright.Data where
22
33import Prelude
44import Untagged.TypeCheck (class HasRuntimeType)
5+import Foreign (Foreign)
56
67foreign import data BrowserType :: Type
78foreign import data Browser :: Type
@@ -63,3 +64,8 @@ foreign import attached :: ElementState
6364foreign import detached :: ElementState
6465foreign import visible :: ElementState
6566foreign import hidden :: ElementState
67+
68+foreign import data Raf :: Type
69+foreign import raf :: Raf
70+
71+type EvaluationArgument = Foreign
src/Playwright/Options.purs+37
@@ -133,3 +133,40 @@ type WaitForSelectorOptions =
133133 { state :: Opt ElementState
134134 , timeout :: Opt Int
135135 }
136+
137+type WaitForFunctionOptions =
138+ { polling :: Opt (Int |+| Raf)
139+ , timeout :: Opt Int
140+ }
141+
142+type WaitForLoadStateOptions =
143+ { timeout :: Opt Int
144+ }
145+
146+type Margin =
147+ { top :: Opt (String |+| Number)
148+ , right :: Opt (String |+| Number)
149+ , bottom :: Opt (String |+| Number)
150+ , left :: Opt (String |+| Number)
151+ }
152+
153+type PdfOptions =
154+ { path :: String
155+ , scale :: Opt Number
156+ , displayHeaderFooter :: Opt Boolean
157+ , headerTemplate :: Opt String
158+ , footerTemplate :: Opt String
159+ , printBackground :: Opt Boolean
160+ , landscape :: Opt Boolean
161+ , pageRanges :: Opt String
162+ , format :: Opt String
163+ , width :: Opt (String |+| Number)
164+ , height :: Opt (String |+| Number)
165+ , margin :: Opt Margin
166+ , preferCSSPageSize :: Opt Boolean
167+ }
168+
169+type SetInputFilesOptions =
170+ { noWaitAfter :: Opt Boolean
171+ , timeout :: Opt Int
172+ }
test/Main.purs+11
@@ -14,6 +14,7 @@ import Effect.Class (liftEffect)
1414import TestUtils
1515import Data.Either
1616import Control.Monad.Error.Class
17+import Foreign (unsafeToForeign)
1718
1819static :: String -> URL
1920static file =
@@ -71,3 +72,13 @@ main = runTest do
7172 res <- try $ waitForSelector page (Selector "nonexistent") { timeout: 100 }
7273 Assert.assert "waitForSelector fails when no element" $
7374 isLeft res
75+ test "waitForFunction" do
76+ withBrowserPage hello
77+ \page -> do
78+ void $ evaluate page
79+ "setTimeout(() => document.body.textContent += 'test', 200)"
80+ void $ waitForFunction
81+ page
82+ "x => document.body.textContent.includes(x)"
83+ (unsafeToForeign "test")
84+ { timeout: 3000 }