1
from autopilot.testcase import AutopilotTestCase
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
5
# Author: Daniel Chapman daniel@chapman-mail.com
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.
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.
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/>.
2
21
from autopilot.matchers import Eventually
3
from testtools.matchers import Equals, Contains
4
from autopilot.process import ProcessManager
9
#http://packages.qa.ubuntu.com/qatracker/testcases/1422/info
10
class TerminalTests(AutopilotTestCase):
13
super(TerminalTests, self).setUp()
14
self.proc_manager = ProcessManager.create('BAMF')
15
self.app = self.proc_manager.start_app_window("Terminal")
17
#Make sure terminal window you launched is focused and ready to accept your keyboard input
19
self.assertTrue(self.app.is_focused)
22
from testtools.matchers import Equals, Contains, FileExists, DirExists, DirContains
23
from terminal import TerminalAutopilotTestCase
26
class TerminalFileSystemTests(TerminalAutopilotTestCase):
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
27
29
self.keyboard.type("touch /tmp/test-file\n")
29
30
#Verify that test-file has been created
33
self.keyboard.type("ls -al /tmp\n")
39
self.keyboard.press_and_release("Up")
41
#Verify output you ran the same command you ran previously
31
self.assertTrue('/tmp/testfile', FileExists())
43
32
#Delete the file we created
44
33
self.addCleanup(os.remove, "/tmp/test-file")
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
52
#Press Alt+e to open "Edit" menu
53
self.keyboard.press_and_release("Alt+e", delay=0.5)
55
#Press "o" to open "Profiles"
56
self.keyboard.press_and_release("o")
58
#Press right arrow twice for "colors" tab
59
self.keyboard.press_and_release("Right")
60
self.keyboard.press_and_release("Right")
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)
72
#Verify colors have changed
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")
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")
88
#Verify text color has changed
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")
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")
114
#Verify Terminal background changes
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)
121
#Close Profile preferences window
122
self.keyboard.press_and_release("Alt+c")
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+-")
132
#Verify zoom level has changed
135
#Put Zoom level back as it was
136
self.keyboard.press_and_release("Ctrl+0")
139
def test_terminal_coloring(self):
140
#Test-case name: gnometerminal/ter-003
141
#This test will check that terminal coloring is active
143
#Type in touch /tmp/text1.txt
144
self.keyboard.type("touch /tmp/text1.txt\n")
147
self.keyboard.type("ls /tmp\n")
149
#Verify txt is in black
152
#Type in chmod 777 text1.txt
153
self.keyboard.type("chmod 777 /tmp/text1.txt\n")
156
self.keyboard.type("ls /tmp\n")
159
#Verify txt should now be green
161
#Delete the file we created
162
self.addCleanup(os.remove, "/tmp/text1.txt")
165
def test_launch_terminal(self):
166
#Test-case name: gnometerminal/ter-004
167
#This test will check that the terminal tab launches succesfully
170
#Open Terminal using the dash, and typing 'terminal'
171
self.keyboard.press_and_release("Super")
172
self.keyboard.type("terminal\n")
174
#Is an instance of gnome-terminal with the title '@: ~' opened, with the current directory set to the users home directory?
177
#Close opened terminal
178
self.keyboard.press_and_release("Ctrl+d", delay=0.2)
181
self.keyboard.press_and_release("Ctrl+Alt+t")
183
#Is an instance of gnome-terminal with the title '@: ~' opened, with the current directory set to the users home directory?
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
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
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)
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")))
205
#Enter 'Test Title' and click OK
206
self.keyboard.type("Test Title")
207
self.keyboard.press_and_release("Alt+o")
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")))
213
def _generateTempFileName():
214
#Create temporary file, then close it, so we can re-use the file name
215
sFile = tempfile.NamedTemporaryFile()
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')
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')
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')
52
self.assertTrue('/tmp/temp-dir2/temp-dir/', DirExists())
54
self.assertTrue('/tmp/temp-dir2/temp-dir/', DirContains(['a', 'b', 'c']))
56
self.addCleanup(shutil.rmtree, '/tmp/temp-dir2')
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')
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')
70
class TerminalWindowTests(TerminalAutopilotTestCase):
72
def test_window_visible(self):
73
terminal_window = self.app.select_single('TerminalWindow')
74
self.assertThat(terminal_window.visible, Eventually(Equals(1)))
76
def test_window_title(self):
77
terminal_window = self.app.select_single('TerminalWindow')
78
self.assertThat(terminal_window.title, Eventually(Contains('~')))
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')))
86
def test_open_new_tab(self, ):
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))