Merge lp:~dpniel/ubuntu-autopilot-tests/evince-autopilot-1.3 into lp:ubuntu-autopilot-tests
- evince-autopilot-1.3
- Merge into trunk
Proposed by
Dan Chapman
Status: | Merged |
---|---|
Merged at revision: | 46 |
Proposed branch: | lp:~dpniel/ubuntu-autopilot-tests/evince-autopilot-1.3 |
Merge into: | lp:ubuntu-autopilot-tests |
Diff against target: |
352 lines (+166/-146) 1 file modified
ubuntu_autopilot_tests/evince/test_evince.py (+166/-146) |
To merge this branch: | bzr merge lp:~dpniel/ubuntu-autopilot-tests/evince-autopilot-1.3 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Nicholas Skaggs (community) | Approve | ||
Review via email:
|
Commit message
Description of the change
4 working tests
- Display pdf
- Changing pages
- Search document
- Side bar open and close
1 non-working test
- Fullscreen mode
One sleep has snuck its way in due to not being able to introspect the Yelp print dialog. Might be beacuse it introspecting a different application from within a different. Although vis shows Yelp and GtkPrintUnixDialog, the test didnt seem to like it. So have set the sleep to 10 seconds
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'ubuntu_autopilot_tests/evince/test_evince.py' |
2 | --- ubuntu_autopilot_tests/evince/test_evince.py 2013-01-17 20:27:58 +0000 |
3 | +++ ubuntu_autopilot_tests/evince/test_evince.py 2013-06-04 15:36:31 +0000 |
4 | @@ -1,182 +1,202 @@ |
5 | from autopilot.testcase import AutopilotTestCase |
6 | from autopilot.matchers import Eventually |
7 | -from testtools.matchers import Equals, Contains |
8 | +from testtools.matchers import Equals, Contains, NotEquals |
9 | + |
10 | +from autopilot.input import Mouse, Touch, Pointer |
11 | |
12 | from time import sleep |
13 | import tempfile |
14 | import os |
15 | - |
16 | -#Register Evince as an application so we can call it |
17 | -AutopilotTestCase.register_known_application("Document Viewer", "evince.desktop", "evince") |
18 | - |
19 | -#http://packages.qa.ubuntu.com/qatracker/testcases/1417/info |
20 | + |
21 | + |
22 | + |
23 | + |
24 | class EvinceTests(AutopilotTestCase): |
25 | - |
26 | + |
27 | def setUp(self): |
28 | super(EvinceTests, self).setUp() |
29 | - self.app = self.start_app_window("Document Viewer") |
30 | - |
31 | - #This will make sure evince window you launched is focused and ready to accept your keyboard input |
32 | - self.app.set_focus() |
33 | - self.assertTrue(self.app.is_focused) |
34 | - |
35 | + self.app = self.launch_test_application('evince') |
36 | + |
37 | + self.windowTitle = self.app.select_single('EvWindow') |
38 | + self.prev_button = self.app.select_single('GtkButton', tooltip_text='Go to the previous page') |
39 | + self.next_button = self.app.select_single('GtkButton', tooltip_text='Go to the next page') |
40 | + self.page_num_box = self.app.select_single('GtkBox', tooltip_text='Select Page') |
41 | + self.search_button = self.app.select_single('GtkToggleButton', |
42 | + tooltip_text='Find a word or phrase in the document') |
43 | + self.entry = self.page_num_box.get_children_by_type('GtkEntry')[0] |
44 | + self.pointing_device = Pointer(Mouse.create()) |
45 | + |
46 | def test_display_pdf_file(self): |
47 | - #Test-case name: evince/evn-001 |
48 | - #This test will check that Evince can display PDFs correctly |
49 | - #Create pdf |
50 | + '''test to view a pdf file''' |
51 | + #Generate a temp file name, and split the path |
52 | tempFile = _generateTempFileName() |
53 | - self.createFile(tempFile) |
54 | - |
55 | - #Open pdf |
56 | - self.openFile(tempFile) |
57 | - sleep(5) |
58 | - #Verify Is the selected PDF displayed correctly? |
59 | (dirName, fileName) = os.path.split(tempFile) |
60 | - self.assertThat(lambda: self.app.name, Eventually(Contains(fileName))) |
61 | - |
62 | - #Delete pdf |
63 | - self.deleteFile(tempFile) |
64 | - |
65 | - def test_enter_fullscreen_mode(self): |
66 | - #Test-case name: evince/evn-002 |
67 | - #This test will check that Evince can enter fullscreen mode via F11 |
68 | - |
69 | - #Press F11 |
70 | - self.keyboard.press_and_release("F11") |
71 | - sleep(5) |
72 | - |
73 | - #Does Evince enter fullscreen mode? |
74 | - windowState = self.app._get_window_states() |
75 | - self.assertThat(windowState, Contains("_NET_WM_STATE_FULLSCREEN")) |
76 | - |
77 | - |
78 | - def test_exit_fullscreen_mode(self): |
79 | - #Test-case name: evince/evn-003 |
80 | - #This test will check that Evince can enter exit fullscreen mode via F11 |
81 | - |
82 | - #Press F11 |
83 | - self.keyboard.press_and_release("F11") |
84 | - sleep(5) |
85 | - |
86 | - #Make sure that Evince is in fullscreen mode |
87 | - windowState = self.app._get_window_states() |
88 | - self.assertThat(windowState, Contains("_NET_WM_STATE_FULLSCREEN")) |
89 | - |
90 | - #Exit fullscreen mode |
91 | - self.keyboard.press_and_release("F11") |
92 | - sleep(5) |
93 | - |
94 | - #Does Evince exit fullscreen mode and restore the window size and position correctly? |
95 | - windowState = self.app._get_window_states() |
96 | - self.assertNotIn(windowState, Contains("_NET_WM_STATE_FULLSCREEN")) |
97 | - |
98 | - |
99 | - def test_hide_side_bar(self): |
100 | - #Test-case name: evince/evn-004 |
101 | - #This test will check that Evince can hide sidebar |
102 | - tempFile = _generateTempFileName() |
103 | - |
104 | - #Create pdf |
105 | - self.createFile(tempFile) |
106 | - #Open pdf |
107 | - self.openFile(tempFile) |
108 | - sleep(5) |
109 | - |
110 | - #Make sure sidebar is displayed |
111 | - #TODO |
112 | - |
113 | - #Press F9 |
114 | - self.keyboard.press_and_release("F9") |
115 | - sleep(5) |
116 | - |
117 | - #Did Evince hide the sidebar? |
118 | - |
119 | - #Delete pdf |
120 | - self.deleteFile(tempFile) |
121 | - |
122 | - def test_show_side_bar(self): |
123 | - #Test-case name: evince/evn-005 |
124 | - #This test will check that Evince can display sidebar |
125 | - tempFile = _generateTempFileName() |
126 | - |
127 | - #Create pdf |
128 | - self.createFile(tempFile) |
129 | - #Open pdf |
130 | - self.openFile(tempFile) |
131 | - sleep(5) |
132 | - #Make sure sidebar is hidden |
133 | - |
134 | - #Press F9 |
135 | - self.keyboard.press_and_release("F9") |
136 | - sleep(5) |
137 | - |
138 | - #Does Evince display a sidebar with page thumbnails or the document index? |
139 | - #TODO |
140 | - |
141 | - #Delete pdf |
142 | - self.deleteFile(tempFile) |
143 | - |
144 | - def test_rotate_document(self): |
145 | - #Test-case name: evince/evn-006 |
146 | - #This test will check that Evince can rotate a document |
147 | - tempFile = _generateTempFileName() |
148 | - |
149 | - #Create pdf |
150 | - self.createFile(tempFile) |
151 | - #Open pdf |
152 | - self.openFile(tempFile) |
153 | - sleep(5) |
154 | - #Press ctrl+left |
155 | - self.keyboard.press_and_release("Ctrl+Left") |
156 | - sleep(5) |
157 | - |
158 | - #Verify The pdf is rotated left and Does Evince display the rotated document correctly? |
159 | - #TODO |
160 | - |
161 | - #Press ctrl+right |
162 | - self.keyboard.press_and_release("Ctrl+Right") |
163 | - sleep(5) |
164 | - |
165 | - #Verify The pdf is rotated right and Does Evince display the rotated document correctly? |
166 | - #TODO |
167 | - |
168 | - #Delete pdf |
169 | - self.deleteFile(tempFile) |
170 | - |
171 | - def createFile(self, fileName): |
172 | + #create the temp file |
173 | + self.create_temp_file(tempFile) |
174 | + #open the created temp file |
175 | + self.open_temp_file(tempFile) |
176 | + #Grab evince window |
177 | + |
178 | + #test file name is in the window title bar |
179 | + self.assertThat(self.windowTitle.title, Eventually(Contains(fileName))) |
180 | + # delete the temp file |
181 | + self.delete_temp_file(tempFile) |
182 | + |
183 | + #def test_enter_and_exit_fullscreen_mode(self): |
184 | + # ''' test to see that we can enter and exit fullscreen mode ''' |
185 | + # self.keyboard.press_and_release('F11') |
186 | + # DOES NOT WORK!!-------------------------------------------- |
187 | + # self.fullscreen_windowState = self.app.get_wm_state() |
188 | + # # find a way to assert the window state |
189 | + # |
190 | + # self.keyboard.press_and_release('F11') |
191 | + # |
192 | + # # TODO: Currently unable to get the window state with get_wm_state. |
193 | + # # needs further investigation. |
194 | + |
195 | + |
196 | + def test_changing_pages(self): |
197 | + #Lets test we can go up and down the pages |
198 | + tempFile = _generateTempFileName() |
199 | + (dirPath, fileName) = os.path.split(tempFile) |
200 | + self.create_temp_file(tempFile) |
201 | + self.open_temp_file(tempFile) |
202 | + self.assertThat(self.windowTitle.title, Eventually(Contains(fileName))) |
203 | + # move to page 2 |
204 | + self.pointing_device.move_to_object(self.next_button) |
205 | + self.pointing_device.click() |
206 | + self.assertThat(self.entry.text, Eventually(Contains('2'))) |
207 | + # move to page 3 |
208 | + self.pointing_device.click() |
209 | + self.assertThat(self.entry.text, Eventually(Contains('3'))) |
210 | + # go back to page 2 |
211 | + self.pointing_device.move_to_object(self.prev_button) |
212 | + self.pointing_device.click() |
213 | + self.assertThat(self.entry.text, Eventually(Contains('2'))) |
214 | + # and back to the first page |
215 | + self.pointing_device.click() |
216 | + self.assertThat(self.entry.text, Eventually(Contains('1'))) |
217 | + |
218 | + self.delete_temp_file(tempFile) |
219 | + |
220 | + def test_sidebar_open_close(self): |
221 | + #Lets test we can open and close the sidebar |
222 | + tempFile = _generateTempFileName() |
223 | + (dirPath, fileName) = os.path.split(tempFile) |
224 | + self.create_temp_file(tempFile) |
225 | + self.open_temp_file(tempFile) |
226 | + self.assertThat(self.windowTitle.title, Eventually(Contains(fileName))) |
227 | + # test opening and closing of sidebar |
228 | + self.change_sidebar_state() |
229 | + self.change_sidebar_state() |
230 | + |
231 | + self.delete_temp_file(tempFile) |
232 | + |
233 | + def test_search_document(self): |
234 | + #lets test we can search a document |
235 | + tempFile = _generateTempFileName() |
236 | + (dirPath, fileName) = os.path.split(tempFile) |
237 | + self.create_temp_file(tempFile) |
238 | + self.open_temp_file(tempFile) |
239 | + self.assertThat(self.windowTitle.title, Eventually(Contains(fileName))) |
240 | + #click search toggle button |
241 | + self.pointing_device.move_to_object(self.search_button) |
242 | + self.pointing_device.click() |
243 | + # Enter a search query |
244 | + self.keyboard.type('Advanced') |
245 | + # check it found the the search query |
246 | + self.search_result_label = self.app.select_single('GtkLabel', label='1 found on this page') |
247 | + self.assertThat(self.search_result_label.label, Eventually(Contains('1 found on this page'))) |
248 | + |
249 | + self.delete_temp_file(tempFile) |
250 | + |
251 | + def change_sidebar_state(self): |
252 | + ''' changes the state of the sidebar and tests that it changed ''' |
253 | + # get value of Evsidebar.visible |
254 | + self.side_bar = self.app.select_single('EvSidebar') |
255 | + visible = self.side_bar.visible |
256 | + # Test and change the side bar, |
257 | + if visible == 1: |
258 | + self.keyboard.press_and_release('F9') |
259 | + self.assertThat(self.side_bar.visible, Equals(0)) |
260 | + else: |
261 | + self.keyboard.press_and_release('F9') |
262 | + self.assertThat(self.side_bar.visible, Equals(1)) |
263 | + |
264 | + def create_temp_file(self, fileName): |
265 | + ''' create a temporary file for tests ''' |
266 | #Create a pdf file to use during tests |
267 | self.keyboard.press_and_release("F1") |
268 | + # TODO: would be good to check yelp window title |
269 | + # but get NoneType error at the moment |
270 | + #self.yelp_dialog = self.app.select_single('YelpWindow') |
271 | + #self.assertThat(self.yelp_dialog.title, Eventually(Contains('Evince Document Viewer'))) |
272 | + # |
273 | + |
274 | + # Open the print dailog and check it loaded |
275 | self.keyboard.press_and_release("Ctrl+p") |
276 | + |
277 | + # TODO: unable to introspect print dialog at moment |
278 | + #self.print_dialog = self.app.select_single('GtkPrintUnixDialog') |
279 | + #self.assertThat(self.print_dialog.title, Eventually(Equals(Print))) |
280 | + |
281 | self.keyboard.press_and_release("Tab") |
282 | - |
283 | + |
284 | #select print to file |
285 | self.keyboard.press_and_release("p") |
286 | - |
287 | + |
288 | #select filename |
289 | + ## TODO: try and select the file button with mouse |
290 | + #self.file_name_button = self.app.select_single('GtkLabel', label='~/Documents/output.pdf') |
291 | + #self.pointing_device.move_to_object(self.file_name_button) |
292 | + #self.pointing_device.click() |
293 | + |
294 | + # Using keyboard to enter file for now |
295 | + |
296 | + |
297 | + |
298 | self.keyboard.press_and_release("Tab") |
299 | self.keyboard.press_and_release("Tab") |
300 | self.keyboard.press_and_release("Space") |
301 | + |
302 | self.keyboard.press_and_release("Ctrl+a") |
303 | self.keyboard.type(fileName + "\n") |
304 | - |
305 | - sleep(5) |
306 | + #TODO: lose this sleep when we can introspect print dialog |
307 | + sleep(10) |
308 | |
309 | #make the file |
310 | self.keyboard.press_and_release("Alt+p") |
311 | |
312 | #close window |
313 | self.keyboard.press_and_release("Ctrl+w") |
314 | - |
315 | - def openFile(self, fileName): |
316 | - #Open a pdf by selecting file |
317 | - self.keyboard.press_and_release("Ctrl+o") |
318 | + |
319 | + |
320 | + def open_temp_file(self, fileName): |
321 | + '''Opens the temporary file''' |
322 | + # Click on the settings button |
323 | + self.settings_button = self.app.select_single('GtkImage', icon_name='emblem-system-symbolic') |
324 | + self.pointing_device.move_to_object(self.settings_button) |
325 | + self.pointing_device.click() |
326 | + # press 'O' to open the file dialog |
327 | + self.keyboard.press_and_release("o") |
328 | + # check the file dialog opened and contains 'Open Document' in the window title |
329 | + self.open_file_dialog = self.app.select_single('GtkFileChooserDialog') |
330 | + self.assertThat(self.open_file_dialog.title, Eventually(Equals('Open Document'))) |
331 | + # enter the temp file name |
332 | self.keyboard.press_and_release("Ctrl+a") |
333 | - self.keyboard.type(fileName + "\n") |
334 | - |
335 | - def deleteFile(self, fileName): |
336 | - #Delete pdf file created for test purposes |
337 | + self.keyboard.type(fileName) |
338 | + # click on the 'open' button |
339 | + self.open_button = self.app.select_single('GtkLabel', label='_Open') |
340 | + self.pointing_device.move_to_object(self.open_button) |
341 | + self.pointing_device.click() |
342 | + |
343 | + def delete_temp_file(self, fileName): |
344 | + #delete temp file |
345 | self.addCleanup(os.remove, fileName) |
346 | |
347 | + |
348 | + |
349 | + |
350 | def _generateTempFileName(): |
351 | #Create temporary file, then close it, so we can re-use the file name |
352 | sFile = tempfile.NamedTemporaryFile() |
Looks good.. Almost got out without needing to fallback because of issues. We'll look into the wmstate for the fullscreen test too. Thanks!