~canonical-platform-qa/ubuntu-system-tests/trunk

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/tests/base.py

  • Committer: Tarmac
  • Author(s): Sergio Cazzolato
  • Date: 2016-02-10 14:20:31 UTC
  • mfrom: (277.4.26 base_test_refactor)
  • Revision ID: tarmac-20160210142031-j2py2zg1d6yi4tdg
Refactoring base test class and autopilot helpers. The idea is to reduce the tests/base and autopilot.py files length.

First step is implemented. For that different methods were move mainly to autopilot helper and this helper was split in different files.

The second part which is pushed and within it all the methods to launch and close apps are moved to the helpers.

Approved by PS Jenkins bot, Richard Huddie.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
#
4
4
# Ubuntu System Tests
5
 
# Copyright (C) 2014, 2015 Canonical
 
5
# Copyright (C) 2014-2016 Canonical
6
6
#
7
7
# This program is free software: you can redistribute it and/or modify
8
8
# it under the terms of the GNU General Public License as published by
23
23
import psutil
24
24
from retrying import retry
25
25
import stat
26
 
import subprocess
27
26
from tempfile import mkstemp
28
27
import threading
29
28
 
31
30
    exceptions,
32
31
    get_test_configuration,
33
32
    input,
34
 
    introspection,
35
33
    logging as autopilot_logging,
36
34
    testcase
37
35
)
38
36
from autopilot.matchers import Eventually
39
 
import ubuntuuitoolkit
40
37
from autopilot._fixtures import OSKAlwaysEnabled
41
38
from autopilot.introspection import _object_registry as object_registry
42
39
from testtools.matchers import Equals
44
41
from unity8 import process_helpers
45
42
from unity8.sensors import FakePlatformSensors
46
43
 
47
 
from ubuntu_system_tests.helpers import autopilot as autopilot_helpers
48
 
from ubuntu_system_tests.helpers import click
 
44
from ubuntu_system_tests.helpers import autopilot
 
45
from ubuntu_system_tests.helpers import context
49
46
from ubuntu_system_tests.helpers import images
50
47
from ubuntu_system_tests.helpers import mir
51
 
from ubuntu_system_tests.helpers import processes
52
48
from ubuntu_system_tests.helpers import screen
53
 
from ubuntu_system_tests.helpers import timer
54
49
from ubuntu_system_tests.helpers import unity8
 
50
from ubuntu_system_tests.helpers.unity8 import get_dash
 
51
from ubuntu_system_tests.helpers.unity8.shell import Unity8  # NOQA
55
52
from ubuntu_system_tests.helpers import wait_until
56
53
from ubuntu_system_tests.helpers import webapp
57
 
from ubuntu_system_tests.helpers.processes import ensure_application_closed
58
 
from ubuntu_system_tests.helpers.scopes import go_to_apps_scope
59
 
from ubuntu_system_tests.helpers.unity8 import get_dash
60
 
from ubuntu_system_tests.helpers.unity8.shell import Unity8  # NOQA
61
54
 
62
55
# Any test name ending with this will leave device locked
63
56
TEST_ID_DEVICE_LOCKED = 'device_locked'
64
57
 
65
 
# Apps and cleanup names
66
 
CALCULATOR_APP = 'ubuntu-calculator-app'
67
 
 
68
 
CATEGORY_LOCAL = 'local'
69
 
CATEGORY_PREDEFINED = 'predefined'
70
 
 
71
58
logger = logging.getLogger(__name__)
72
59
 
73
60
 
86
73
    def setUp(self):
87
74
        super().setUp()
88
75
        self._reset_autopilot_registry()
 
76
        self._init_shared_context()
 
77
 
 
78
    def _init_shared_context(self):
 
79
        # The shared context is reset for each test
 
80
        context.shared.clear()
 
81
        context.shared.add_cleanup = self.addCleanup
 
82
        context.shared.timers = []
 
83
 
 
84
    # Retry added until fix for bug 1427946 in QtMir is landed
 
85
    @retry(stop_max_delay=30000,
 
86
           retry_on_exception=lambda exception: (
 
87
                isinstance(exception, psutil.NoSuchProcess) or
 
88
                isinstance(exception, ValueError)))
 
89
    def _get_unity8_proxy_object(self):
 
90
        return autopilot.get_job_proxy_object('unity8')
89
91
 
90
92
    @autopilot_logging.log_action(logger.info)
91
93
    def launch_unity(self, fake_sensors=False):
111
113
        else:
112
114
            self._start_unity_with_testability()
113
115
 
114
 
        unity = self.get_job_proxy_object('unity8')
 
116
        unity = self._get_unity8_proxy_object()
 
117
        context.shared.unity = unity
115
118
        unity.wait_for_greeter_content()
116
119
        # Workaround to remove the UInput keyboard created by autopilot.
117
120
        # This stops the OSK from being displayed, so must remove it.
125
128
    def _start_unity_with_testability(self):
126
129
        process_helpers.start_job('unity8', 'QT_LOAD_TESTABILITY=1')
127
130
 
128
 
    # Retry added until fix for bug 1427946 in QtMir is landed
129
 
    @retry(stop_max_delay=30000,
130
 
           retry_on_exception=lambda exception: (
131
 
               isinstance(exception, psutil.NoSuchProcess) or
132
 
               isinstance(exception, ValueError)))
133
 
    def get_job_proxy_object(self, pname):
134
 
        pid = process_helpers.get_job_pid(pname)
135
 
        return self.get_proxy_object(pid)
136
 
 
137
 
    def get_proxy_object(self, pid):
138
 
        return introspection.get_proxy_object_for_existing_process(
139
 
            pid=pid,
140
 
            emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase,
141
 
        )
142
 
 
143
131
    def _remove_autopilot_keyboard(self):
144
132
        """Remove the UInput simulated keyboard automatically created by
145
133
        autopilot which stops the OSK from appearing."""
225
213
        test_id = self.id().split('.')[-1]
226
214
        return not test_id.endswith(TEST_ID_DEVICE_LOCKED)
227
215
 
228
 
    def ensure_application_closed(self, app_name):
229
 
        """Stop the app before unity8 is restarted so it's not orphaned."""
230
 
        subprocess.call(['ubuntu-app-stop', app_name])
231
 
 
232
216
    def _get_screenshot_size(self, x, y, width, height):
233
217
        """ Calculate the screenshot size """
234
 
        unity = self.get_job_proxy_object('unity8')
 
218
        unity = context.shared.unity
235
219
        if width and height:
236
220
            return width, height
237
221
        else:
251
235
        return images.get_image_from_rgba(
252
236
            file_path, self._get_screenshot_size(x, y, width, height))
253
237
 
254
 
    def _launch_application_from_apps_scope(self, app_name, category=None):
255
 
        """
256
 
        Launch an app from apps scope and return proxy object.
257
 
 
258
 
        :param app_name: Name of the displayed application.
259
 
        :param category: Category name app is displayed in. If None then the
260
 
                         category name will be discovered automatically.
261
 
        :return: Proxy object for application.
262
 
 
263
 
        """
264
 
        apps_scope = go_to_apps_scope()
265
 
        if not category:
266
 
            category = apps_scope.get_app_category(app_name)
267
 
        apps_scope.click_scope_item(category, app_name)
268
 
 
269
 
    def _launch_application_from_launcher(self, app_name):
270
 
        """
271
 
        Launch an app from the launcher.
272
 
 
273
 
        :param app_name: Name of the displayed application.
274
 
 
275
 
        """
276
 
        unity = self.get_job_proxy_object('unity8')
277
 
        timer.start(timer.LAUNCH_ID)
278
 
        unity.main_window.launch_application(app_name)
279
 
 
280
 
    def _get_proxy_object_for_existing_app(
281
 
            self,
282
 
            process_name,
283
 
            cleanup_process=None,
284
 
            base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
285
 
        """
286
 
        Return proxy object from existing application process.
287
 
 
288
 
        Add cleanup action to close the application using cleanup_process
289
 
        parameter. If cleanup_process is None then process_name is used as the
290
 
        cleanup target using ensure_application_closed().
291
 
 
292
 
        :param process_name: Name of required application process.
293
 
        :param cleanup_process: Name of process to clean up.
294
 
        :param base: custom emulator base for proxy object
295
 
        :return: Proxy object for the desired application.
296
 
 
297
 
        """
298
 
        if not cleanup_process:
299
 
            cleanup_process = process_name
300
 
        proxy = autopilot_helpers.get_proxy_object_for_existing_process(
301
 
            process_name,
302
 
            base)
303
 
        self.addCleanup(ensure_application_closed, cleanup_process)
304
 
        return proxy
305
 
 
306
 
    def _get_proxy_object_for_existing_qmlscene_process(self, qmlfile):
307
 
        """
308
 
        Return proxy object from existing qmlscene process.
309
 
 
310
 
        Add cleanup action to close the application using cleanup_process
311
 
        parameter. If cleanup_process is None then process_id is used as the
312
 
        cleanup target using processes.stop_qmlscene_process().
313
 
 
314
 
        :param qmlfile: Thje name of the QML file for the required process
315
 
        :return: Proxy object for the desired qmlscene process
316
 
 
317
 
        """
318
 
        process_id = processes.get_qmlscene_process_id(qmlfile)
319
 
        proxy = introspection.get_proxy_object_for_existing_process(
320
 
            pid=process_id,
321
 
            emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
322
 
        )
323
 
        self.addCleanup(processes.stop_qmlscene_process, qmlfile)
324
 
        return proxy
325
 
 
326
 
    def _get_proxy_object_for_existing_webapp(self, qmlfile):
327
 
        """
328
 
        Return proxy object from existing qmlscene process.
329
 
 
330
 
        Add cleanup action to close the application using cleanup_process
331
 
        parameter. If cleanup_process is None then process_id is used as the
332
 
        cleanup target using processes.stop_qmlscene_process().
333
 
 
334
 
        :param qmlfile: Thje name of the QML file for the required process
335
 
        :return: Proxy object for the desired qmlscene process
336
 
 
337
 
        """
338
 
        process_id = processes.get_qmlscene_process_id(qmlfile)
339
 
        proxy = introspection.get_proxy_object_for_existing_process(
340
 
            pid=process_id,
341
 
            emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
342
 
        )
343
 
        self.addCleanup(processes.stop_qmlscene_process, qmlfile)
344
 
        return proxy
345
 
 
346
 
    def launch_address_book(self):
347
 
        """
348
 
        Launch the address book app from apps scope and return proxy object.
349
 
 
350
 
        :return: Proxy object for address book application.
351
 
 
352
 
        """
353
 
        self._launch_application_from_apps_scope(
354
 
            'Contacts', CATEGORY_PREDEFINED)
355
 
        return self.get_address_book_app_proxy()
356
 
 
357
 
    def close_address_book(self):
358
 
        """ Close the address book app using task switcher """
359
 
        if self.is_address_book_app_running():
360
 
            self._close_app('address-book-app')
361
 
 
362
 
    def is_address_book_app_running(self):
363
 
        """ Indicate if the address book app is currently running """
364
 
        return processes.is_process_running('address-book-app')
365
 
 
366
 
    def launch_address_book_from_launcher(self):
367
 
        """Drag out the launcher and tap the address book icon to start it."""
368
 
        self._launch_application_from_launcher('address-book-app')
369
 
        return self.get_address_book_app_proxy()
370
 
 
371
 
    def get_address_book_app_proxy(self):
372
 
        """
373
 
        Return address book app proxy object from existing process.
374
 
 
375
 
        :return: Proxy object for address book application.
376
 
 
377
 
        """
378
 
        from ubuntu_system_tests.helpers.addressbook import _cpo  # NOQA
379
 
        wait_until(self.is_address_book_app_running, period=0.5)
380
 
        proxy = self._get_proxy_object_for_existing_app('address-book-app')
381
 
        return proxy.main_window
382
 
 
383
 
    def launch_camera_app(self):
384
 
        """
385
 
        Launch the camera app from dash and return proxy object.
386
 
 
387
 
        :return: Proxy object for camera application.
388
 
 
389
 
        """
390
 
        self._launch_application_from_apps_scope('Camera', CATEGORY_PREDEFINED)
391
 
        return self.get_camera_app_proxy()
392
 
 
393
 
    def close_camera_app(self):
394
 
        """ Close the camera app using task switcher """
395
 
        if self.is_camera_app_running():
396
 
            self._close_app('com.ubuntu.camera_camera')
397
 
 
398
 
    def is_camera_app_running(self):
399
 
        """ Indicate if the camera app is currently running """
400
 
        return processes.is_process_running('camera-app')
401
 
 
402
 
    def launch_camera_app_from_launcher(self):
403
 
        """Drag out the launcher and tap the camera icon to start it."""
404
 
        self._launch_application_from_launcher('com.ubuntu.camera_camera')
405
 
        return self.get_camera_app_proxy()
406
 
 
407
 
    def get_camera_app_proxy(self):
408
 
        """
409
 
        Return camera app proxy object from existing process and add
410
 
        cleanup actions to close the application.
411
 
 
412
 
        :return: Proxy object for camera application.
413
 
 
414
 
        """
415
 
        from ubuntu_system_tests.helpers.camera._cpo import MainWindow
416
 
        wait_until(self.is_camera_app_running, period=0.5)
417
 
        proxy = self._get_proxy_object_for_existing_app(
418
 
            'camera-app',
419
 
            cleanup_process=click.get_click_app_identifier('com.ubuntu.camera')
420
 
        )
421
 
        return MainWindow(proxy)
422
 
 
423
 
    def launch_dialer_app(self):
424
 
        """
425
 
        Launch the dialer app from apps scope and return proxy object.
426
 
 
427
 
        :return: Proxy object for dialer application.
428
 
 
429
 
        """
430
 
        self._launch_application_from_apps_scope('Phone', CATEGORY_PREDEFINED)
431
 
        return self.get_dialer_app_proxy()
432
 
 
433
 
    def close_dialer_app(self):
434
 
        """ Close the dialer app using task switcher """
435
 
        if self.is_dialer_app_running():
436
 
            self._close_app('dialer-app')
437
 
 
438
 
    def is_dialer_app_running(self):
439
 
        """ Indicate if the dialer app is currently running """
440
 
        return processes.is_process_running('dialer-app')
441
 
 
442
 
    def get_dialer_app_proxy(self):
443
 
        """
444
 
        Return dialer app proxy object from existing process.
445
 
 
446
 
        :return: Proxy object for dialer application.
447
 
 
448
 
        """
449
 
        from ubuntu_system_tests.helpers.dialer_app import _cpo  # NOQA
450
 
        wait_until(self.is_dialer_app_running, period=0.5)
451
 
        proxy = self._get_proxy_object_for_existing_app('dialer-app')
452
 
        return proxy.main_view
453
 
 
454
 
    def launch_gallery_app(self):
455
 
        """
456
 
        Launch the gallery app from apps scope and return proxy object.
457
 
 
458
 
        :return: Proxy object for gallery application.
459
 
 
460
 
        """
461
 
        from ubuntu_system_tests.helpers.gallery._cpo import EventsView
462
 
        self._launch_application_from_apps_scope('Gallery', CATEGORY_LOCAL)
463
 
        return EventsView(self.get_gallery_app_proxy())
464
 
 
465
 
    def close_gallery_app(self):
466
 
        """ Close the gallery app using task switcher """
467
 
        if self.is_gallery_app_running():
468
 
            self._close_app('com.ubuntu.gallery_gallery')
469
 
 
470
 
    def is_gallery_app_running(self):
471
 
        """ Indicate if the gallery app is currently running """
472
 
        return processes.is_process_running('gallery-app')
473
 
 
474
 
    def get_gallery_app_proxy(self):
475
 
        """
476
 
        Return gallery app proxy object from existing process.
477
 
 
478
 
        :return: Proxy object for gallery application.
479
 
 
480
 
        """
481
 
        wait_until(self.is_gallery_app_running, period=0.5)
482
 
        proxy = self._get_proxy_object_for_existing_app(
483
 
            'gallery-app',
484
 
            cleanup_process=click.get_click_app_identifier(
485
 
                'com.ubuntu.gallery'))
486
 
        return proxy
487
 
 
488
 
    def get_gallery_events_view(self):
489
 
        """Return a gallery_app EventsView custom proxy object."""
490
 
        from ubuntu_system_tests.helpers.gallery._cpo import EventsView
491
 
        return EventsView(self.get_gallery_app_proxy())
492
 
 
493
 
    def get_gallery_photo_viewer(self):
494
 
        """Return a gallery_app PhotoViewer custom proxy object."""
495
 
        from ubuntu_system_tests.helpers.gallery._cpo import PhotoViewer
496
 
        return PhotoViewer(self.get_gallery_app_proxy())
497
 
 
498
 
    def get_media_player_proxy(self):
499
 
        """
500
 
        Return media player app proxy object from existing process.
501
 
 
502
 
        :return: Proxy object for media player application.
503
 
 
504
 
        """
505
 
        from ubuntu_system_tests.helpers.mediaplayer._cpo import MainWindow
506
 
        proxy = self._get_proxy_object_for_existing_app('mediaplayer-app')
507
 
        return MainWindow(proxy)
508
 
 
509
 
    def launch_messaging_app(self):
510
 
        """
511
 
        Launch the messaging app from apps scope and return proxy object.
512
 
 
513
 
        :return: Proxy object for messaging application.
514
 
 
515
 
        """
516
 
        self._launch_application_from_apps_scope(
517
 
            'Messaging', CATEGORY_PREDEFINED)
518
 
        return self.get_messaging_app_proxy()
519
 
 
520
 
    def close_messaging_app(self):
521
 
        """ Close the messaging app using task switcher """
522
 
        if self.is_messaging_app_running():
523
 
            self._close_app('messaging-app')
524
 
 
525
 
    def is_messaging_app_running(self):
526
 
        """ Indicate if the messaging app is currently running """
527
 
        return processes.is_process_running('messaging-app')
528
 
 
529
 
    def get_messaging_app_proxy(
530
 
            self, base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
531
 
        """
532
 
        Return messaging app proxy object from existing process.
533
 
 
534
 
        :return: Proxy object for messaging application.
535
 
 
536
 
        """
537
 
        wait_until(self.is_messaging_app_running, period=0.5)
538
 
        if not base:
539
 
            return self._get_proxy_object_for_existing_app('messaging-app',
540
 
                                                           base=base)
541
 
 
542
 
        from ubuntu_system_tests.helpers.messaging._cpo import MainView
543
 
        proxy = self._get_proxy_object_for_existing_app('messaging-app')
544
 
        return proxy.wait_select_single(MainView)
545
 
 
546
 
    def launch_system_settings(self):
547
 
        """
548
 
        Launch system settings from apps scope and return proxy object.
549
 
 
550
 
        :return: Proxy object for system settings.
551
 
 
552
 
        """
553
 
        self._launch_application_from_apps_scope(
554
 
            'System Settings', CATEGORY_LOCAL)
555
 
        return self.get_system_settings_proxy()
556
 
 
557
 
    def close_system_settings(self):
558
 
        """ Close the system settings app using task switcher """
559
 
        if self.is_system_settings_running():
560
 
            self._close_app('ubuntu-system-settings')
561
 
 
562
 
    def is_system_settings_running(self):
563
 
        """ Indicate if the system settings is currently running """
564
 
        return processes.is_process_running('system-settings')
565
 
 
566
 
    def get_system_settings_proxy(self):
567
 
        """
568
 
        Return system settings proxy object from existing process.
569
 
 
570
 
        :return: Proxy object for system settings.
571
 
 
572
 
        """
573
 
        from ubuntu_system_tests.helpers.system_settings import _cpo  # NOQA
574
 
        wait_until(self.is_system_settings_running, period=0.5)
575
 
        proxy = self._get_proxy_object_for_existing_app(
576
 
            'system-settings', cleanup_process='ubuntu-system-settings')
577
 
        return proxy.main_view
578
 
 
579
 
    def launch_webbrowser_app(self):
580
 
        """
581
 
        Launch the webbrowser app from apps scope and return proxy object.
582
 
 
583
 
        :return: Proxy object for webbrowser application.
584
 
 
585
 
        """
586
 
        self._launch_application_from_apps_scope(
587
 
            'Browser', CATEGORY_PREDEFINED)
588
 
        return self.get_webbrowser_app_proxy()
589
 
 
590
 
    def close_webbrowser_app(self):
591
 
        """ Close the webbrowser app using task switcher """
592
 
        if self.is_webbrowser_app_running():
593
 
            self._close_app('webbrowser-app')
594
 
 
595
 
    def is_webbrowser_app_running(self):
596
 
        """ Indicate if the webbrowser app is currently running """
597
 
        return processes.is_process_running('webbrowser-app')
598
 
 
599
 
    def get_webbrowser_app_proxy(self):
600
 
        """
601
 
        Return webbrowser app proxy object from existing process.
602
 
 
603
 
        :return: Proxy object for webbrowser application.
604
 
 
605
 
        """
606
 
        from ubuntu_system_tests.helpers.webbrowser import _cpo  # NOQA
607
 
        wait_until(self.is_webbrowser_app_running, period=0.5)
608
 
        proxy = self._get_proxy_object_for_existing_app('webbrowser-app')
609
 
        return proxy.main_window
610
 
 
611
 
    def launch_calendar_app(self):
612
 
        """
613
 
        Launch the calendar app from apps scope and return proxy object.
614
 
 
615
 
        :return: Proxy object for calendar application.
616
 
 
617
 
        """
618
 
        self._launch_application_from_apps_scope('Calendar', CATEGORY_LOCAL)
619
 
        wait_until(self.is_calendar_app_running, period=0.5)
620
 
 
621
 
        return self.get_calendar_app_proxy()
622
 
 
623
 
    def close_calendar_app(self):
624
 
        """ Close the calendar app using task switcher """
625
 
        if self.is_calendar_app_running():
626
 
            self._close_app('calendar')
627
 
 
628
 
    def is_calendar_app_running(self):
629
 
        """ Indicate if the calendar app is currently running """
630
 
        return processes.is_qmlscene_running_with_qmlfile('calendar')
631
 
 
632
 
    def get_calendar_app_proxy(self):
633
 
        """
634
 
        Return calendar app proxy object from existing process.
635
 
 
636
 
        :return: Proxy object for calendar application.
637
 
 
638
 
        """
639
 
        proxy = self._get_proxy_object_for_existing_qmlscene_process(
640
 
            'calendar')
641
 
        return proxy.main_window
642
 
 
643
 
    def launch_clock_app(self):
644
 
        """
645
 
        Launch the clock app from apps scope and return proxy object.
646
 
 
647
 
        :return: Proxy object for clock application.
648
 
 
649
 
        """
650
 
        self._launch_application_from_apps_scope('Clock', CATEGORY_PREDEFINED)
651
 
        wait_until(self.is_clock_app_running, period=0.5)
652
 
        return self.get_clock_app_proxy()
653
 
 
654
 
    def close_clock_app(self):
655
 
        """ Close the calendar app using task switcher """
656
 
        if self.is_clock_app_running():
657
 
            self._close_app('com.ubuntu.clock_clock')
658
 
 
659
 
    def is_clock_app_running(self):
660
 
        """ Indicate if the clock app is currently running """
661
 
        return processes.is_qmlscene_running_with_qmlfile('ubuntu-clock-app')
662
 
 
663
 
    def get_clock_app_proxy(self):
664
 
        """
665
 
        Return clock app proxy object from existing process.
666
 
 
667
 
        :return: Proxy object for calendar application.
668
 
 
669
 
        """
670
 
        from ubuntu_system_tests.helpers.clock import _cpo  # NOQA
671
 
        proxy = self._get_proxy_object_for_existing_qmlscene_process(
672
 
            'ubuntu-clock-app')
673
 
        return proxy.main_view
674
 
 
675
 
    def launch_webbrowser_from_launcher(self):
676
 
        """Start webbrowser from the launcher."""
677
 
        self._launch_application_from_launcher('webbrowser-app')
678
 
        return self.get_webbrowser_app_proxy()
679
 
 
680
 
    def launch_messaging_app_from_launcher(self):
681
 
        """Drag out the launcher and tap the messaging app icon to start it."""
682
 
        self._launch_application_from_launcher('messaging-app')
683
 
        return self.get_messaging_app_proxy()
684
 
 
685
 
    def launch_dialer_app_from_launcher(self):
686
 
        """Drag out the launcher and tap the dialer app icon to start it."""
687
 
        self._launch_application_from_launcher('dialer-app')
688
 
        return self.get_dialer_app_proxy()
689
 
 
690
 
    def launch_gallery_app_from_launcher(self):
691
 
        """Drag out the launcher and tap the gallery app icon to start it."""
692
 
        self._launch_application_from_launcher('com.ubuntu.gallery_gallery')
693
 
        return self.get_gallery_app_proxy()
694
 
 
695
 
    def get_webapp_proxy(self, web_app_package):
696
 
        """ Return webapp proxy object from existing process.
697
 
        :param web_app_package: The package name
698
 
        :return: Proxy object for webapp.
699
 
        """
700
 
        from ubuntu_system_tests.helpers.webapp import _cpo  # NOQA
701
 
 
702
 
        pid = webapp.get_webapp_pid(web_app_package)
703
 
        proxy = introspection.get_proxy_object_for_existing_process(
704
 
            pid=pid,
705
 
            emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
706
 
        )
707
 
        return proxy.wait_select_single('BrowserWindow')
708
 
 
709
238
    def setup_webapp_environment(self):
710
239
        """ Setup the environment for the webapps. This method has to be
711
240
        called before launch the first web app in the test.
715
244
            UBUNTU_WEBVIEW_DEVTOOLS_HOST=webapp.DEFAULT_WEBVIEW_INSPECTOR_IP,
716
245
            UBUNTU_WEBVIEW_DEVTOOLS_PORT=str(
717
246
                webapp.DEFAULT_WEBVIEW_INSPECTOR_PORT)))
718
 
 
719
 
    def launch_webapp(self, app_name, web_app_package):
720
 
        """ Launch the webapp and return the webapp proxy object
721
 
        :param app_name: The name in the apps scope
722
 
        :param web_app_package: The package name
723
 
        :return: Proxy object for webapp
724
 
        """
725
 
        apps_scope = go_to_apps_scope()
726
 
        apps_scope.click_scope_item(CATEGORY_LOCAL, app_name)
727
 
        self.addCleanup(webapp.ensure_webapp_closed, web_app_package)
728
 
        wait_until(webapp.is_webapp_runing, web_app_package)
729
 
        return self.get_webapp_proxy(web_app_package)
730
 
 
731
 
    def launch_calculator_app(self):
732
 
        """
733
 
        Launch calculator app from apps scope and return its proxy object.
734
 
        """
735
 
        self._launch_application_from_apps_scope(
736
 
            'Calculator', CATEGORY_LOCAL)
737
 
        wait_until(self.is_calculator_app_running, period=0.5)
738
 
        return self.get_calculator_app_proxy()
739
 
 
740
 
    def close_calculator_app(self):
741
 
        """ Close the calculator app using task switcher """
742
 
        if self.is_calculator_app_running():
743
 
            self._close_app('com.ubuntu.calculator_calculator')
744
 
 
745
 
    def is_calculator_app_running(self):
746
 
        """ Indicate if the calculator app is currently running """
747
 
        return processes.is_qmlscene_running_with_qmlfile(
748
 
            'ubuntu-calculator-app')
749
 
 
750
 
    def get_calculator_app_proxy(self):
751
 
        """Return the proxy object of the calculator app."""
752
 
        from ubuntu_system_tests.helpers.calculator import _cpo  # NOQA
753
 
        proxy = self._get_proxy_object_for_existing_qmlscene_process(
754
 
            CALCULATOR_APP)
755
 
        return proxy.main_view
756
 
 
757
 
    def get_ubuntu_keyboard_proxy(self):
758
 
        from ubuntu_system_tests.helpers.ubuntu_keyboard import _cpo  # NOQA
759
 
        return self._get_proxy_object_for_existing_app('maliit-server')
760
 
 
761
 
    def launch_ebay_webapp(self):
762
 
        """ Launch the Ebay webapp from apps scope and return its proxy object
763
 
        """
764
 
        webapp_name = 'eBay'
765
 
        webapp_package = 'com.ubuntu.developer.webapps.webapp-ebay'
766
 
        return self.launch_webapp(webapp_name, webapp_package)
767
 
 
768
 
    def close_ebay_webapp(self):
769
 
        """ Close the ebay webapp using task switcher """
770
 
        if self.is_ebay_webapp_running():
771
 
            self._close_app(
772
 
                'com.ubuntu.developer.webapps.webapp-ebay_webapp-ebay')
773
 
 
774
 
    def is_ebay_webapp_running(self):
775
 
        """ Indicate if the ebay webapp is currently running """
776
 
        webapp_package = 'com.ubuntu.developer.webapps.webapp-ebay'
777
 
        return webapp.is_webapp_runing(webapp_package)
778
 
 
779
 
    def launch_here_webapp(self):
780
 
        """ Launch the Here webapp from apps scope and return its proxy object
781
 
        """
782
 
        webapp_name = 'HERE Maps'
783
 
        webapp_package = 'com.nokia.heremaps'
784
 
        return self.launch_webapp(webapp_name, webapp_package)
785
 
 
786
 
    def close_here_webapp(self):
787
 
        """ Close the here webapp using task switcher """
788
 
        if self.is_here_webapp_running():
789
 
            self._close_app('com.nokia.heremaps_here')
790
 
 
791
 
    def is_here_webapp_running(self):
792
 
        """ Indicate if the here webapp is currently running """
793
 
        webapp_package = 'com.nokia.heremaps'
794
 
        return webapp.is_webapp_runing(webapp_package)
795
 
 
796
 
    def launch_music_app(self):
797
 
        """
798
 
        Launch the music app from apps scope and return proxy object.
799
 
 
800
 
        :return: Proxy object for music application.
801
 
 
802
 
        """
803
 
        self._launch_application_from_apps_scope('Music')
804
 
        wait_until(self.is_music_app_running, period=0.5)
805
 
        return self.get_music_app_proxy()
806
 
 
807
 
    def close_music_app(self):
808
 
        """ Close the music app using task switcher """
809
 
        if self.is_music_app_running():
810
 
            self._close_app('com.ubuntu.music_music')
811
 
 
812
 
    def is_music_app_running(self):
813
 
        """ Indicate if the music app is currently running """
814
 
        return processes.is_qmlscene_running_with_qmlfile('music-app')
815
 
 
816
 
    def get_music_app_proxy(self):
817
 
        """
818
 
        Return music app proxy object from existing process.
819
 
 
820
 
        :return: Proxy object for music application.
821
 
 
822
 
        """
823
 
        proxy = self._get_proxy_object_for_existing_qmlscene_process(
824
 
            'music-app')
825
 
        return proxy.wait_select_single(ubuntuuitoolkit.MainView)
826
 
 
827
 
    def _close_app(self, app_name):
828
 
        """Close an app using task switcher and check process is stopped."""
829
 
        unity_proxy = self.get_job_proxy_object('unity8')
830
 
 
831
 
        # Get the windows name
832
 
        stage = unity_proxy.main_window.swipe_to_show_app_switcher()
833
 
        app_window_name = 'appWindow_' + app_name
834
 
        app_windows = stage.get_app_window_names()
835
 
        count = len(app_windows)
836
 
        self.assertTrue(app_window_name in app_windows)
837
 
 
838
 
        # Close the windows and assert that it is closed
839
 
        stage.close_app(app_name)
840
 
        app_windows = stage.get_app_window_names()
841
 
        self.assertFalse(app_window_name in app_windows)
842
 
        self.assertEqual(len(app_windows), count - 1)