diff --git a/src/Playwright.purs b/src/Playwright.purs index 86d8c5b..1572e78 100644 --- a/src/Playwright.purs +++ b/src/Playwright.purs @@ -5,8 +5,11 @@ module Playwright , version , close , newPage + , goto , query , queryMany + , screenshot + , textContent , module Playwright.Data , module Playwright.Options ) @@ -22,6 +25,7 @@ import Node.Buffer (Buffer) import Playwright.Data import Playwright.Options import Playwright.Internal (effProp) +import Literals.Null launch :: BrowserType -> Options Launch -> Aff Browser launch bt = @@ -51,6 +55,16 @@ newPage sth = effProp "newPage" (\_ -> newPage) sth >>> toAffE +goto + :: Page |+| Frame + -> URL + -> Options Goto + -> Aff (Null |+| Response) +goto sth url' = + options >>> + effProp "goto" (\_ -> goto) sth url' >>> + toAffE + -- | `sth.$(selector)` query :: ElementHandle |+| Page |+| Frame @@ -76,6 +90,14 @@ screenshot sth = effProp "screenshot" (\_ -> screenshot) sth >>> toAffE +textContent + :: Page |+| Frame |+| ElementHandle + -> Selector + -> Aff (Null |+| String) +textContent sth = + effProp "textContent" (\_ -> textContent) sth >>> + toAffE + url :: Page |+| Frame |+| Download |+| Request |+| Response |+| Worker -> Effect String diff --git a/src/Playwright/Data.js b/src/Playwright/Data.js index 0eff87c..156fa8b 100644 --- a/src/Playwright/Data.js +++ b/src/Playwright/Data.js @@ -7,3 +7,7 @@ exports.jpg = "jpg"; exports.chromium = P.chromium; exports.firefox = P.firefox; exports.webkit = P.webkit; + +exports.domcontentloaded = "domcontentloaded"; +exports.load = "load"; +exports.networkidle = "networkidle"; diff --git a/src/Playwright/Data.purs b/src/Playwright/Data.purs index d074647..d623e5a 100644 --- a/src/Playwright/Data.purs +++ b/src/Playwright/Data.purs @@ -31,6 +31,16 @@ derive newtype instance eqSelector :: Eq Selector derive newtype instance showSelector :: Show 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 chromium :: BrowserType foreign import webkit :: BrowserType + +foreign import data WaitUntil :: Type +foreign import domcontentloaded :: WaitUntil +foreign import load :: WaitUntil +foreign import networkidle :: WaitUntil diff --git a/src/Playwright/Internal.js b/src/Playwright/Internal.js index 75cc453..68d52cc 100644 --- a/src/Playwright/Internal.js +++ b/src/Playwright/Internal.js @@ -22,7 +22,7 @@ function effectfulGetter (property, n) { return function (object) { function runner (arg) { if (n == 0) { - return object[property].call(object, args); + return object[property].apply(object, args); } else { args.push(arg); n--; diff --git a/src/Playwright/Options.purs b/src/Playwright/Options.purs index 16b0609..ce50c7f 100644 --- a/src/Playwright/Options.purs +++ b/src/Playwright/Options.purs @@ -6,7 +6,6 @@ import Foreign.Object (Object) import Foreign (Foreign) foreign import data Launch :: Type -foreign import data Proxy :: Type headless :: Option Launch Boolean headless = opt "headless" @@ -53,6 +52,8 @@ devtools = opt "devtools" slowMo :: Option Launch Number slowMo = opt "slowMo" +foreign import data Proxy :: Type + server :: Option Proxy String server = opt "server" @@ -83,3 +84,14 @@ omitBackground = opt "omitBackground" screenshotTimeout :: Option Screenshot Number 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" diff --git a/test/Main.js b/test/Main.js new file mode 100644 index 0000000..58d7cad --- /dev/null +++ b/test/Main.js @@ -0,0 +1,3 @@ +/* global exports __dirname */ + +exports.cwd = process.cwd(); diff --git a/test/Main.purs b/test/Main.purs index f0267de..2810d75 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -1,12 +1,18 @@ module Test.Main where import Prelude -import Playwright (close, firefox, headless, launch, slowMo) +import Playwright import Effect (Effect) import Data.Options ((:=)) import Test.Unit (suite, test) 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 = runTest do @@ -16,3 +22,15 @@ main = runTest do headless := false <> slowMo := 100.0 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 diff --git a/test/static/hello.html b/test/static/hello.html new file mode 100644 index 0000000..ce01362 --- /dev/null +++ b/test/static/hello.html @@ -0,0 +1 @@ +hello