私は初心者ですので、私にご負担ください。WebDriverとScottyのモナドを組み合わせる方法
私は次のコードを持っている:私もそれらの満たされた部分が正しいかどうかわからないのです
{-# LANGUAGE OverloadedStrings #-}
module Lib where
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Data.Monoid ((<>))
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import Test.WebDriver
--import Web.Scotty
import Web.Scotty.Trans
firefoxConfig :: WDConfig
firefoxConfig = defaultConfig
startMyBrowser :: WD a -> IO a
startMyBrowser = runSession firefoxConfig
stopMyBrowser = closeSession
someFunc :: WD String
someFunc = do
openPage "http://maslo.cz"
captionElem <- findElem (ByCSS "h2")
text <- getText captionElem
return $ T.unpack text
helloAction :: ActionT TL.Text WD()
helloAction = do
a <- lift someFunc
text $ "got this for you: " <> TL.pack a
routes :: ScottyT TL.Text WD()
routes = get "/hello" helloAction
startServer = startMyBrowser $ do
lift $ scottyT 3000 _ routes
stopMyBrowser
を - ウェブサーバ(scottyT
一部をスピンアップ、セレンセッション(startMyBrowser
)を開始することになっています)、Webサーバーが停止したら、Seleniumセッション(stopMyBrowser
)を終了する必要があります。
タイプで手を加えた後、私は上記のコードに到達しました。そして、私は1つだけ欠けているようです - 穴。
解決策を説明したり、さらに多くの資料へのリンクを追加したりしてください。私はそれらの変圧器を理解するのが大好きです。
編集1:ここでは はエラーは以下のとおりです。redditのanswered it上
• Couldn't match type ‘t0 m0’ with ‘WD’
Expected type: WD()
Actual type: t0 m0()
• In a stmt of a 'do' block: lift $ scottyT 3000 _ routes
In the second argument of ‘($)’, namely
‘do { lift $ scottyT 3000 _ routes;
stopMyBrowser }’
In the expression:
startMyBrowser
$ do { lift $ scottyT 3000 _ routes;
stopMyBrowser }
• Found hole:
_ :: WD wai-3.2.1.1:Network.Wai.Internal.Response
-> IO wai-3.2.1.1:Network.Wai.Internal.Response
• In the second argument of ‘scottyT’, namely ‘_’
In the second argument of ‘($)’, namely ‘scottyT 3000 _ routes’
In a stmt of a 'do' block: lift $ scottyT 3000 _ routes
• Relevant bindings include
startServer :: IO() (bound at src/Lib.hs:37:1)