webdriver 0.0.1 → 0.1
raw patch · 6 files changed
+113/−38 lines, 6 filesdep ~aesondep ~networkdep ~time
Dependency ranges changed: aeson, network, time, transformers, transformers-base
Files
- Test/WebDriver/Commands.hs +54/−24
- Test/WebDriver/Commands/Internal.hs +11/−0
- Test/WebDriver/Firefox/Profile.hs +2/−2
- Test/WebDriver/Internal.hs +1/−1
- Test/WebDriver/Types.hs +35/−4
- webdriver.cabal +10/−7
Test/WebDriver/Commands.hs view
@@ -10,7 +10,7 @@ -- ** Page info , getCurrentURL, getSource, getTitle, screenshot -- * Timeouts- , setImplicitWait, setScriptTimeout+ , setImplicitWait, setScriptTimeout, setPageLoadTimeout -- * Web elements , Element(..), Selector(..) -- ** Searching for elements@@ -24,15 +24,17 @@ , tagName, activeElem, elemInfo -- ** Element equality , (<==>), (</=>)- -- * Javascript + -- * Javascript , executeJS, asyncJS , JSArg(..)- -- * Windows + -- * Windows , WindowHandle(..), currentWindow- , getCurrentWindow, focusWindow, closeWindow, windows+ , getCurrentWindow, closeWindow, windows, focusWindow, maximize , getWindowSize, setWindowSize, getWindowPos, setWindowPos+ -- * Focusing on frames+ , focusFrame, FrameSelector(..) -- * Cookies- , Cookie(..)+ , Cookie(..), mkCookie , cookies, setCookie, deleteCookie, deleteVisibleCookies -- * Alerts , getAlertText, replyToAlert, acceptAlert, dismissAlert@@ -49,6 +51,8 @@ , getOrientation, setOrientation -- * Geo-location , getLocation, setLocation+ -- * HTML 5 web storage+ , storageSize, getAllKeys, deleteAllKeys, getKey, setKey, deleteKey -- * IME support , availableIMEEngines, activeIMEEngine, checkIMEActive , activateIME, deactivateIME@@ -127,6 +131,11 @@ where msField = ["ms" .= ms] allFields = ["type" .= ("script" :: String)] ++ msField +setPageLoadTimeout :: Integer -> WD ()+setPageLoadTimeout ms = doSessCommand POST "/timeouts" params+ where params = object ["type" .= ("page load" :: String)+ ,"ms" .= ms ]+ -- |Gets the URL of the current page. getCurrentURL :: WD String getCurrentURL = doSessCommand GET "/url" ()@@ -205,9 +214,9 @@ deactivateIME :: WD () deactivateIME = doSessCommand POST "/ime/deactivate" () ---TODO!!!---focusFrame :: Frame -> WD ()---focusFrame = undefined+-- |Switch focus to the frame specified by the FrameSelector.+focusFrame :: FrameSelector -> WD ()+focusFrame s = doSessCommand POST "/frame" . single "id" $ s -- |Returns a handle to the currently focused window getCurrentWindow :: WD WindowHandle@@ -217,32 +226,36 @@ windows :: WD [WindowHandle] windows = doSessCommand GET "/window_handles" () --- |Switches focus to a given window. focusWindow :: WindowHandle -> WD ()-focusWindow = doSessCommand POST "/window" . single "name"+focusWindow w = doSessCommand POST "/window" . single "name" $ w -- |Closes the given window closeWindow :: WindowHandle -> WD () closeWindow = doSessCommand DELETE "/window" . single "name" --- |Get the dimensions of the given window.-getWindowSize :: WindowHandle -> WD (Word, Word)-getWindowSize w =- doWinCommand GET w "/size" () >>= parsePair "width" "height" "getWindowSize"+-- |Maximizes the current window if not already maximized+maximize :: WD ()+maximize = doWinCommand GET currentWindow "/maximize" () --- |Set the dimensions of the given window.-setWindowSize :: WindowHandle -> (Word, Word) -> WD ()-setWindowSize win = doWinCommand POST win "/size" . pair ("width", "height")+-- |Get the dimensions of the current window.+getWindowSize :: WD (Word, Word)+getWindowSize = doWinCommand GET currentWindow "/size" () + >>= parsePair "width" "height" "getWindowSize" --- |Get the coordinates of the given window.-getWindowPos :: WindowHandle -> WD (Int, Int)-getWindowPos w = do - doWinCommand GET w "/position" () >>= parsePair "x" "y" "getWindowPos"+-- |Set the dimensions of the current window.+setWindowSize :: (Word, Word) -> WD ()+setWindowSize = doWinCommand POST currentWindow "/size" + . pair ("width", "height") --- |Set the coordinates of the given window.-setWindowPos :: WindowHandle -> (Int, Int) -> WD ()-setWindowPos w = doWinCommand POST w "/position" . pair ("x","y")+-- |Get the coordinates of the current window.+getWindowPos :: WD (Int, Int)+getWindowPos = doWinCommand GET currentWindow "/position" () + >>= parsePair "x" "y" "getWindowPos" +-- |Set the coordinates of the current window.+setWindowPos :: (Int, Int) -> WD ()+setWindowPos = doWinCommand POST currentWindow "/position" . pair ("x","y")+ -- |Retrieve all cookies visible to the current page. cookies :: WD [Cookie] cookies = doSessCommand GET "/cookie" ()@@ -496,3 +509,20 @@ "longitude", "altitude") +storageSize :: HTML5StorageType -> WD Integer+storageSize s = doStorageCommand GET s "/size" ()++getAllKeys :: HTML5StorageType -> WD [Text]+getAllKeys s = doStorageCommand GET s "" ()++deleteAllKeys :: HTML5StorageType -> WD ()+deleteAllKeys s = doStorageCommand DELETE s "" ()++getKey :: HTML5StorageType -> Text -> WD Text+getKey s k = doStorageCommand GET s ("/key/" `T.append` k) ()++setKey :: HTML5StorageType -> Text -> Text -> WD Text+setKey s k v = doStorageCommand POST s "" . object $ ["key" .= k,+ "value" .= v ] +deleteKey :: HTML5StorageType -> Text -> WD ()+deleteKey s k = doStorageCommand POST s ("/key/" `T.append` k) ()
Test/WebDriver/Commands/Internal.hs view
@@ -30,6 +30,10 @@ RequestMethod -> WindowHandle -> Text -> a -> WD b doWinCommand = doWinCommand' [] +doStorageCommand :: (ToJSON a, FromJSON b) =>+ RequestMethod -> HTML5StorageType -> Text -> a -> WD b+doStorageCommand = doStorageCommand' []+ doCommand' :: (ToJSON a, FromJSON b) => [Header] -> RequestMethod -> Text -> a -> WD b doCommand' headers method path args = do@@ -62,3 +66,10 @@ doElemCommand' h m (Element e) path a = doSessCommand' h m (T.concat ["/element/", e, path]) a +doStorageCommand' :: (ToJSON a, FromJSON b) =>+ [Header] -> RequestMethod -> HTML5StorageType -> Text -> a+ -> WD b+doStorageCommand' h m s path a = doSessCommand' h m (T.concat ["/", s', path]) a+ where s' = case s of+ LocalStorage -> "local_storage"+ SessionStorage -> "session_storage"
Test/WebDriver/Firefox/Profile.hs view
@@ -46,13 +46,13 @@ import Control.Exception.Lifted import Data.Typeable --- |A pure representation of a FirefoxProfile. This structure allows you to+-- |This structure allows you to -- construct and manipulate Firefox profiles in pure code, deferring execution -- of IO operations until the profile is \"prepared\" using either -- 'prepareProfile' or one of the wrapper functions 'prepareTempProfile' and -- 'prepareLoadedProfile'. data FirefoxProfile = FirefoxProfile - { -- |Location of the profile in the file system+ { -- |Location of the profile in the local file system profileDir :: FilePath -- |A set of filepaths pointing to Firefox extensions. -- These paths can either refer to an .xpi file
Test/WebDriver/Internal.hs view
@@ -42,7 +42,7 @@ (Nothing, _) -> throwIO $ InvalidURL urlStr (_, Nothing) -> throwIO $ InvalidURL relPath (Just baseURI, Just relURI) -> return . fromJust $ relURI `relativeTo` baseURI-+ mkRequest :: ToJSON a => [Header] -> RequestMethod -> Text -> a -> WD (Response ByteString) mkRequest headers method path args = do uri <- mkWDUri (T.unpack path)
Test/WebDriver/Types.hs view
@@ -13,11 +13,13 @@ -- * WebDriver objects and command-specific types , Element(..) , WindowHandle(..), currentWindow- , Cookie(..)- , Orientation(..)- , MouseButton(..) , Selector(..) , JSArg(..)+ , FrameSelector(..)+ , Cookie(..), mkCookie+ , Orientation(..)+ , MouseButton(..)+ , HTML5StorageType(..) -- * Exceptions , InvalidURL(..), NoSessionId(..), BadJSON(..) , HTTPStatusUnknown(..), HTTPConnError(..)@@ -90,6 +92,17 @@ currentWindow :: WindowHandle currentWindow = WindowHandle "current" +-- |Specifies the frame used by 'Test.WebDriver.Commands.focusFrame'+data FrameSelector = WithIndex Integer + -- |focus on a frame by name or ID+ | WithName Text+ -- |focus on a frame Element+ | WithElement Element+ -- |focus on the first frame, or the main document+ -- if iframes are used.+ | DefaultFrame+ deriving (Eq, Show, Read)+ {- |Information about a WebDriver session. This structure is passed implicitly through all 'WD' computations, and is also used to configure the 'WD' monad before execution. -}@@ -114,7 +127,7 @@ } {- |A default session connects to localhost on port 4444, and hasn't been -created yet. This value is the same as the 'def' with a more specific type. -}+created yet. This value is the same as 'def' but with a more specific type. -} defaultSession :: WDSession defaultSession = def @@ -404,6 +417,14 @@ , cookExpiry :: Maybe Integer } deriving (Eq, Show) +-- |Creates a Cookie with only a name and value specified. All other+-- fields are set to Nothing, which tells the server to use default values.+mkCookie :: Text -> Text -> Cookie+mkCookie name value = Cookie { cookName = name, cookValue = value,+ cookPath = Nothing, cookDomain = Nothing,+ cookSecure = Nothing, cookExpiry = Nothing+ }+ -- |Specifies element(s) within a DOM tree using various selection methods. data Selector = ById Text | ByName Text@@ -429,6 +450,9 @@ deriving (Eq, Show, Ord, Bounded, Enum) +-- |A type to specify HTML 5 storage type+data HTML5StorageType = LocalStorage | SessionStorage + deriving (Eq, Show, Ord, Bounded, Enum) instance Show FailedCommandInfo where --todo: pretty print show i = showString "{errMsg = " . shows (errMsg i) @@ -667,3 +691,10 @@ instance ToJSON JSArg where toJSON (JSArg a) = toJSON a++instance ToJSON FrameSelector where+ toJSON s = case s of+ WithIndex i -> toJSON i+ WithName n -> toJSON n+ WithElement e -> toJSON e+ DefaultFrame -> Null
webdriver.cabal view
@@ -1,6 +1,5 @@ Name: webdriver-Version: 0.0.1-Stability: alpha+Version: 0.1 Cabal-Version: >= 1.6 License: BSD3 License-File: LICENSE@@ -19,7 +18,11 @@ For more information about Selenium itself, see <http://seleniumhq.org/> + To find out what's been changed in this version and others,+ see the changelog at + <https://github.com/kallisti-dev/hs-webdriver/blob/master/CHANGELOG.md> + source-repository this type: git location: git://github.com/kallisti-dev/hs-webdriver.git@@ -31,14 +34,14 @@ library build-depends: base == 4.*- , aeson == 0.6.*+ , aeson >= 0.4 && < 0.7 , HTTP >= 4000.1 && < 4000.3 , mtl >= 2.0 && < 2.2- , network == 2.3.*+ , network == 2.* , bytestring == 0.9.* , text >= 0.7 && < 0.12- , time- , transformers == 0.2.*+ , time == 1.*+ , transformers >= 0.2 , Cabal >= 1.6 , zip-archive >= 0.1.1.7 , directory == 1.*@@ -46,7 +49,7 @@ , unordered-containers >= 0.1.3 , attoparsec == 0.10.* , monad-control == 0.3.*- , transformers-base == 0.4.*+ , transformers-base < 1.0 , vector >= 0.3 , lifted-base == 0.1.* , data-default