on xenial help sign in
Update the screenlock autopilot tests.
commit2797093317f427644063421b8b4f8a15e7b2b5b3 authorLeo Arias <leo.arias@canonical.com> dateWed 30 Jul 2014, 12:22 (12 years ago) parent55642cb
5 files changed+58−65
tests/autopilot/unity8/process_helpers.py+3−3 tests/autopilot/unity8/shell/emulators/greeter.py+4−1 tests/autopilot/unity8/shell/emulators/main_window.py+28−6 tests/autopilot/unity8/shell/tests/__init__.py+15−8 tests/autopilot/unity8/shell/tests/test_lock_screen.py+8−47
tests/autopilot/unity8/process_helpers.py+3−3
@@ -162,7 +162,7 @@ def start_job(name, *args):
162162 universal_newlines=True,
163163 )
164164 logger.info(output)
165− pid = _get_job_pid(name)
165+ pid = get_job_pid(name)
166166 except subprocess.CalledProcessError as e:
167167 e.args += ('Failed to start {}: {}.'.format(name, e.output))
168168 raise
@@ -170,7 +170,7 @@ def start_job(name, *args):
170170 return pid
171171
172172
173−def _get_job_pid(name):
173+def get_job_pid(name):
174174 """Return the process id of a running job.
175175
176176 :param str name: The name of the job.
@@ -232,7 +232,7 @@ def _get_unity_status():
232232
233233def _get_unity_pid():
234234 try:
235− return _get_job_pid('unity8')
235+ return get_job_pid('unity8')
236236 except JobError as error:
237237 raise CannotAccessUnity(str(error))
238238
tests/autopilot/unity8/shell/emulators/greeter.py+4−1
@@ -17,6 +17,8 @@
1717# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818#
1919
20+import ubuntuuitoolkit
21+
2022from unity8.shell.emulators import UnityEmulatorBase
2123
2224
@@ -37,4 +39,5 @@ class Greeter(UnityEmulatorBase):
3739 self.created.wait_for(False)
3840
3941 def get_prompt(self):
40− return self.select_single("TextField", objectName="passwordInput")
42+ return self.select_single(
43+ ubuntuuitoolkit.TextField, objectName='passwordInput')
tests/autopilot/unity8/shell/emulators/main_window.py+28−6
@@ -76,12 +76,6 @@ class QQuickView(emulators.UnityEmulatorBase):
7676 objectName="pinPadLoader"
7777 )
7878
79− def get_pinPadButton(self, buttonId):
80− return self.select_single(
81− "PinPadButton",
82− objectName="pinPadButton%i" % buttonId
83− )
84−
8579 def get_lockscreen(self):
8680 return self.select_single("Lockscreen")
8781
@@ -134,3 +128,31 @@ class QQuickView(emulators.UnityEmulatorBase):
134128 @autopilot_logging.log_action(logger.info)
135129 def search(self, query):
136130 self.get_dash().enter_search_query(query)
131+
132+ @autopilot_logging.log_action(logger.info)
133+ def enter_pin_code(self, code):
134+ """Enter code 'code' into the single-pin lightdm pincode entry screen.
135+
136+ :param code: must be a string of numeric characters.
137+ :raises: TypeError if code is not a string.
138+ :raises: ValueError if code contains non-numeric characters.
139+
140+ """
141+ if not isinstance(code, str):
142+ raise TypeError(
143+ "'code' parameter must be a string, not %r."
144+ % type(code)
145+ )
146+ for num in code:
147+ if not num.isdigit():
148+ raise ValueError(
149+ "'code' parameter contains non-numeric characters."
150+ )
151+ self.pointing_device.click_object(
152+ self._get_pinpad_button(int(num)))
153+
154+ def _get_pinpad_button(self, button_id):
155+ return self.select_single(
156+ 'PinPadButton',
157+ objectName='pinPadButton{}'.format(button_id)
158+ )
tests/autopilot/unity8/shell/tests/__init__.py+15−8
@@ -24,6 +24,7 @@ try:
2424except ImportError:
2525 Gio = None
2626
27+from autopilot import introspection
2728from autopilot.platform import model
2829from autopilot.testcase import AutopilotTestCase
2930from autopilot.matchers import Eventually
@@ -47,6 +48,7 @@ from unity8 import (
4748 fixture_setup,
4849 process_helpers
4950)
51+from unity8.shell import emulators
5052from unity8.shell.emulators import (
5153 dash as dash_helpers,
5254 main_window as main_window_emulator,
@@ -391,8 +393,13 @@ class UnityTestCase(AutopilotTestCase):
391393
392394
393395 def get_dash(self):
394− dash = self._proxy.wait_select_single(dash_helpers.Dash)
395− return dash
396+ pid = process_helpers.get_job_pid('unity8-dash')
397+ dash_proxy = introspection.get_proxy_object_for_existing_process(
398+ pid=pid,
399+ emulator_base=emulators.UnityEmulatorBase,
400+ )
401+ dash_app = dash_helpers.DashApp(dash_proxy)
402+ return dash_app.dash
396403
397404 @property
398405 def main_window(self):
@@ -433,6 +440,12 @@ class DashBaseTestCase(AutopilotTestCase):
433440 self.dash_app = dash_helpers.DashApp(dash_proxy)
434441 self.dash = self.dash_app.dash
435442
443+ def launch_dash(self, binary_path, variables):
444+ launch_dash_app_fixture = fixture_setup.LaunchDashApp(
445+ binary_path, variables)
446+ self.useFixture(launch_dash_app_fixture)
447+ return launch_dash_app_fixture.application_proxy
448+
436449 def should_simulate_device(self):
437450 return (hasattr(self, 'app_width') and hasattr(self, 'app_height') and
438451 hasattr(self, 'grid_unit_px'))
@@ -456,9 +469,3 @@ class DashBaseTestCase(AutopilotTestCase):
456469 self.assertThat(
457470 get_window_size,
458471 Eventually(Equals((self.app_width, self.app_height))))
459−
460− def launch_dash(self, binary_path, variables):
461− launch_dash_app_fixture = fixture_setup.LaunchDashApp(
462− binary_path, variables)
463− self.useFixture(launch_dash_app_fixture)
464− return launch_dash_app_fixture.application_proxy
tests/autopilot/unity8/shell/tests/test_lock_screen.py+8−47
@@ -48,10 +48,11 @@ class TestLockscreen(UnityTestCase):
4848 unity_proxy = self.launch_unity()
4949 greeter = self.main_window.get_greeter()
5050
51+
5152 if greeter.narrowMode:
5253 unlock_unity(unity_proxy)
5354 lockscreen = self._wait_for_lockscreen()
54− self._enter_pincode("1234")
55+ self.main_window.enter_pin_code("1234")
5556 self.assertThat(lockscreen.shown, Eventually(Equals(False)))
5657 else:
5758 self._enter_prompt_passphrase("1234")
@@ -81,7 +82,7 @@ class TestLockscreen(UnityTestCase):
8182 if greeter.narrowMode:
8283 unlock_unity(unity_proxy)
8384 lockscreen = self._wait_for_lockscreen()
84− self._enter_pincode("4321")
85+ self.main_window.enter_pin_code("4321")
8586 pinentryField = self.main_window.get_pinentryField()
8687 self.assertThat(pinentryField.text, Eventually(Equals("")))
8788 self.assertThat(lockscreen.shown, Eventually(Equals(True)))
@@ -118,28 +119,6 @@ class TestLockscreen(UnityTestCase):
118119 self.assertThat(lockscreen.shown, Eventually(Equals(True)))
119120 return lockscreen
120121
121− def _enter_pincode(self, code):
122− """Enter code 'code' into the single-pin lightdm pincode entry
123− screen.
124−
125− :param code: must be a string of numeric characters.
126− :raises: TypeError if code is not a string.
127− :raises: ValueError if code contains non-numeric characters.
128−
129− """
130−
131− if not isinstance(code, basestring):
132− raise TypeError(
133− "'code' parameter must be a string, not %r."
134− % type(code)
135− )
136− for num in code:
137− if not num.isdigit():
138− raise ValueError(
139− "'code' parameter contains non-numeric characters."
140− )
141− self.touch.tap_object(self.main_window.get_pinPadButton(int(num)))
142−
143122 def _enter_pin_passphrase(self, passphrase):
144123 """Enter the password specified in 'passphrase' into the password entry
145124 field of the pin lock screen.
@@ -148,18 +127,15 @@ class TestLockscreen(UnityTestCase):
148127 :raises: TypeError if passphrase is not a string.
149128
150129 """
151− if not isinstance(passphrase, basestring):
130+ if not isinstance(passphrase, str):
152131 raise TypeError(
153132 "'passphrase' parameter must be a string, not %r."
154133 % type(passphrase)
155134 )
156135
157− pinentryField = self.main_window.get_pinentryField()
158− self.touch.tap_object(pinentryField)
159− self.assertThat(pinentryField.activeFocus, Eventually(Equals(True)))
160− for character in passphrase:
161− self._type_character(character, pinentryField)
162− logger.debug("Typed passphrase: %s", pinentryField.text)
136+ pin_entry_field = self.main_window.get_pinentryField()
137+ pin_entry_field.write(passphrase)
138+ logger.debug("Typed passphrase: %s", pin_entry_field.text)
163139 self.keyboard.type("\n")
164140
165141 def _enter_prompt_passphrase(self, passphrase):
@@ -177,21 +153,6 @@ class TestLockscreen(UnityTestCase):
177153 )
178154
179155 prompt = self.main_window.get_greeter().get_prompt()
180− self.touch.tap_object(prompt)
181− self.assertThat(prompt.activeFocus, Eventually(Equals(True)))
182− for character in passphrase:
183− self._type_character(character, prompt)
156+ prompt.write(passphrase)
184157 logger.debug("Typed passphrase: %s", prompt.text)
185158 self.keyboard.type("\n")
186−
187− def _type_character(self, character, prompt, retries=5):
188− current_text = prompt.text
189− self.keyboard.type(character)
190− try:
191− self.assertThat(
192− prompt.text, Eventually(Equals(current_text + character)))
193− except AssertionError:
194− if retries > 0:
195− self._type_character(character, prompt, retries-1)
196− else:
197− raise