~adam-disc0tech/ubuntu-autopilot-tests/test-runner

« back to all changes in this revision

Viewing changes to ubuntu_autopilot_tests/terminal/test_terminal.py

  • Committer: nskaggs
  • Date: 2013-07-30 18:31:48 UTC
  • mfrom: (56.1.3 terminal)
  • Revision ID: nicholas.skaggs@canonical.com-20130730183148-b70y7d85fc81gyxn
Add Dan's terminal test

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from autopilot.testcase import AutopilotTestCase
 
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
 
2
#
 
3
# Copyright (C) 2013
 
4
#
 
5
# Author: Daniel Chapman daniel@chapman-mail.com
 
6
#
 
7
# This program is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU Lesser General Public License as published by
 
9
# the Free Software Foundation; version 3.
 
10
#
 
11
# This program is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
14
# GNU Lesser General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU Lesser General Public License
 
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
18
import os
 
19
import shutil
 
20
import tempfile
2
21
from autopilot.matchers import Eventually
3
 
from testtools.matchers import Equals, Contains
4
 
from autopilot.process import ProcessManager
5
 
 
6
 
import tempfile
7
 
import os
8
 
 
9
 
#http://packages.qa.ubuntu.com/qatracker/testcases/1422/info
10
 
class TerminalTests(AutopilotTestCase):
11
 
 
12
 
    def setUp(self):
13
 
        super(TerminalTests, self).setUp()
14
 
        self.proc_manager = ProcessManager.create('BAMF')
15
 
        self.app = self.proc_manager.start_app_window("Terminal")
16
 
 
17
 
        #Make sure terminal window you launched is focused and ready to accept your keyboard input
18
 
        self.app.set_focus()
19
 
        self.assertTrue(self.app.is_focused)
20
 
 
 
22
from testtools.matchers import Equals, Contains, FileExists, DirExists, DirContains
 
23
from terminal import TerminalAutopilotTestCase
 
24
 
 
25
 
 
26
class TerminalFileSystemTests(TerminalAutopilotTestCase):
21
27
 
22
28
    def test_save_a_file(self):
23
 
        #Test-case name: gnometerminal/ter-001
24
 
        #This test will check that basic terminal commands work in Gnome Terminal
25
 
 
26
 
        #Type a command
27
29
        self.keyboard.type("touch /tmp/test-file\n")
28
 
 
29
30
        #Verify that test-file has been created
30
 
 
31
 
 
32
 
        #Enter ls -al
33
 
        self.keyboard.type("ls -al /tmp\n")
34
 
 
35
 
        #Verify output
36
 
 
37
 
 
38
 
        #Press up arrow
39
 
        self.keyboard.press_and_release("Up")
40
 
 
41
 
        #Verify output you ran the same command you ran previously
42
 
 
 
31
        self.assertTrue('/tmp/testfile', FileExists())
43
32
        #Delete the file we created
44
33
        self.addCleanup(os.remove, "/tmp/test-file")
45
34
 
46
 
 
47
 
 
48
 
    def test_change_colors(self):
49
 
        #Test-case name: gnometerminal/ter-002
50
 
        #This test will check that terminal colors and zoom level can be changed
51
 
 
52
 
        #Press Alt+e to open "Edit" menu
53
 
        self.keyboard.press_and_release("Alt+e", delay=0.5)
54
 
 
55
 
        #Press "o" to open "Profiles"
56
 
        self.keyboard.press_and_release("o")
57
 
 
58
 
        #Press right arrow  twice for  "colors" tab
59
 
        self.keyboard.press_and_release("Right")
60
 
        self.keyboard.press_and_release("Right")
61
 
 
62
 
        #Change built in themes
63
 
        self.keyboard.press_and_release("Tab")
64
 
        self.keyboard.type("\n", delay=1)
65
 
        self.keyboard.press_and_release("Tab")
66
 
        self.keyboard.press_and_release("Down")
67
 
        self.keyboard.press_and_release("Down")
68
 
        self.keyboard.press_and_release("Down")
69
 
        self.keyboard.press_and_release("Down")
70
 
        self.keyboard.press_and_release("Down", delay=0.3)
71
 
 
72
 
        #Verify colors have changed
73
 
 
74
 
        #Put configuration back as it was
75
 
        self.keyboard.press_and_release("Up")
76
 
        self.keyboard.press_and_release("Up")
77
 
        self.keyboard.press_and_release("Up")
78
 
        self.keyboard.press_and_release("Up")
79
 
        self.keyboard.press_and_release("Up")
80
 
 
81
 
 
82
 
        #Change text color
83
 
        self.keyboard.press_and_release("Tab")
84
 
        self.keyboard.type("\n")
85
 
        self.keyboard.type("\n")
86
 
        self.keyboard.press_and_release("Alt+s")
87
 
 
88
 
        #Verify text color has changed
89
 
 
90
 
 
91
 
        #Put text color back as it was
92
 
        self.keyboard.type("\n", delay=1)
93
 
        self.keyboard.press_and_release("Down")
94
 
        self.keyboard.press_and_release("Down")
95
 
        self.keyboard.press_and_release("Down")
96
 
        self.keyboard.type("\n")
97
 
        self.keyboard.press_and_release("Alt+s")
98
 
        self.keyboard.press_and_release("Shift+Tab")
99
 
        self.keyboard.press_and_release("Shift+Tab")
100
 
        self.keyboard.type("\n")
101
 
 
102
 
        #Set a Background Image
103
 
        self.keyboard.press_and_release("Shift+Tab")
104
 
        self.keyboard.press_and_release("Right")
105
 
        self.keyboard.press_and_release("Alt+b")
106
 
        self.keyboard.press_and_release("Alt+f")
107
 
        self.keyboard.press_and_release("Space")
108
 
        self.keyboard.type("/usr/share/backgrounds/Leftover_by_Sagar_Jain.jpg")
109
 
        self.keyboard.press_and_release("Alt+o")
110
 
        self.keyboard.press_and_release("Tab")
111
 
        self.keyboard.press_and_release("Tab")
112
 
        self.keyboard.press_and_release("Space")
113
 
 
114
 
        #Verify Terminal background changes
115
 
 
116
 
 
117
 
        #Put Terminal background back as it was
118
 
        self.keyboard.press_and_release("Alt+s")
119
 
        self.keyboard.press_and_release("Space", delay=0.2)
120
 
 
121
 
        #Close Profile preferences window
122
 
        self.keyboard.press_and_release("Alt+c")
123
 
 
124
 
        #Change the Zoom Level
125
 
        self.keyboard.press_and_release("Ctrl+plus")
126
 
        self.keyboard.press_and_release("Ctrl+plus")
127
 
        self.keyboard.press_and_release("Ctrl+plus")
128
 
        self.keyboard.press_and_release("Ctrl+plus")
129
 
        self.keyboard.press_and_release("Ctrl+-")
130
 
        self.keyboard.press_and_release("Ctrl+-")
131
 
 
132
 
        #Verify zoom level has changed
133
 
 
134
 
 
135
 
        #Put Zoom level back as it was
136
 
        self.keyboard.press_and_release("Ctrl+0")
137
 
 
138
 
 
139
 
    def test_terminal_coloring(self):
140
 
        #Test-case name: gnometerminal/ter-003
141
 
        #This test will check that terminal coloring is active
142
 
 
143
 
        #Type in touch /tmp/text1.txt
144
 
        self.keyboard.type("touch /tmp/text1.txt\n")
145
 
 
146
 
        #Type in ls
147
 
        self.keyboard.type("ls /tmp\n")
148
 
 
149
 
        #Verify txt is in black
150
 
 
151
 
 
152
 
        #Type in chmod 777 text1.txt
153
 
        self.keyboard.type("chmod 777 /tmp/text1.txt\n")
154
 
 
155
 
        #Type in ls
156
 
        self.keyboard.type("ls /tmp\n")
157
 
 
158
 
 
159
 
        #Verify txt should now be green
160
 
 
161
 
        #Delete the file we created
162
 
        self.addCleanup(os.remove, "/tmp/text1.txt")
163
 
 
164
 
 
165
 
    def test_launch_terminal(self):
166
 
        #Test-case name: gnometerminal/ter-004
167
 
        #This test will check that the terminal tab launches succesfully
168
 
 
169
 
 
170
 
        #Open Terminal using the dash, and typing 'terminal'
171
 
        self.keyboard.press_and_release("Super")
172
 
        self.keyboard.type("terminal\n")
173
 
 
174
 
        #Is an instance of gnome-terminal with the title '@: ~' opened, with the current directory set to the users home directory?
175
 
 
176
 
 
177
 
        #Close opened terminal
178
 
        self.keyboard.press_and_release("Ctrl+d", delay=0.2)
179
 
 
180
 
        #Press Ctrl+Alt+T
181
 
        self.keyboard.press_and_release("Ctrl+Alt+t")
182
 
 
183
 
        #Is an instance of gnome-terminal with the title '@: ~' opened, with the current directory set to the users home directory?
184
 
 
185
 
 
186
 
        #Close opened terminal
187
 
        self.keyboard.press_and_release("Ctrl+d")
188
 
        self.keyboard.press_and_release("Ctrl+d")
189
 
        #Had to put two Ctrl+d's as the first one closes the terminal that opens with the launch of this test
190
 
 
191
 
 
192
 
    def test_new_title(self):
193
 
        #Test-case name: gnometerminal/ter-005
194
 
        #This test will check that the terminal can be given a new title
195
 
 
196
 
        #From the main menu select 'Terminal > Set Title...'
197
 
        self.keyboard.press_and_release("Alt+t", delay=0.5)
198
 
        self.keyboard.press_and_release("s", delay=0.5)
199
 
 
200
 
        #Verify the Set Title dialog appears
201
 
        #Check to see that the title of the window is "Set Title"
202
 
        #self.assertThat(lambda: self.app.title, Eventually(Contains("Set Title")))
203
 
        
204
 
 
205
 
        #Enter 'Test Title' and click OK
206
 
        self.keyboard.type("Test Title")
207
 
        self.keyboard.press_and_release("Alt+o")
208
 
 
209
 
        #Is the title of the window now 'Test Title'?
210
 
        #Check to see that the title reflects our 'Test Title'
211
 
        self.assertThat(lambda: self.app.name, Eventually(Contains("Test Title")))
212
 
 
213
 
def _generateTempFileName():
214
 
    #Create temporary file, then close it, so we can re-use the file name
215
 
    sFile = tempfile.NamedTemporaryFile()
216
 
    sFile.close()
217
 
    return sFile.name
218
 
 
219
 
 
 
35
    def test_create_directory(self):
 
36
        self.keyboard.type('mkdir /tmp/temp-dir\n')
 
37
        self.assertTrue('/tmp/temp-dir/', DirExists())
 
38
        self.addCleanup(os.removedirs, '/tmp/temp-dir')
 
39
 
 
40
    def test_directory_contains_files(self):
 
41
        self.create_temp_directory_with_temp_files()
 
42
        self.assertTrue('/tmp/temp-dir/', DirContains(['a', 'b', 'c']))
 
43
        self.addCleanup(shutil.rmtree, '/tmp/temp-dir')
 
44
 
 
45
    def test_move_directory_with_files(self):
 
46
        self.create_temp_directory_with_temp_files()
 
47
        #create directory to move to
 
48
        self.keyboard.type('mkdir /tmp/temp-dir2\n')
 
49
        #move temp-dir to temp-dir2
 
50
        self.keyboard.type('mv /tmp/temp-dir/ /tmp/temp-dir2/\n')
 
51
        #assert dir moved
 
52
        self.assertTrue('/tmp/temp-dir2/temp-dir/', DirExists())
 
53
        ##assert files moved
 
54
        self.assertTrue('/tmp/temp-dir2/temp-dir/', DirContains(['a', 'b', 'c']))
 
55
 
 
56
        self.addCleanup(shutil.rmtree, '/tmp/temp-dir2')
 
57
 
 
58
    def test_copying_file(self):
 
59
        self.create_temp_directory_with_temp_files()
 
60
        #create directory to move to
 
61
        self.keyboard.type('mkdir /tmp/temp-dir2\n')
 
62
        #move file 'a' to temp-dir2
 
63
        self.keyboard.type('cp /tmp/temp-dir/a /tmp/temp-dir2/\n')
 
64
        ##assert file moved
 
65
        self.assertTrue('/tmp/temp-dir2/temp-dir/', DirContains(['a']))
 
66
        self.addCleanup(shutil.rmtree, '/tmp/temp-dir')
 
67
        self.addCleanup(shutil.rmtree, '/tmp/temp-dir2')
 
68
 
 
69
 
 
70
class TerminalWindowTests(TerminalAutopilotTestCase):
 
71
 
 
72
    def test_window_visible(self):
 
73
        terminal_window = self.app.select_single('TerminalWindow')
 
74
        self.assertThat(terminal_window.visible, Eventually(Equals(1)))
 
75
 
 
76
    def test_window_title(self):
 
77
        terminal_window = self.app.select_single('TerminalWindow')
 
78
        self.assertThat(terminal_window.title, Eventually(Contains('~')))
 
79
 
 
80
    def test_window_title_changes_when_changing_directory(self):
 
81
        terminal_window = self.app.select_single('TerminalWindow')
 
82
        self.keyboard.type('cd\n')
 
83
        self.keyboard.type('cd Documents\n')
 
84
        self.assertThat(terminal_window.title, Eventually(Contains('~/Documents')))
 
85
 
 
86
    def test_open_new_tab(self, ):
 
87
        #open a new tab
 
88
        self.keyboard.press_and_release('Ctrl+Shift+t')
 
89
        # test number of tabs(containers) equals 2
 
90
        tabs = self.app.select_many('TerminalScreenContainer')
 
91
        self.assertThat(len(tabs), Equals(2))
220
92