I am working on the selenium Haskell WebDriver package for testing, here .
I have this example:
import Test.WebDriver firefoxConfig :: WDConfig firefoxConfig = defaultConfig main :: IO () main = runSession firefoxConfig $ do openPage "http://google.com" searchInput <- findElem ( ByCSS "input[type='text']" ) sendKeys "Hello, World!" searchInput submit searchInput closeSession
getting started makes it clear that the selenium client needs the selenium server to communicate with
java -jar selenium-server-standalone-*.jar
Without launch, you will get the following:
ghci λ> main *** Exception: FailedConnectionException2 "127.0.0.1" 4444 False connect: does not exist (Connection refused)
I would like to complete the entire test script in a function that initializes the selenium server, writes its pid and kill (pid) after starting the session. That is, throughout my existing core, I would like to name java selenium-server in existence, but I would like it to cease to exist as soon as the call ends.
In python, I would do this using the definition of __enter__()
and __exit__()
with other dump files, subprocess.Popen
, write down the id, kill it, and then call
with Browser() as b: do_stuff
It seems to me that the essence of runSession is what I would need to replicate in order to wrap the launch and stall like this in the sense that it takes the firefoxConfig $ do
block as an argument, and I also want to do this.
However, I cannot fully understand the runSession polling types, how to do this:
ghci λ> :t runSession runSession :: Test.WebDriver.Config.WebDriverConfig conf => conf -> WD a -> IO a
I think I would be looking for some kind of Monad method that I could apply to this that applies to do
. I think the syntax will be kind ...
import Test.WebDriver import System.Process firefoxConfig :: WDConfig firefoxConfig = defaultConfig withBrowser :: Monad a -> Monad a -- maybe this type? withBrowser = do r <- createProcess (proc "java -jar selenium-server-standalone-*.jar" []) -- other magic here? main :: IO () main = withBrowser $ runSession firefoxConfig $ do openPage "http://google.com" searchInput <- findElem ( ByCSS "input[type='text']" ) sendKeys "Hello, World!" searchInput submit searchInput closeSession
How can i achieve this? Monad right? Is there a more or more Haskill idiom or strategy for this?