forked from haskell-webdriver/haskell-webdriver
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SearchBaidu.hs
50 lines (38 loc) · 1.21 KB
/
SearchBaidu.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{-# LANGUAGE OverloadedStrings #-}
module SearchBaidu where
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Text as T
import Test.WebDriver
import Test.WebDriver.Commands.Wait
import Prelude
chromeConf = useBrowser chrome defaultConfig
ffConf = defaultConfig
-- Have no fun with baidu but only cause it is loading fast than google in China.
--
baidu :: WD ()
baidu = do
openPage "http://www.baidu.com/"
waitUntil 15 $
expect . (== "http://www.baidu.com/") =<< getCurrentURL
searchBaidu :: WD ()
searchBaidu = do
searchBox <- findElem (ById "kw")
sendKeys "Cheese!" searchBox
submit searchBox
waitUntil 15 $ do
title <- getTitle
expect ("Cheese!" `T.isInfixOf` title)
container <- findElem (ById "container")
eList1 <- findElems (ByCSS "c-container")
eList2 <- findElems (ByClass "c-container")
expect =<< (fmap and $ zipWithM (==) eList1 eList2)
forM_ eList1 $ \e -> findElemsFrom e (ByTag "a")
testCase c = void . runSession c . finallyClose $ (baidu >> searchBaidu)
testSuites = mapM_ testCase [ffConf, chromeConf]
main = do
--testCase capsChrome `seq` testCase capsFF
--mapM_ (forkOS . testCase) [capsFF, capsChrome]
testSuites
print "done"