mirror of
https://github.com/klntsky/purescript-playwright.git
synced 2024-11-22 22:45:34 +03:00
Fix: effectfulGetter (.apply instead of .call)
Add: goto, screenshot, textContent + tests
This commit is contained in:
parent
4feee12b76
commit
9bd082d42a
@ -5,8 +5,11 @@ module Playwright
|
|||||||
, version
|
, version
|
||||||
, close
|
, close
|
||||||
, newPage
|
, newPage
|
||||||
|
, goto
|
||||||
, query
|
, query
|
||||||
, queryMany
|
, queryMany
|
||||||
|
, screenshot
|
||||||
|
, textContent
|
||||||
, module Playwright.Data
|
, module Playwright.Data
|
||||||
, module Playwright.Options
|
, module Playwright.Options
|
||||||
)
|
)
|
||||||
@ -22,6 +25,7 @@ import Node.Buffer (Buffer)
|
|||||||
import Playwright.Data
|
import Playwright.Data
|
||||||
import Playwright.Options
|
import Playwright.Options
|
||||||
import Playwright.Internal (effProp)
|
import Playwright.Internal (effProp)
|
||||||
|
import Literals.Null
|
||||||
|
|
||||||
launch :: BrowserType -> Options Launch -> Aff Browser
|
launch :: BrowserType -> Options Launch -> Aff Browser
|
||||||
launch bt =
|
launch bt =
|
||||||
@ -51,6 +55,16 @@ newPage sth =
|
|||||||
effProp "newPage" (\_ -> newPage) sth >>>
|
effProp "newPage" (\_ -> newPage) sth >>>
|
||||||
toAffE
|
toAffE
|
||||||
|
|
||||||
|
goto
|
||||||
|
:: Page |+| Frame
|
||||||
|
-> URL
|
||||||
|
-> Options Goto
|
||||||
|
-> Aff (Null |+| Response)
|
||||||
|
goto sth url' =
|
||||||
|
options >>>
|
||||||
|
effProp "goto" (\_ -> goto) sth url' >>>
|
||||||
|
toAffE
|
||||||
|
|
||||||
-- | `sth.$(selector)`
|
-- | `sth.$(selector)`
|
||||||
query
|
query
|
||||||
:: ElementHandle |+| Page |+| Frame
|
:: ElementHandle |+| Page |+| Frame
|
||||||
@ -76,6 +90,14 @@ screenshot sth =
|
|||||||
effProp "screenshot" (\_ -> screenshot) sth >>>
|
effProp "screenshot" (\_ -> screenshot) sth >>>
|
||||||
toAffE
|
toAffE
|
||||||
|
|
||||||
|
textContent
|
||||||
|
:: Page |+| Frame |+| ElementHandle
|
||||||
|
-> Selector
|
||||||
|
-> Aff (Null |+| String)
|
||||||
|
textContent sth =
|
||||||
|
effProp "textContent" (\_ -> textContent) sth >>>
|
||||||
|
toAffE
|
||||||
|
|
||||||
url
|
url
|
||||||
:: Page |+| Frame |+| Download |+| Request |+| Response |+| Worker
|
:: Page |+| Frame |+| Download |+| Request |+| Response |+| Worker
|
||||||
-> Effect String
|
-> Effect String
|
||||||
|
@ -7,3 +7,7 @@ exports.jpg = "jpg";
|
|||||||
exports.chromium = P.chromium;
|
exports.chromium = P.chromium;
|
||||||
exports.firefox = P.firefox;
|
exports.firefox = P.firefox;
|
||||||
exports.webkit = P.webkit;
|
exports.webkit = P.webkit;
|
||||||
|
|
||||||
|
exports.domcontentloaded = "domcontentloaded";
|
||||||
|
exports.load = "load";
|
||||||
|
exports.networkidle = "networkidle";
|
||||||
|
@ -31,6 +31,16 @@ 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
|
||||||
|
derive newtype instance eqURL :: Eq URL
|
||||||
|
derive newtype instance showURL :: Show URL
|
||||||
|
derive newtype instance ordURL :: Ord URL
|
||||||
|
|
||||||
foreign import firefox :: BrowserType
|
foreign import firefox :: BrowserType
|
||||||
foreign import chromium :: BrowserType
|
foreign import chromium :: BrowserType
|
||||||
foreign import webkit :: BrowserType
|
foreign import webkit :: BrowserType
|
||||||
|
|
||||||
|
foreign import data WaitUntil :: Type
|
||||||
|
foreign import domcontentloaded :: WaitUntil
|
||||||
|
foreign import load :: WaitUntil
|
||||||
|
foreign import networkidle :: WaitUntil
|
||||||
|
@ -22,7 +22,7 @@ function effectfulGetter (property, n) {
|
|||||||
return function (object) {
|
return function (object) {
|
||||||
function runner (arg) {
|
function runner (arg) {
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
return object[property].call(object, args);
|
return object[property].apply(object, args);
|
||||||
} else {
|
} else {
|
||||||
args.push(arg);
|
args.push(arg);
|
||||||
n--;
|
n--;
|
||||||
|
@ -6,7 +6,6 @@ import Foreign.Object (Object)
|
|||||||
import Foreign (Foreign)
|
import Foreign (Foreign)
|
||||||
|
|
||||||
foreign import data Launch :: Type
|
foreign import data Launch :: Type
|
||||||
foreign import data Proxy :: Type
|
|
||||||
|
|
||||||
headless :: Option Launch Boolean
|
headless :: Option Launch Boolean
|
||||||
headless = opt "headless"
|
headless = opt "headless"
|
||||||
@ -53,6 +52,8 @@ devtools = opt "devtools"
|
|||||||
slowMo :: Option Launch Number
|
slowMo :: Option Launch Number
|
||||||
slowMo = opt "slowMo"
|
slowMo = opt "slowMo"
|
||||||
|
|
||||||
|
foreign import data Proxy :: Type
|
||||||
|
|
||||||
server :: Option Proxy String
|
server :: Option Proxy String
|
||||||
server = opt "server"
|
server = opt "server"
|
||||||
|
|
||||||
@ -83,3 +84,14 @@ omitBackground = opt "omitBackground"
|
|||||||
|
|
||||||
screenshotTimeout :: Option Screenshot Number
|
screenshotTimeout :: Option Screenshot Number
|
||||||
screenshotTimeout = opt "timeout"
|
screenshotTimeout = opt "timeout"
|
||||||
|
|
||||||
|
foreign import data Goto :: Type
|
||||||
|
|
||||||
|
gotoTimeout :: Option Goto Int
|
||||||
|
gotoTimeout = opt "timeout"
|
||||||
|
|
||||||
|
waitUntil :: Option Goto WaitUntil
|
||||||
|
waitUntil = opt "waitUntil"
|
||||||
|
|
||||||
|
referer :: Option Goto String
|
||||||
|
referer = opt "referer"
|
||||||
|
3
test/Main.js
Normal file
3
test/Main.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/* global exports __dirname */
|
||||||
|
|
||||||
|
exports.cwd = process.cwd();
|
@ -1,12 +1,18 @@
|
|||||||
module Test.Main where
|
module Test.Main where
|
||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
import Playwright (close, firefox, headless, launch, slowMo)
|
import Playwright
|
||||||
import Effect (Effect)
|
import Effect (Effect)
|
||||||
import Data.Options ((:=))
|
import Data.Options ((:=))
|
||||||
import Test.Unit (suite, test)
|
import Test.Unit (suite, test)
|
||||||
import Test.Unit.Main (runTest)
|
import Test.Unit.Main (runTest)
|
||||||
import Untagged.Union (asOneOf)
|
import Untagged.Union (asOneOf, fromOneOf)
|
||||||
|
import Test.Unit.Assert as Assert
|
||||||
|
import Data.Maybe (Maybe(..))
|
||||||
|
|
||||||
|
static :: String -> URL
|
||||||
|
static file =
|
||||||
|
URL $ "file://" <> cwd <> "/static/" <> file
|
||||||
|
|
||||||
main :: Effect Unit
|
main :: Effect Unit
|
||||||
main = runTest do
|
main = runTest do
|
||||||
@ -16,3 +22,15 @@ main = runTest do
|
|||||||
headless := false <>
|
headless := false <>
|
||||||
slowMo := 100.0
|
slowMo := 100.0
|
||||||
close $ asOneOf browser
|
close $ asOneOf browser
|
||||||
|
test "textContent" do
|
||||||
|
browser <- launch firefox mempty
|
||||||
|
page <- newPage (asOneOf browser) mempty
|
||||||
|
void $ goto
|
||||||
|
(asOneOf page)
|
||||||
|
(static "hello.html")
|
||||||
|
mempty
|
||||||
|
text <- textContent (asOneOf page) (Selector "body")
|
||||||
|
Assert.equal (Just "hello\n") (fromOneOf text)
|
||||||
|
close $ asOneOf browser
|
||||||
|
|
||||||
|
foreign import cwd :: String
|
||||||
|
1
test/static/hello.html
Normal file
1
test/static/hello.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
hello
|
Loading…
Reference in New Issue
Block a user