I want to test with selenium webdriver on yesod

Asked 2 years ago, Updated 2 years ago, 95 views

I would like to test with selenium webdriver on yesod.

The following tests worked.

it "webdriver load check" $do
    title<-liftIO$runSession(def::WDConfig)$do
        openPage "https://google.co.jp"
        getTitle
    assertEq "title" "Google" title

After that, I wrote a test to access localhost:3000, but I couldn't connect because there was no such server.

I set the approot to localhost:3000

I wanted to know the URL being tested, so I tried putStrLn using getUrlRender, but I gave up because the type didn't make sense.

Comments will exceed the number of characters, so I will add them here.

The test cases that fail are added below.

Home.hs is

getHomeR::Handler Html
getHomeR=do
    defaultLayout$do
        setTitle "HOME"
        $(widgetFile "home")

HomeSpec.hs is

spec::Spec
spec=withApp$do
    it "webdriver load check" $do
        title<-liftIO$runSession(def::WDConfig)$do
            openPage$"http://localhost:3000"
            t<-getTitle
            closeSession
            return
        assertEq "title" "HOME" title

The browser actually starts, but I get an error saying I can't connect to the server.

The error is as follows.

test/Handler/HomeSpec.hs:8: 
1) Handler.Home webdriver load check
     uncaught exception —FailedCommand UnknownError 
     SessionId: "18939a04-1e84-4f18-8eea-46418d5d4f60" at "127.0.0.1":4444
     org.openqa.selenium.WebDriverException: Reached error page: about:neterror?e=connectionFailure&u=http%3A//localhost%3A3000/&c=UTF-8&f=regular&d=localhost%3A3000%20%E3%81%AE%E3%82%B5%E3%83%BC%E3%83%90%E3%83%BC%E3%81%B8%E3%81%AE%E6%8E%A5%E7%B6%9A%E3%82%92%E7%A2%BA%E7%AB%8B%E3%81%A7%E3%81%8D%E3%81%BE%E3%81%9B%E3%82%93%E3%81%A7%E3%81%97%E3%81%9F%E3%80%82
     Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
     System info: host: 'Unknown', ip: 'Unknown', os.name: 'Linux', os.arch: 'amd64', os.version: '4.9.16-gentoo', java.version: '1.8.0_131'
     Driver info: org.openqa.selenium.firefox.FirefoxDriver
     Capabilities [{moz:profile=/tmp/rust_mozprofile.DDlePRCG2AFm, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, platform=ANY, proxy=Proxy(system), specificationLevel=0.0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=54.0, platformVersion=4.9.16-gentoo, moz:processID=19730.0, browserName=firefox, javascriptEnabled=true, platformName=linux}]
     Session ID: 2930f19c-906e-4841-9f1c-ce7e11cfa73a
       sun.reflect.NativeConstructorAccessorImpl.newInstance0 (NativeConstructorAccessorImpl.java:-2)
       sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
       sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
       java.lang.reflect.Constructor.newInstance(Constructor.java:423)
       org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException (W3CHttpResponseCodec.java:150)
       org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode (W3CHttpResponseCodec.java:115)
       org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode (W3CHttpResponseCodec.java:45)
       org.openqa.selenium.remote.HttpCommandExecutor.execute (HttpCommandExecutor.java:164)
       org.openqa.selenium.remote.service.DriverCommandExecutor.execute (DriverCommandExecutor.java:82)
       org.openqa.selenium.remote.RemoteWebDriver.execute (RemoteWebDriver.java:637)
       org.openqa.selenium.remote.RemoteWebDriver.get (RemoteWebDriver.java:364 )
       sun.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethodAccessorImpl.java:-2)
       sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
       sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
       java.lang.reflect.Method.invoke (Method.java:498)
       org.openqa.selenium.support.events.EventFiringWebDriver $2.invoke (EventFiringWebDriver.java:104)
       com.sun.proxy.$Proxy4.get(:-1)
       org.openqa.selenium.support.events.EventFiringWebDriver.get (EventFiringWebDriver.java:163)
       org.openqa.selenium.remote.server.handler.ChangeUrl.call (ChangeUrl.java:40)
       org.openqa.selenium.remote.server.handler.ChangeUrl.call (ChangeUrl.java:25)
       java.util.current.FutureTask.run (FutureTask.java:266)
       org.openqa.selenium.remote.server.DefaultSession$1.run (DefaultSession.java:176)
       java.util.current.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142)
       java.util.current.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
       java.lang.Thread.run (Thread.java:748)
     )

haskell selenium

2022-09-30 21:24

1 Answers

This is my guess because there is no code for the test that falls.
Are you starting the server with spec=withApp$do etc.?
If you call openPage "http://localhost:3000" while starting the yesod server with that code, it will work.

If you can refer to this
http://qiita.com/jabaraster/items/6cfb39776cbac9cfd3e0#%E3%83%86%E3%82%B9%E3%83%88%E6%9C%AC%E4%BD%93


2022-09-30 21:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.