1 | <?php |
||
5 | class Cops extends Sauce\Sausage\WebDriverTestCase |
||
6 | { |
||
7 | public static $browsers = array( |
||
8 | // run FF15 on Windows 8 on Sauce |
||
9 | array( |
||
10 | 'browserName' => 'firefox', |
||
11 | 'desiredCapabilities' => array( |
||
12 | 'version' => '28', |
||
13 | 'platform' => 'Windows 8.1', |
||
14 | ) |
||
15 | ), |
||
16 | // run IE9 on Windows 7 on Sauce |
||
17 | array( |
||
18 | 'browserName' => 'internet explorer', |
||
19 | 'desiredCapabilities' => array( |
||
20 | 'version' => '9', |
||
21 | 'platform' => 'Windows 7', |
||
22 | ) |
||
23 | ), |
||
24 | // run IE10 on Windows 8 on Sauce |
||
25 | array( |
||
26 | 'browserName' => 'internet explorer', |
||
27 | 'desiredCapabilities' => array( |
||
28 | 'version' => '11', |
||
29 | 'platform' => 'Windows 8.1', |
||
30 | ) |
||
31 | ), |
||
32 | // run Safari 7 on Maverick on Sauce |
||
33 | array( |
||
34 | 'browserName' => 'safari', |
||
35 | 'desiredCapabilities' => array( |
||
36 | 'version' => '7', |
||
37 | 'platform' => 'OS X 10.9', |
||
38 | ) |
||
39 | ), |
||
40 | // run Mobile Safari on iOS |
||
41 | array( |
||
42 | 'browserName' => 'iphone', |
||
43 | 'desiredCapabilities' => array( |
||
44 | 'app' => 'safari', |
||
45 | 'device' => 'iPhone 6', |
||
46 | 'version' => '9.2', |
||
47 | 'platform' => 'OS X 10.10', |
||
48 | ) |
||
49 | ), |
||
50 | // run Mobile Browser on Android |
||
51 | array( |
||
52 | 'browserName' => 'Android', |
||
53 | 'desiredCapabilities' => array( |
||
54 | 'version' => '5.1', |
||
55 | 'platform' => 'Linux', |
||
56 | ) |
||
57 | ), |
||
58 | // run Chrome on Linux on Sauce |
||
59 | array( |
||
60 | 'browserName' => 'chrome', |
||
61 | 'desiredCapabilities' => array( |
||
62 | 'version' => '33', |
||
63 | 'platform' => 'Linux' |
||
64 | ) |
||
65 | ) |
||
66 | |||
67 | |||
68 | // run Chrome locally |
||
69 | //array( |
||
70 | //'browserName' => 'chrome', |
||
71 | //'local' => true, |
||
72 | //'sessionStrategy' => 'shared' |
||
73 | //) |
||
74 | ); |
||
75 | |||
76 | public function setUp() |
||
77 | { |
||
78 | if (isset ($_SERVER["TRAVIS_JOB_NUMBER"])) { |
||
79 | $caps = $this->getDesiredCapabilities(); |
||
80 | $caps['build'] = getenv ("TRAVIS_JOB_NUMBER"); |
||
81 | $caps['tunnel-identifier'] = getenv ("TRAVIS_JOB_NUMBER"); |
||
82 | $caps['idle-timeout'] = "180"; |
||
83 | $this->setDesiredCapabilities($caps); |
||
84 | } |
||
85 | parent::setUp (); |
||
86 | } |
||
87 | |||
88 | public function setUpPage() |
||
89 | { |
||
90 | if (isset ($_SERVER["TRAVIS_JOB_NUMBER"])) { |
||
91 | $this->url('http://127.0.0.1:8888/index.php'); |
||
92 | } else { |
||
93 | $this->url('http://cops-demo.slucas.fr/index.php'); |
||
94 | } |
||
95 | |||
96 | $driver = $this; |
||
97 | $title_test = function($value) use ($driver) { |
||
98 | $text = $driver->byXPath('//h1')->text (); |
||
99 | return $text == $value; |
||
100 | }; |
||
101 | |||
102 | $this->spinAssert("Home Title", $title_test, [ "COPS DEMO" ]); |
||
103 | } |
||
104 | |||
105 | public function string_to_ascii($string) |
||
106 | { |
||
107 | $ascii = NULL; |
||
108 | |||
109 | for ($i = 0; $i < strlen($string); $i++) |
||
110 | { |
||
111 | $ascii += ord($string[$i]); |
||
112 | } |
||
113 | |||
114 | return mb_detect_encoding($string) . "X" . $ascii; |
||
115 | } |
||
116 | |||
117 | // public function testTitle() |
||
118 | // { |
||
119 | // $driver = $this; |
||
120 | // $title_test = function($value) use ($driver) { |
||
121 | // $text = $driver->byXPath('//h1')->text (); |
||
122 | // return $text == $value; |
||
123 | // }; |
||
124 | |||
125 | // $author = $this->byXPath ('//h2[contains(text(), "Authors")]'); |
||
126 | // $author->click (); |
||
127 | |||
128 | // $this->spinAssert("Author Title", $title_test, [ "AUTHORS" ]); |
||
129 | // } |
||
130 | |||
131 | // public function testCog() |
||
132 | // { |
||
133 | // $cog = $this->byId ("searchImage"); |
||
134 | |||
135 | // $search = $this->byName ("query"); |
||
136 | // $this->assertFalse ($search->displayed ()); |
||
137 | |||
138 | // $cog->click (); |
||
139 | |||
140 | // $search = $this->byName ("query"); |
||
141 | // $this->assertTrue ($search->displayed ()); |
||
142 | // } |
||
143 | |||
144 | public function testFilter() |
||
145 | { |
||
146 | $driver = $this; |
||
147 | $title_test = function($value) use ($driver) { |
||
148 | $text = $driver->byXPath('//h1')->text (); |
||
149 | return $text == $value; |
||
150 | }; |
||
151 | |||
152 | $element_present = function ($using, $id) use ($driver) { |
||
153 | $elements = $driver->elements ($driver->using($using)->value($id)); |
||
154 | return count($elements) == 1; |
||
155 | }; |
||
156 | |||
157 | // Click on the wrench to enable tag filtering |
||
158 | $this->spinWait ("", $element_present, [ "class name", 'icon-wrench']); |
||
159 | $this->byClassName ("icon-wrench")->click (); |
||
160 | |||
161 | $this->spinWait ("", $element_present, [ "id", "html_tag_filter"]); |
||
162 | $this->byId ("html_tag_filter")->click (); |
||
163 | |||
164 | // Go back to home screen |
||
165 | $this->byClassName ("icon-home")->click (); |
||
166 | |||
167 | $this->spinAssert("Home Title", $title_test, [ "COPS DEMO" ]); |
||
168 | |||
169 | // Go on the recent page |
||
170 | $author = $this->byXPath ('//h2[contains(text(), "Recent")]'); |
||
171 | $author->click (); |
||
172 | |||
173 | $this->spinAssert("Recent book title", $title_test, [ "RECENT ADDITIONS" ]); |
||
174 | |||
175 | // Click on the cog to show tag filters |
||
176 | $cog = $this->byId ("searchImage"); |
||
177 | $cog->click (); |
||
178 | sleep (1); |
||
179 | // Filter on War & Military |
||
180 | $filter = $this->byXPath ('//li[contains(text(), "War")]'); |
||
181 | $filter->click (); |
||
182 | sleep (1); |
||
183 | // Only one book |
||
184 | $filtered = $this->elements ($this->using('css selector')->value('*[class="books"]')); |
||
185 | $this->assertEquals (1, count($filtered)); |
||
186 | $filter->click (); |
||
187 | sleep (1); |
||
188 | // 13 book |
||
189 | $filtered = $this->elements ($this->using('css selector')->value('*[class="books"]')); |
||
190 | $this->assertEquals (14, count($filtered)); |
||
191 | } |
||
192 | |||
193 | public function normalSearch ($src, $out) |
||
194 | { |
||
195 | $driver = $this; |
||
196 | $title_test = function($value) use ($driver) { |
||
197 | $text = $driver->byXPath('//h1')->text (); |
||
198 | return $text == $value; |
||
199 | }; |
||
200 | |||
201 | // Click on the cog to show the search |
||
202 | $cog = $this->byId ("searchImage"); |
||
203 | $cog->click (); |
||
204 | //sleep (1); |
||
205 | |||
206 | // Focus the input and type |
||
207 | $this->waitUntil(function () { |
||
208 | if ($this->byName ("query")) { |
||
209 | return true; |
||
210 | } |
||
211 | return null; |
||
212 | }, 1000); |
||
213 | $queryInput = $this->byName ("query"); |
||
214 | $queryInput->click (); |
||
215 | $queryInput->value ($src); |
||
216 | $queryInput->submit (); |
||
217 | |||
218 | $this->spinAssert("Home Title", $title_test, [ "SEARCH RESULT FOR *" . $out . "*" ]); |
||
219 | } |
||
220 | |||
221 | public function testSearchWithoutAccentuatedCharacters() |
||
222 | { |
||
223 | $this->normalSearch ("ali", "ALI"); |
||
224 | } |
||
225 | |||
226 | public function testSearchWithAccentuatedCharacters() |
||
227 | { |
||
228 | if ($this->getBrowser() == "Android") { |
||
229 | $this->markTestIncomplete(); |
||
230 | return; |
||
231 | } |
||
232 | $this->normalSearch ("é", "É"); |
||
233 | } |
||
234 | } |
||
235 |