Skip to content

Commit

Permalink
mostly working w3c commands
Browse files Browse the repository at this point in the history
  • Loading branch information
dten committed Dec 12, 2023
1 parent 0be31d1 commit 1fa32e7
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 261 deletions.
26 changes: 11 additions & 15 deletions src/Test/WebDriver/Capabilities.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Test.WebDriver.JSON
import Data.Aeson
import Data.Aeson.Types (Parser, typeMismatch, Pair)

import Data.Text (Text, toLower, toUpper)
import Data.Text (Text, toLower)
import Data.Default.Class (Default(..))
import Data.Word (Word16)
import Data.Maybe (fromMaybe, catMaybes)
Expand Down Expand Up @@ -176,7 +176,7 @@ instance ToJSON Capabilities where
object $ filter (\p -> snd p /= Null)
$ [ "browserName" .= browser
, "version" .= version
, "platform" .= platform
, "platformName" .= platform
, "proxy" .= proxy
, "javascriptEnabled" .= javascriptEnabled
, "takesScreenshot" .= takesScreenshot
Expand Down Expand Up @@ -204,7 +204,7 @@ instance ToJSON Capabilities where
]
Chrome {..}
-> catMaybes [ opt "chrome.chromedriverVersion" chromeDriverVersion ]
++ [ "chromeOptions" .= object (catMaybes
++ [ "goog:chromeOptions" .= object (catMaybes
[ opt "binary" chromeBinary
] ++
[ "args" .= chromeOptions
Expand Down Expand Up @@ -264,12 +264,7 @@ instance FromJSON Capabilities where
browser <- req "browserName"
Capabilities <$> getBrowserCaps browser
<*> opt "version" Nothing
<*> do
p <- o .:? "platform"
pN <- o .:? "platformName"
case p <|> pN of
Just p' -> return p'
Nothing -> throw . BadJSON $ "platform or platformName required"
<*> opt "platformName" Any
<*> opt "proxy" NoProxy
<*> b "javascriptEnabled"
<*> b "takesScreenshot"
Expand Down Expand Up @@ -615,7 +610,8 @@ data Platform = Windows | XP | Vista | Mac | Linux | Unix | Any
deriving (Eq, Show, Ord, Bounded, Enum)

instance ToJSON Platform where
toJSON = String . toUpper . fromString . show
toJSON Any = Null
toJSON p = String . toLower . fromString $ show p

instance FromJSON Platform where
parseJSON (String jStr) = case toLower jStr of
Expand Down Expand Up @@ -664,17 +660,17 @@ instance FromJSON ProxyType where
instance ToJSON ProxyType where
toJSON pt = object $ case pt of
NoProxy ->
["proxyType" .= ("DIRECT" :: String)]
["proxyType" .= ("direct" :: String)]
UseSystemSettings ->
["proxyType" .= ("SYSTEM" :: String)]
["proxyType" .= ("system" :: String)]
AutoDetect ->
["proxyType" .= ("AUTODETECT" :: String)]
["proxyType" .= ("autodetect" :: String)]
PAC{autoConfigUrl = url} ->
["proxyType" .= ("PAC" :: String)
["proxyType" .= ("pac" :: String)
,"proxyAutoconfigUrl" .= url
]
Manual{ftpProxy = ftp, sslProxy = ssl, httpProxy = http} ->
["proxyType" .= ("MANUAL" :: String)
["proxyType" .= ("manual" :: String)
,"ftpProxy" .= ftp
,"sslProxy" .= ssl
,"httpProxy" .= http
Expand Down
Loading

0 comments on commit 1fa32e7

Please sign in to comment.