Merge lp:~dpniel/ubuntu-autopilot-tests/fileroller-autopilot-1.3 into lp:ubuntu-autopilot-tests

Proposed by Dan Chapman 
Status: Superseded
Proposed branch: lp:~dpniel/ubuntu-autopilot-tests/fileroller-autopilot-1.3
Merge into: lp:ubuntu-autopilot-tests
Diff against target: 433 lines (+219/-196)
2 files modified
ubuntu_autopilot_tests/fileroller/__init__.py (+1/-0)
ubuntu_autopilot_tests/fileroller/test_fileroller.py (+218/-196)
To merge this branch: bzr merge lp:~dpniel/ubuntu-autopilot-tests/fileroller-autopilot-1.3
Reviewer Review Type Date Requested Status
Nicholas Skaggs (community) Needs Fixing
Review via email: mp+166234@code.launchpad.net

This proposal supersedes a proposal from 2013-05-27.

This proposal has been superseded by a proposal from 2013-05-30.

Description of the change

Have removed the delete_all_test_files method and made each test selfcontained. :) All tests run independently on my machine. Should be good to go :)

To post a comment you must log in.
Revision history for this message
Nicholas Skaggs (nskaggs) wrote : Posted in a previous version of this proposal

Despite the hack to get the path going, this looks good!

A couple minor tweaks; If you could remove the delete_all_test_files function and incorporate that into teardown or the end of each needed test. Please also make sure each test is self-contained.

review: Needs Fixing
Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

One more tweak: Could we move the hardcoded filename to a generated temporary filename instead? In addition, this would make files in /tmp instead of /home, which is nicer. I see you also cleanup after yourself anyway, so don't forget that step :)

With those fixes, this should be ready for prod.

review: Needs Fixing
49. By DanChapman <email address hidden>

Changed to using temp directory

50. By DanChapman <email address hidden>

added comments for sleep()

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_autopilot_tests/fileroller/__init__.py'
2--- ubuntu_autopilot_tests/fileroller/__init__.py 2013-03-18 20:29:30 +0000
3+++ ubuntu_autopilot_tests/fileroller/__init__.py 2013-05-30 21:02:26 +0000
4@@ -0,0 +1,1 @@
5+# -*- coding: utf-8 -*-
6
7=== modified file 'ubuntu_autopilot_tests/fileroller/test_fileroller.py'
8--- ubuntu_autopilot_tests/fileroller/test_fileroller.py 2013-05-23 14:46:17 +0000
9+++ ubuntu_autopilot_tests/fileroller/test_fileroller.py 2013-05-30 21:02:26 +0000
10@@ -1,205 +1,227 @@
11 from autopilot.testcase import AutopilotTestCase
12-from autopilot.introspection.gtk import GtkIntrospectionTestMixin
13 from autopilot.matchers import Eventually
14-from testtools.matchers import Equals, NotEquals, GreaterThan, LessThan, Contains
15-
16+from testtools.matchers import Equals, Contains, NotEquals
17+from autopilot.input import Mouse, Pointer
18 from time import sleep
19+import os
20+import shutil
21 import tempfile
22-import os
23-
24-
25-#Register File-roller as an application so we can call it
26-AutopilotTestCase.register_known_application("Archive Manager", "file-roller.desktop", "file-roller")
27-#http://packages.qa.ubuntu.com/qatracker/testcases/1418/info
28-class GtkToolbarTests(AutopilotTestCase, GtkIntrospectionTestMixin):
29+
30+class FileRollerTests(AutopilotTestCase):
31+ '''Collection of autopilot test for file-roller (Archive Manager) '''
32
33 def setUp(self):
34- #Open File-roller
35- super(GtkToolbarTests, self).setUp()
36- self.app = self.launch_test_application('file-roller')
37-
38- #Verify that File-roller is open
39- #FrWindow
40- windowTitle = self.app.select_single('FrWindow', title='Archive Manager')
41- self.assertThat(windowTitle.title, Eventually(Equals('Archive Manager')))
42-
43- def test_archive_and_extract(self):
44- #Test-case name: fileroller/flr-001
45- # This test will check that File Roller can archive and extract files
46-
47- #Click 'New' button from the toolbar
48- #FrWindow, GtkGrid, GtkToolbar, GtkToolButton
49- self.assertThat(lambda: self.app.select_single('GtkToolButton', name='New'), Eventually(NotEquals(None)))
50- btn = self.app.select_single('GtkToolButton', name='New')
51- #let's click it
52- self.mouse.move_to_object(btn)
53- self.mouse.click()
54-
55- #Verify new archive dialog opens
56- #FrNewArchiveDialog
57- dialogWindow = self.app.select_single('FrNewArchiveDialog')
58- self.assertThat(lambda: self.app.select_single('FrNewArchiveDialog').title, Eventually(Contains("New Archive")))
59-
60- #Input any test name for archive
61- tempFile = _generateTempFileName()
62- self.keyboard.type(tempFile)
63-
64- # select 'Tar compressed with gzip' from available formats combobox
65- #TODO
66- #FrNewArchiveDialog, Gtkbox, GtkHBox, GtkVbox, GtkTable, GtkHbox, GtkComboBoxText
67- # active = 9
68-
69- #TODO
70- #Verify that .tar.gz file format is selected
71- #selectWindow = self.app.select_single('GtkComboBoxText', active='9')
72- #self.assertThat(lambda: self.app.select_single('GtkComboBoxText').active, Eventually(Contains(9)))
73- #does not work as it's not an unique identifier
74-
75- #click 'Create' button
76- #FrNewArchiveDialog, GtkBox, GtkButtonBox, GtkButton
77- #label: create-archive (the name property is empty :( )
78- self.assertThat(lambda: self.app.select_single('GtkButton', label='create-archive'), Eventually(NotEquals(None)))
79- createButton = self.app.select_single('GtkButton', label='create-archive')
80- #let's click it
81- self.mouse.move_to_object(createButton)
82- self.mouse.click()
83- #delay to wait
84- sleep(2)
85-
86- #Click 'Add files to archive' button from toolbar
87- #FrWindow, GtkGrid, GtkToolButton
88- #name: 'Add_Toolbar'
89- self.assertThat(lambda: self.app.select_single('GtkToolButton', name='Add_Toolbar'), Eventually(NotEquals(None)))
90- addFilesButton = self.app.select_single('GtkToolButton', name='Add_Toolbar')
91- #let's click it
92- self.mouse.move_to_object(addFilesButton)
93- self.mouse.click()
94- #delay to wait
95- sleep(2)
96-
97- #Verify that the Add files dialog window has opened
98- #FrFileSelectorDialog
99- selectWindow = self.app.select_single('FrFileSelectorDialog')
100- self.assertThat(lambda: self.app.select_single('FrFileSelectorDialog').title, Eventually(Contains("Add Files")))
101-
102- #
103- # DOES NOT WORK !!!! ********************************************
104- #
105- #Select any files and/or folders to be added to the archive, click 'Add' button
106- #self.keyboard.press_and_release("Alt+l")
107- #self.keyboard.type("/usr/share/example-content/Ubuntu_Free_Culture_Showcase/How fast.ogg")
108- #
109- # DOES NOT WORK !!!! ********************************************
110- #
111-
112- #make a temporary file in the ~/ directory
113-# tempFile = _generateTempFileName()
114-# if os.path.exists("~/" + tempFile):
115- #just use that file
116-# sleep(1)
117-# else:
118- #create it
119-# f = open(tempfile, 'w')
120-# f.write("this is a test file for fileroller!")
121-# f.close
122-
123- self.keyboard.type("tmp")
124- self.keyboard.press_and_release("Enter")
125- self.keyboard.press_and_release("Space")
126-
127-
128- #FrFileSelectorDialog, GtkBox, GtkButtonBox, GtkButton, GtkAlignment, GtkBox, GtkLable
129- #label: _Add
130- self.assertThat(lambda: self.app.select_single('GtkLabel', label='_Add'), Eventually(NotEquals(None)))
131- addFolerButton = self.app.select_single('GtkLabel', label='_Add')
132- #let's click it
133- self.mouse.move_to_object(addFolerButton)
134- self.mouse.click()
135-
136- #Close the archive and file-roller
137- self.keyboard.press_and_release("Alt+a")
138- self.keyboard.type("c")
139-
140- #Open the archive using file-roller
141- super(GtkToolbarTests, self).setUp()
142- self.app = self.launch_test_application('file-roller')
143- #FrWindow, GtkGrid, GtkToolbar, GtkMenuToolButton, GTkBox, GtkButton, GtkBox, GtkImage
144- #stock: gtk-open
145- self.assertThat(lambda: self.app.select_single('GtkImage', stock='gtk-open'), Eventually(NotEquals(None)))
146- openRecentButton = self.app.select_single('GtkImage', stock='gtk-open')
147- #let's click it
148- self.mouse.move_to_object(openRecentButton)
149- self.mouse.click()
150- #delay to wait
151- sleep(2)
152- #GtkFileChooserDialog, GtkBox, GtkFileChooserWidget, GtkFileChooserDefault, GtkBox, GtkBox, GtkBox, GtkToggleButton, GtkAligmment, GtkBox, GtkImage
153- #stock: gtk-edit
154- self.assertThat(lambda: self.app.select_single('GtkImage', stock='gtk-edit'), Eventually(NotEquals(None)))
155- fileNameToggleButton = self.app.select_single('GtkImage', stock='gtk-edit')
156- #let's click it only if it is not already active
157- fileAttributeToggleBut = self.app.select_single('GtkToggleButton', tooltip_markup='Type a file name')
158- if self.assertProperty(fileAttributeToggleBut, active = False):
159- self.mouse.move_to_object(fileNameToggleButton)
160- self.mouse.click()
161- #delay to wait
162- sleep(2)
163- else:
164- self.keyboard.press_and_release("Alt+1")
165-
166- self.keyboard.type(tempFile)
167-
168- #GtkFileChooserDialog, GtkBox, GtkButtonBox, GtkButton, GtkAligmment, GtkBox, GtkImage
169- #stock: gtk-open
170- self.assertThat(lambda: self.app.select_single('GtkImage', stock='gtk-open'), Eventually(NotEquals(None)))
171- openFileButton = self.app.select_single('GtkImage', stock='gtk-open')
172- #let's click it
173- self.mouse.move_to_object(openFileButton)
174- self.mouse.click()
175- #delay to wait
176- sleep(2)
177-
178- # Click 'Extract' button from toolbar
179- #FrWindow, Gtkgrid, GtkToolBar, GtkMenuToolButton,
180- #name: Extract_ToolBar
181- self.assertThat(lambda: self.app.select_single('GtkMenuToolButton', name='Extract_ToolBar'), Eventually(NotEquals(None)))
182- extractFileButton = self.app.select_single('GtkMenuToolButton', name='Extract_ToolBar')
183- #let's click it
184- self.mouse.move_to_object(extractFileButton)
185- self.mouse.click()
186- #delay to wait
187- sleep(2)
188-
189- #Select any folder to extract files to, click 'Extract' button
190- self.keyboard.press_and_release("Alt+l")
191- self.keyboard.type(tempfile.gettempdir)
192- #GtkFileChooserDialog, GtkBox, GtkButtonBox, GtkButton, GtkAligmment, GtkBox, GtkImage
193- #stock: extract-archive
194- self.assertThat(lambda: self.app.select_single('GtkImage', stock='extract-archive'), Eventually(NotEquals(None)))
195- extractFileButton = self.app.select_single('GtkImage', stock='extract-archive')
196- #let's click it
197- self.mouse.move_to_object(extractFileButton)
198- self.mouse.click()
199- #delay to wait
200- sleep(2)
201-
202- #Wait until extracting process is complete
203- #'Extraction completed successfully' label appears
204- #GtkDialog, GtkBox, GtkHBox, GtkBox, GtkLabel
205- #label: <span weight="bold" size="larger">Extraction completed successfully</span>
206- selectWindow = self.app.select_single('GtkDialog')
207- self.assertThat(lambda: self.app.select_single('GtkLabel').label, Eventually(Contains("<span weight=""bold"" size=""larger"">Extraction completed successfully</span>")))
208-
209- #TODO
210- #Open Nautilus and navigate to the selected extract folder
211- #Are the files and folders from archive extracted correctly in the selected folder?
212-
213- #Delete the temp file we created
214- #Added sleep so file does not get removed too soon
215- sleep(1)
216- self.addCleanup(os.remove, tempFile + '.tar.gz')
217-
218-def _generateTempFileName():
219- #Create temporary file, then close it, so we can re-use the file name
220+ '''Set-up method'''
221+ super(FileRollerTests, self).setUp()
222+ self.app = self.launch_test_application('file-roller')
223+
224+ # only instantiate these once for multiple tests
225+ # these can only be instantiated here if you do not need to reload the application during a test
226+ # As the Gtk id's change when application is relaunched. and throws error
227+ # So for tests that are reloaded also grab new Gtkobject id's after relaunch
228+ self.pointing_device = Pointer(Mouse.create())
229+ self.archiveWindow = self.app.select_single('FrWindow')
230+ self.add_files_button = self.app.select_single('GtkLabel', label=u'Add Files')
231+ self.extract_button = self.app.select_single('GtkLabel', label=u'Extract')
232+ self.open_button = self.app.select_single('GtkLabel', label=u'Open')
233+ self.new_archive_button = self.app.select_single('GtkToolButton', name=u'New')
234+
235+ def test_create_archive(self):
236+ '''Creates an archive and adds sample data, Window title must contain archive name'''
237+
238+ tempArchive = _tempArchiveName()
239+ #Test: Archive must be created with sample data
240+ self.create_archive_with_sample_data(tempArchive)
241+ # If create archive successfull, then check here that the window title
242+ # is the name of the archive.
243+ (dirName, fileName) = os.path.split(tempArchive)
244+ self.assertThat(self.archiveWindow.title, Eventually(Contains(fileName)))
245+
246+ #Cleanup
247+ self.delete_temp_archive()
248+
249+
250+
251+ def test_open_archive(self):
252+ '''Open archive window title must contains the archive name '''
253+
254+ tempArchive = _tempArchiveName()
255+ # Call create and relaunch to get a safe way of reloading an application
256+ self.create_and_relaunch(tempArchive)
257+
258+ #Test: Must open archive
259+ self.open_test_archive(tempArchive)
260+ # if open archive successful, then check here that the window title
261+ # is the name of the archive.
262+ (dirName, fileName) = os.path.split(tempArchive)
263+ self.assertThat(self.archiveWindow.title, Eventually(Contains(fileName)))
264+ # Cleanup
265+ self.delete_temp_archive()
266+
267+ def test_extract_archive(self):
268+ '''Open archive and extract file'contents,'''
269+
270+ tempArchive = _tempArchiveName()
271+ # Call create and relaunch to get a safe way of reloading an application
272+ self.create_and_relaunch(tempArchive)
273+ self.assertThat(self.archiveWindow.title, Eventually(Contains('Archive Manager')))
274+ #Test: Open and extract an archive
275+ self.extract_test_archive(tempArchive)
276+ ## assert we have come back to main window after extraction
277+ ## Test Will not get back to mainWindow if extraction failed.
278+ ## Check window title is same as archive
279+ (dirName, fileName) = os.path.split(tempArchive)
280+ self.assertThat(self.archiveWindow.title, Eventually(Contains(fileName)))
281+ #Cleanup
282+ self.delete_temp_archive()
283+ self.delete_temp_directory(fileName)
284+
285+ # this method needs some more assertions. At the moment its relying that commands are correct
286+ def create_archive_with_sample_data(self, tempArchive):
287+ ''' Must create archive and add sample data'''
288+ #Click on the new archive button
289+ self.pointing_device.move_to_object(self.new_archive_button)
290+ self.pointing_device.click()
291+ # The new archive dialog window title must have 'New Archive'
292+ self.new_dialog = self.app.select_single('FrNewArchiveDialog')
293+ self.assertThat(self.new_dialog.title, Eventually(Equals(u'New Archive')))
294+
295+ #Enter name of new archive
296+ self.keyboard.type(tempArchive)
297+
298+ # TODO: Figure out a gzip commpress, does not have an active Id enabled
299+
300+ # select the create button and check it is clickable
301+ self.create_button = self.app.select_single('GtkButton', label=u'create-archive')
302+ self.assertThat(self.create_button.label, Eventually(NotEquals(None)))
303+ # Click on Create button
304+ self.pointing_device.move_to_object(self.create_button)
305+ self.pointing_device.click()
306+ # Click on the add files button
307+ self.pointing_device.move_to_object(self.add_files_button)
308+ self.pointing_device.click()
309+ # The add files dialog title must contain 'Add Files'
310+ self.add_files_dialog = self.app.select_single('FrFileSelectorDialog')
311+ self.assertThat(self.add_files_dialog.title, Eventually(Equals('Add Files')))
312+
313+ # This is a horrible hacky workaround to add sample files from /usr/share/example-content/*
314+ # Need to find a better workaround :S Location GtkEntry doesnt work when entering file path
315+ # Maybe add some assertions to check that the Location GTKEntry contains correct path
316+ self.keyboard.press_and_release("Alt+l")
317+ self.keyboard.press_and_release("Tab")
318+ self.keyboard.press_and_release("Tab")
319+ self.keyboard.type("File")
320+ self.keyboard.press_and_release("Enter")
321+ self.keyboard.press_and_release("Tab")
322+ self.keyboard.press_and_release("Right")
323+ self.keyboard.press_and_release("Right")
324+ self.keyboard.type("usr")
325+ self.keyboard.press_and_release("Enter")
326+ self.keyboard.type("share")
327+ self.keyboard.press_and_release("Enter")
328+ self.keyboard.type("example-content")
329+ self.keyboard.press_and_release("Enter")
330+ self.keyboard.press_and_release("Left")
331+ self.keyboard.press_and_release("Left")
332+ self.keyboard.press_and_release("Enter")
333+ # We must be able to click the '_Add' button
334+ self.add_folder_button = self.app.select_single('GtkLabel', label=u'_Add')
335+ self.assertThat(self.add_folder_button.label, Eventually(NotEquals(None)))
336+ #Click the '_Add" button
337+ self.pointing_device.move_to_object(self.add_folder_button)
338+ self.pointing_device.click()
339+ # sleep needed to give sample data enough time to be added
340+ sleep(3)
341+
342+ # Method for opening an archive, needs assertions adding
343+ def open_test_archive(self, tempArchive):
344+ '''Open the test archive'''
345+ self.open_button = self.app.select_single('GtkLabel', label=u'Open')
346+ self.pointing_device.move_to_object(self.open_button)
347+ self.pointing_device.click()
348+
349+ self.keyboard.press_and_release("Alt+l")
350+ self.keyboard.type(tempArchive)
351+ #self.keyboard.press_and_release("Enter")
352+
353+ self.open_archive_button = self.app.select_single('GtkLabel', label=u'_Open')
354+ self.pointing_device.move_to_object(self.open_archive_button)
355+ self.pointing_device.click()
356+
357+ def extract_test_archive(self, tempArchive):
358+ '''Open Archive and extract the sample data'''
359+
360+ self.open_test_archive(tempArchive)
361+ (dirName, fileName) = os.path.split(tempArchive)
362+
363+ self.assertThat(self.archiveWindow.title, Eventually(Contains(fileName)))
364+
365+ # Check that the Extract button is now clickable
366+ self.assertThat(self.extract_button.label, Eventually(NotEquals(None)))
367+
368+ #click on extract button
369+ self.pointing_device.move_to_object(self.extract_button)
370+ self.pointing_device.click()
371+
372+ self.keyboard.press_and_release("Alt+l")
373+ self.keyboard.type(tempArchive)
374+
375+ self.extract_archive_button = self.app.select_single('GtkLabel', label=u'_Extract')
376+ self.assertThat(self.extract_archive_button.label, Eventually(NotEquals(None)))
377+
378+ self.pointing_device.move_to_object(self.extract_archive_button)
379+ self.pointing_device.click()
380+ sleep(2)
381+ self.extract_dialog = self.app.select_single('GtkDialog')
382+ self.assertThat(self.extract_dialog.title, Eventually(Contains(u"")))
383+ self.show_files_button = self.app.select_single('GtkLabel', label=u'_Show the Files')
384+ self.assertThat(self.show_files_button.label, Eventually(NotEquals(None)))
385+
386+ self.pointing_device.move_to_object(self.show_files_button)
387+ self.pointing_device.click()
388+
389+ sleep(2)
390+
391+ self.keyboard.press_and_release("Alt+F4")
392+
393+ def create_and_relaunch(self, tempArchive):
394+ ''' This method calls create archive_with_sample_data
395+ then will close the application and relaunch it
396+ grabbing new Gtk object id's'''
397+ # Create archive and check window title
398+ self.create_archive_with_sample_data(tempArchive)
399+ (dirName, fileName) = os.path.split(tempArchive)
400+
401+ self.assertThat(self.archiveWindow.title, Eventually(Contains(fileName)))
402+ # Close the Application
403+ self.keyboard.press_and_release('Ctrl+w')
404+ # launch a new instance of fire-roller
405+ self.app = self.launch_test_application('file-roller')
406+ # We need to get the new object id's here as we have reloaded the application and
407+ # will throw an error unknown id if we don't :)
408+ self.archiveWindow = self.app.select_single('FrWindow')
409+ self.add_files_button = self.app.select_single('GtkLabel', label=u'Add Files')
410+ self.extract_button = self.app.select_single('GtkLabel', label=u'Extract')
411+ self.open_button = self.app.select_single('GtkLabel', label=u'Open')
412+ self.new_archive_button = self.app.select_single('GtkToolButton', name=u'New')
413+
414+ def delete_temp_archive(self):
415+ # Cleanup
416+ temp = self.archiveWindow.title
417+ # Strip archive name of whitespace
418+ temp = temp.strip()
419+ path = os.path.join('/tmp/'+temp)
420+ self.addCleanup(os.unlink, path)
421+
422+ def delete_temp_directory(self, fileName ):
423+ #Delete the extracted directory
424+ extract_path = os.path.join('/tmp/'+ fileName)
425+ self.addCleanup(shutil.rmtree, extract_path)
426+
427+
428+#hardcoded global archiveName
429+def _tempArchiveName():
430+ '''Temporary archive name for testing with.'''
431 sFile = tempfile.NamedTemporaryFile()
432 sFile.close()
433 return sFile.name

Subscribers

People subscribed via source and target branches