git.iko.soy/rowtype-yoga/purescript-playwright
on main help sign in
Merge effectfulGetter and affectfulGetter into one + More bindings
commitcbe9cc4033313a14e77e3e148364e9b49f428746 authorVladimir Kalnitsky <klntsky@gmail.com> dateMon 2 Nov 2020, 19:38 (6 years ago) parent7bcc58a
6 files changed+78−25
src/Playwright.purs+35−2 src/Playwright/Data.js+5 src/Playwright/Data.purs+6 src/Playwright/Internal.js+10−23 src/Playwright/Options.purs+13 test/Main.purs+9
src/Playwright.purs+35−2
@@ -26,9 +26,12 @@ module Playwright
2626 , click
2727 , content
2828 , dblclick
29− , waitForNavigation
30− , evaluateHandle
3129 , evaluate
30+ , evaluateHandle
31+ , waitForNavigation
32+ , waitForRequest
33+ , waitForResponse
34+ , waitForSelector
3235 , module Playwright.Data
3336 , module Playwright.Options
3437 )
@@ -271,3 +274,33 @@ waitForNavigation
271274 -> Aff (Null |+| Response)
272275waitForNavigation =
273276 affCall "waitForNavigation" \_ -> waitForNavigation
277+
278+waitForRequest
279+ :: forall url o
280+ . Coercible url (URL |+| Regex |+| URL -> Boolean)
281+ => Coercible o WaitForRequestOptions
282+ => Page
283+ -> url
284+ -> o
285+ -> Aff Request
286+waitForRequest = affCall "waitForRequest" \_ -> waitForRequest
287+
288+waitForResponse
289+ :: forall url o
290+ . Coercible url (URL |+| Regex |+| URL -> Boolean)
291+ => Coercible o WaitForResponseOptions
292+ => Page
293+ -> url
294+ -> o
295+ -> Aff Response
296+waitForResponse = affCall "waitForResponse" \_ -> waitForResponse
297+
298+waitForSelector
299+ :: forall x o
300+ . Coercible x (Page |+| Frame |+| ElementHandle)
301+ => Coercible o WaitForSelectorOptions
302+ => x
303+ -> Selector
304+ -> o
305+ -> Aff (Null |+| ElementHandle)
306+waitForSelector = affCall "waitForSelector" \_ -> waitForSelector
src/Playwright/Data.js+5
@@ -22,3 +22,8 @@ exports.null = null;
2222exports.left = "left";
2323exports.right = "right";
2424exports.middle = "middle";
25+
26+exports.attached = "attached";
27+exports.detached = "detached";
28+exports.visible = "visible";
29+exports.hidden = "hidden";
src/Playwright/Data.purs+6
@@ -57,3 +57,9 @@ foreign import data MouseButton :: Type
5757foreign import left :: MouseButton
5858foreign import right :: MouseButton
5959foreign import middle :: MouseButton
60+
61+foreign import data ElementState :: Type
62+foreign import attached :: ElementState
63+foreign import detached :: ElementState
64+foreign import visible :: ElementState
65+foreign import hidden :: ElementState
src/Playwright/Internal.js+10−23
@@ -3,6 +3,8 @@
33/**
44 * @param {string} property - method to call on object
55 * @param {number} n - number of (curried) arguments
6+ * @param {effectRunnerWrapper} effectRunnerWrapper - a function to overrride
7+ * effect runner with. `toAffE` for `Aff`, `identity` for `Effect`.
68 *
79 * E.g. these are equivalent:
810 *
@@ -14,34 +16,16 @@
1416 *
1517 * and
1618 *
17− * effectfulGetter('close', 0);
19+ * effectfulGetter('close', 0, identity);
1820 */
19−function effectfulGetter (property, n) {
20− var args = [];
21−
22− return function (object) {
23− function runner (arg) {
24− if (n == 0) {
25− return object[property].apply(object, args);
26− } else {
27− args.push(arg);
28− n--;
29− return runner;
30− }
31− }
32−
33− return runner;
34− };
35−}
36−
37−function affectfulGetter (property, argsCount, toAffE) {
21+function effectfulGetter (property, argsCount, effectRunnerWrapper) {
3822 var args = [];
3923 return function (object) {
4024 function effectRunner () {
4125 return object[property].apply(object, args);
4226 }
4327
44− var affectRunner = toAffE(effectRunner);
28+ var affectRunner = effectRunnerWrapper(effectRunner);
4529
4630 function chooseNext () {
4731 return argsCount > 0 ? argsConsumer : affectRunner;
@@ -61,17 +45,20 @@ function affectfulGetter (property, argsCount, toAffE) {
6145 };
6246}
6347
48+function identity (x) {
49+ return x;
50+}
6451
6552exports.unsafeEffCall = function (method) {
6653 return function (argsCount) {
67− return effectfulGetter(method, argsCount);
54+ return effectfulGetter(method, argsCount, identity);
6855 };
6956};
7057
7158exports.unsafeAffCall = function (toAffE) {
7259 return function (method) {
7360 return function (argsCount) {
74− return affectfulGetter(method, argsCount, toAffE);
61+ return effectfulGetter(method, argsCount, toAffE);
7562 };
7663 };
7764};
src/Playwright/Options.purs+13
@@ -120,3 +120,16 @@ type WaitForNavigationOptions =
120120 , url :: Opt (String |+| Regex |+| URL -> Boolean)
121121 , waitUntil :: Opt WaitUntil
122122 }
123+
124+type WaitForRequestOptions =
125+ { timeout :: Opt Int
126+ }
127+
128+type WaitForResponseOptions =
129+ { timeout :: Opt Int
130+ }
131+
132+type WaitForSelectorOptions =
133+ { state :: Opt ElementState
134+ , timeout :: Opt Int
135+ }
test/Main.purs+9
@@ -12,6 +12,8 @@ import Node.FS.Aff as FS
1212import Effect.Aff (Aff)
1313import Effect.Class (liftEffect)
1414import TestUtils
15+import Data.Either
16+import Control.Monad.Error.Class
1517
1618static :: String -> URL
1719static file =
@@ -62,3 +64,10 @@ main = runTest do
6264 withBrowserPage index $ testClickEvent "click" click
6365 test "dblclick" do
6466 withBrowserPage index $ testClickEvent "dblclick" dblclick
67+ test "waitForSelector" do
68+ withBrowserPage hello
69+ \page -> do
70+ void $ waitForSelector page (Selector "body") {}
71+ res <- try $ waitForSelector page (Selector "nonexistent") { timeout: 100 }
72+ Assert.assert "waitForSelector fails when no element" $
73+ isLeft res