Merge lp:~carla-sella/ubuntu-autopilot-tests/screenshot-1-3 into lp:ubuntu-autopilot-tests

Proposed by Carla Sella
Status: Merged
Merged at revision: 48
Proposed branch: lp:~carla-sella/ubuntu-autopilot-tests/screenshot-1-3
Merge into: lp:ubuntu-autopilot-tests
Diff against target: 273 lines (+150/-89)
1 file modified
ubuntu_autopilot_tests/screenshot/test_screenshot.py (+150/-89)
To merge this branch: bzr merge lp:~carla-sella/ubuntu-autopilot-tests/screenshot-1-3
Reviewer Review Type Date Requested Status
Nicholas Skaggs (community) Approve
Review via email: mp+168150@code.launchpad.net

Description of the change

Screenshot test with 'drop shadow' bit dropped as cannot get it to work.
Test should be complete now.

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

yaya! this is finally ready. Thanks Carla.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntu_autopilot_tests/screenshot/test_screenshot.py'
2--- ubuntu_autopilot_tests/screenshot/test_screenshot.py 2013-01-14 19:50:12 +0000
3+++ ubuntu_autopilot_tests/screenshot/test_screenshot.py 2013-06-07 19:06:28 +0000
4@@ -1,118 +1,179 @@
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+from autopilot.process import ProcessManager
10+from autopilot.input import Mouse, Pointer
11
12 from time import sleep
13 import tempfile
14 import os
15-
16-
17-#Register Screenshot as an application so we can call it
18-AutopilotTestCase.register_known_application("Screenshot", "gnome-screenshot.desktop", "gnome-screenshot")
19+import shutil
20
21 #http://packages.qa.ubuntu.com/qatracker/testcases/1421/info
22 class ScreenshotTests(AutopilotTestCase):
23
24 def setUp(self):
25 super(ScreenshotTests, self).setUp()
26- self.app = self.start_app_window("Screenshot")
27-
28- #Make sure screenshot window you launched is focused and ready to accept your keyboard input
29- self.app.set_focus()
30- self.assertTrue(self.app.is_focused)
31-
32-
33+ self.app = self.launch_test_application("gnome-screenshot", "-i")
34+
35+ # only instantiate these once for multiple tests
36+ self.pointing_device = Pointer(Mouse.create())
37+ self.archiveWindow = self.app.select_single('GtkDialog')
38+
39+ #verify window title: Take Screenshot to verify Screenshot is correclty opened
40+ self.assertThat(self.archiveWindow.title, Eventually(Contains('Take Screenshot')))
41+
42+ self.take_screenshot_button = self.app.select_single('GtkLabel', label='Take _Screenshot')
43+ self.grab_whole_screen_rb = self.app.select_single('GtkRadioButton', label='Grab the whole sc_reen')
44+ self.grab_curr_window_rb = self.app.select_single('GtkRadioButton', label='Grab the current _window')
45+ self.select_grab_area_rb=self.app.select_single('GtkRadioButton', label='Select _area to grab')
46+ self.incl_win_border=self.app.select_single('GtkCheckButton', label='Include the window _border')
47+## self.drop_shadow_effect_shadow=self.app.select_single('GtkComboBoxAccessible', accessible_name='shadow')
48+## self.drop_shadow_effect_none=self.app.select_single('GtkComboBoxAccessible', accessible_name='none')
49+## self.drop_shadow_effect_border=self.app.select_single('GtkComboBoxAccessible', accessible_name='border')
50+
51+ #potentially useful objects
52+ #self.border_effect=self.app.select_single('GtkComboBoxAccessible', accessible_name='border')
53+ #self.no_effect=self.app.select_single('GtkComboBoxAccessible', accessible_name='none')
54+ #self.app.select_single('GtkLabel', label='Grab after a _delay of')
55+ #self.app.select_single('GtkCheckButton', label='Include _pointer')
56+ #self.app.select_single('GtkToggleButtonAccessible', accessible_name='Include pointer')
57+ #self.app.select_single('GtkToggleButtonAccessible', accessible_name='Include the window border')
58+ #self.app.select_single('GtkMenuItemAccessible', accessible_name='Drop shadow')
59+ #self.app.select_single('GtkLabel', label='Apply _effect:')
60+ #self.app.select_single('GtkLabelAccessible', accessible_name='Apply effect:')
61+
62 def test_whole_screen(self):
63 #Test-case name: gnomescreenshot/gns-001
64 #This test will check that Gnome Screenshot can save screenshot of the whole screen
65- tempFile = "/tmp/shot1.png"
66-
67- #Press Alt+s to Grab the whole desktop
68- self.keyboard.press_and_release("Alt+s")
69-
70- sleep(5)
71-
72- #Make sure screenshot window you launched is focused and ready to accept your keyboard input
73- #self.app.set_focus()
74- #self.assertTrue(self.app.is_focused)
75-
76- #Press Alt+n to focus on Name field
77- #self.keyboard.press_and_release("Alt+n")
78-
79- #Name it shot1.png
80- #self.keyboard.press_and_release("Ctrl+a")
81- self.keyboard.type(tempFile)
82-
83- #Press Alt+s to save image
84- self.keyboard.press_and_release("Alt+s")
85-
86- #Is the screenshot image saved to your home directory? Is it a valid image file containing your screen?
87+
88+ #Grab the whole desktop
89+ #Select Grab Whole Screen radio button and click on it
90+ self.pointing_device.move_to_object(self.grab_whole_screen_rb)
91+ self.pointing_device.click()
92+
93+ #Select Take screenshot button and click it
94+ self.click_take_screenshot()
95+
96+ #verify take screenshot window opens
97+ tempArchive = _tempArchiveName()
98+ (dirName, fileName) = os.path.split(tempArchive)
99+ self.save_screenshot_file(fileName)
100+
101+ #Is the screenshot image saved to the /tmp directory? Is it a valid image file containing your screen?
102 #verify it's a non-zero file
103- self.assertTrue(os.stat(tempFile).st_size>0)
104-
105- #Remove created file
106- self.addCleanup(os.remove, tempFile)
107-
108+ self.verify_non_zero_file(fileName)
109+
110+ #Cleanup
111+ self.delete_temp_file(tempArchive)
112
113 def test_selected_window(self):
114 #Test-case name: gnomescreenshot/gns-002
115 #This test will check that Gnome Screenshot can save screenshot of selected window
116
117 #Select Grab the current window
118- self.keyboard.press_and_release("Alt+w")
119-
120- #Make sure screenshot window you launched is focused and ready to accept your keyboard input
121- self.app.set_focus()
122- self.assertTrue(self.app.is_focused)
123-
124- #Press Alt+n to focus on Name field
125- self.keyboard.press_and_release("Alt+n")
126-
127-
128- #Name it shot2.png
129- self.keyboard.type("/tmp/shot2.png")
130-
131- #Is the screenshot image saved to your home directory? Is it a valid image file containing your selected window?
132-
133- #Remove created file
134- self.addCleanup(os.remove, "/tmp/shot2.png")
135-
136-
137- def test_drop_shadow(self):
138+ self.pointing_device.move_to_object(self.grab_curr_window_rb)
139+ self.pointing_device.click()
140+ #Select Take screenshot button and click it
141+ self.click_take_screenshot()
142+
143+ #verify take screenshot window opens
144+ tempArchive = _tempArchiveName()
145+ (dirName, fileName) = os.path.split(tempArchive)
146+ self.save_screenshot_file(fileName)
147+
148+ #Is the screenshot image saved to the /tmp directory? Is it a valid image file containing your screen?
149+ #verify it's a non-zero file
150+ self.verify_non_zero_file(fileName)
151+
152+ #Cleanup
153+ self.delete_temp_file(tempArchive)
154+
155+ def test_drop_shadow_effect(self):
156 #Test-case name: gnomescreenshot/gns-003
157 #This test will check that Gnome Screenshot can save screenshot of selected window
158-
159+
160 #Select Grab the current window
161- self.keyboard.press_and_release("Alt+w")
162-
163- #Select Drop shadow from the Apply effect drop down menu
164- self.keyboard.press_and_release("Alt+b")
165-
166+ self.pointing_device.move_to_object(self.grab_curr_window_rb)
167+ self.pointing_device.click()
168+
169 #Verify the "Include the window border" box is selected
170-
171- self.keyboard.press_and_release("Down")
172- self.keyboard.press_and_release("Down")
173-
174- #Verify the "Drop shadow" is selected
175- self.keyboard.press_and_release("Alt+s")
176-
177+ if self.incl_win_border.active == 0:
178+ self.pointing_device.move_to_object(self.incl_win_border)
179+ self.pointing_device.click()
180+ self.assertThat(lambda: self.incl_win_border.active, Eventually(Equals(1)))
181+
182+## #Select Drop shadow from the Apply effect drop down menu
183+## if self.drop_shadow_effect_none.enabled == 'True':
184+## self.pointing_device.move_to_object(self.drop_shadow_effect_none)
185+## elif self.drop_shadow_effect_shadow.enabled == 'True':
186+## self.pointing_device.move_to_object(self.drop_shadow_effect_shadow)
187+## else:
188+## self.pointing_device.move_to_object(self.drop_shadow_effect_border)
189+## self.pointing_device.click()
190+## self.keyboard.press_and_release('Down')
191+## self.keyboard.type('\n')
192+## self.pointing_device.click()
193+## self.pointing_device.click()
194+
195+## #Verify the "Drop shadow" is selected
196+### don't use these assertions
197+### self.assertThat(lambda: self.drop_shadow_effect.selected, Eventually(Equals(True)))
198+### self.assertThat(lambda: self.drop_shadow_effect.focused, Eventually(Equals(True)))
199+## self.assertThat(lambda: self.drop_shadow_effect.enabled, Eventually(Equals(True)))
200+
201+ #Select Take screenshot button and click it
202+ self.click_take_screenshot()
203+
204 #Make sure screenshot window you launched is focused and ready to accept your keyboard input
205- self.app.set_focus()
206- self.assertTrue(self.app.is_focused)
207-
208- #Press Alt+n to focus on Name field
209- self.keyboard.press_and_release("Alt+n")
210-
211- #Name it shot2.png
212- self.keyboard.type("/tmp/shot2.png")
213-
214- #Is the screenshot image saved to your home directory? Is it a valid image file containing your selected window, with the drop shadow effect?
215-
216- #Remove created file
217- self.addCleanup(os.remove, "/tmp/shot2.png")
218-
219-def _generateTempFileName():
220- #Create temporary file, then close it, so we can re-use the file name
221+ tempArchive = _tempArchiveName()
222+ (dirName, fileName) = os.path.split(tempArchive)
223+ self.save_screenshot_file(fileName)
224+
225+ #Is the screenshot image saved to the /tmp directory? Is it a valid image file containing your screen?
226+ #verify it's a non-zero file
227+ self.verify_non_zero_file(fileName)
228+
229+ #Cleanup
230+ self.delete_temp_file(tempArchive)
231+
232+ def save_screenshot_file(self, fileName):
233+ check_fn = lambda: self.app.select_single('GtkDialog', title='Save Screenshot')
234+ self.assertThat(check_fn, Eventually(NotEquals(None)))
235+ #select everything so to cancel old file name
236+ self.keyboard.press_and_release('Ctrl+a')
237+ self.keyboard.type(fileName)
238+ self.keyboard.type('.png')
239+ #select /tmp folder
240+ self.save_in_folder_button=self.app.select_single('GtkFileChooserButton', title='Select a folder')
241+ self.pointing_device.move_to_object(self.save_in_folder_button)
242+ self.pointing_device.click()
243+ #get to "other"
244+ self.keyboard.press_and_release('End')
245+ #save in the tmp folder
246+ self.keyboard.type("\n/tmp\n")
247+ #Save screenshot
248+ self.save_button=self.app.select_single('GtkLabel', label='_Save')
249+ self.pointing_device.move_to_object(self.save_button)
250+ self.pointing_device.click()
251+
252+ def verify_non_zero_file(self,fileName):
253+ self.assertThat(lambda: os.path.isfile('/tmp/'+fileName+'.png'), Eventually(Equals(True)))
254+ self.assertThat(lambda: os.stat('/tmp/'+ fileName+'.png').st_size, Eventually(NotEquals(0)))
255+
256+ def delete_temp_file(self, tempArchive):
257+ #Delete the screenshot file
258+ self.addCleanup(os.unlink, tempArchive+'.png')
259+
260+ def click_take_screenshot(self):
261+ #click on take screenshot button
262+ self.pointing_device.move_to_object(self.take_screenshot_button)
263+ self.pointing_device.click()
264+
265+
266+#Create temporary file name
267+def _tempArchiveName():
268+ '''Temporary archive name.'''
269 sFile = tempfile.NamedTemporaryFile()
270 sFile.close()
271- return sFile.name
272+ return sFile.name
273\ No newline at end of file

Subscribers

People subscribed via source and target branches