251
235
return images.get_image_from_rgba(
252
236
file_path, self._get_screenshot_size(x, y, width, height))
254
def _launch_application_from_apps_scope(self, app_name, category=None):
256
Launch an app from apps scope and return proxy object.
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.
264
apps_scope = go_to_apps_scope()
266
category = apps_scope.get_app_category(app_name)
267
apps_scope.click_scope_item(category, app_name)
269
def _launch_application_from_launcher(self, app_name):
271
Launch an app from the launcher.
273
:param app_name: Name of the displayed application.
276
unity = self.get_job_proxy_object('unity8')
277
timer.start(timer.LAUNCH_ID)
278
unity.main_window.launch_application(app_name)
280
def _get_proxy_object_for_existing_app(
283
cleanup_process=None,
284
base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
286
Return proxy object from existing application process.
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().
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.
298
if not cleanup_process:
299
cleanup_process = process_name
300
proxy = autopilot_helpers.get_proxy_object_for_existing_process(
303
self.addCleanup(ensure_application_closed, cleanup_process)
306
def _get_proxy_object_for_existing_qmlscene_process(self, qmlfile):
308
Return proxy object from existing qmlscene process.
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().
314
:param qmlfile: Thje name of the QML file for the required process
315
:return: Proxy object for the desired qmlscene process
318
process_id = processes.get_qmlscene_process_id(qmlfile)
319
proxy = introspection.get_proxy_object_for_existing_process(
321
emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
323
self.addCleanup(processes.stop_qmlscene_process, qmlfile)
326
def _get_proxy_object_for_existing_webapp(self, qmlfile):
328
Return proxy object from existing qmlscene process.
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().
334
:param qmlfile: Thje name of the QML file for the required process
335
:return: Proxy object for the desired qmlscene process
338
process_id = processes.get_qmlscene_process_id(qmlfile)
339
proxy = introspection.get_proxy_object_for_existing_process(
341
emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
343
self.addCleanup(processes.stop_qmlscene_process, qmlfile)
346
def launch_address_book(self):
348
Launch the address book app from apps scope and return proxy object.
350
:return: Proxy object for address book application.
353
self._launch_application_from_apps_scope(
354
'Contacts', CATEGORY_PREDEFINED)
355
return self.get_address_book_app_proxy()
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')
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')
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()
371
def get_address_book_app_proxy(self):
373
Return address book app proxy object from existing process.
375
:return: Proxy object for address book application.
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
383
def launch_camera_app(self):
385
Launch the camera app from dash and return proxy object.
387
:return: Proxy object for camera application.
390
self._launch_application_from_apps_scope('Camera', CATEGORY_PREDEFINED)
391
return self.get_camera_app_proxy()
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')
398
def is_camera_app_running(self):
399
""" Indicate if the camera app is currently running """
400
return processes.is_process_running('camera-app')
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()
407
def get_camera_app_proxy(self):
409
Return camera app proxy object from existing process and add
410
cleanup actions to close the application.
412
:return: Proxy object for camera application.
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(
419
cleanup_process=click.get_click_app_identifier('com.ubuntu.camera')
421
return MainWindow(proxy)
423
def launch_dialer_app(self):
425
Launch the dialer app from apps scope and return proxy object.
427
:return: Proxy object for dialer application.
430
self._launch_application_from_apps_scope('Phone', CATEGORY_PREDEFINED)
431
return self.get_dialer_app_proxy()
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')
438
def is_dialer_app_running(self):
439
""" Indicate if the dialer app is currently running """
440
return processes.is_process_running('dialer-app')
442
def get_dialer_app_proxy(self):
444
Return dialer app proxy object from existing process.
446
:return: Proxy object for dialer application.
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
454
def launch_gallery_app(self):
456
Launch the gallery app from apps scope and return proxy object.
458
:return: Proxy object for gallery application.
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())
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')
470
def is_gallery_app_running(self):
471
""" Indicate if the gallery app is currently running """
472
return processes.is_process_running('gallery-app')
474
def get_gallery_app_proxy(self):
476
Return gallery app proxy object from existing process.
478
:return: Proxy object for gallery application.
481
wait_until(self.is_gallery_app_running, period=0.5)
482
proxy = self._get_proxy_object_for_existing_app(
484
cleanup_process=click.get_click_app_identifier(
485
'com.ubuntu.gallery'))
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())
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())
498
def get_media_player_proxy(self):
500
Return media player app proxy object from existing process.
502
:return: Proxy object for media player application.
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)
509
def launch_messaging_app(self):
511
Launch the messaging app from apps scope and return proxy object.
513
:return: Proxy object for messaging application.
516
self._launch_application_from_apps_scope(
517
'Messaging', CATEGORY_PREDEFINED)
518
return self.get_messaging_app_proxy()
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')
525
def is_messaging_app_running(self):
526
""" Indicate if the messaging app is currently running """
527
return processes.is_process_running('messaging-app')
529
def get_messaging_app_proxy(
530
self, base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
532
Return messaging app proxy object from existing process.
534
:return: Proxy object for messaging application.
537
wait_until(self.is_messaging_app_running, period=0.5)
539
return self._get_proxy_object_for_existing_app('messaging-app',
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)
546
def launch_system_settings(self):
548
Launch system settings from apps scope and return proxy object.
550
:return: Proxy object for system settings.
553
self._launch_application_from_apps_scope(
554
'System Settings', CATEGORY_LOCAL)
555
return self.get_system_settings_proxy()
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')
562
def is_system_settings_running(self):
563
""" Indicate if the system settings is currently running """
564
return processes.is_process_running('system-settings')
566
def get_system_settings_proxy(self):
568
Return system settings proxy object from existing process.
570
:return: Proxy object for system settings.
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
579
def launch_webbrowser_app(self):
581
Launch the webbrowser app from apps scope and return proxy object.
583
:return: Proxy object for webbrowser application.
586
self._launch_application_from_apps_scope(
587
'Browser', CATEGORY_PREDEFINED)
588
return self.get_webbrowser_app_proxy()
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')
595
def is_webbrowser_app_running(self):
596
""" Indicate if the webbrowser app is currently running """
597
return processes.is_process_running('webbrowser-app')
599
def get_webbrowser_app_proxy(self):
601
Return webbrowser app proxy object from existing process.
603
:return: Proxy object for webbrowser application.
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
611
def launch_calendar_app(self):
613
Launch the calendar app from apps scope and return proxy object.
615
:return: Proxy object for calendar application.
618
self._launch_application_from_apps_scope('Calendar', CATEGORY_LOCAL)
619
wait_until(self.is_calendar_app_running, period=0.5)
621
return self.get_calendar_app_proxy()
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')
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')
632
def get_calendar_app_proxy(self):
634
Return calendar app proxy object from existing process.
636
:return: Proxy object for calendar application.
639
proxy = self._get_proxy_object_for_existing_qmlscene_process(
641
return proxy.main_window
643
def launch_clock_app(self):
645
Launch the clock app from apps scope and return proxy object.
647
:return: Proxy object for clock application.
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()
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')
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')
663
def get_clock_app_proxy(self):
665
Return clock app proxy object from existing process.
667
:return: Proxy object for calendar application.
670
from ubuntu_system_tests.helpers.clock import _cpo # NOQA
671
proxy = self._get_proxy_object_for_existing_qmlscene_process(
673
return proxy.main_view
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()
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()
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()
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()
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.
700
from ubuntu_system_tests.helpers.webapp import _cpo # NOQA
702
pid = webapp.get_webapp_pid(web_app_package)
703
proxy = introspection.get_proxy_object_for_existing_process(
705
emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
707
return proxy.wait_select_single('BrowserWindow')
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)))
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
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)
731
def launch_calculator_app(self):
733
Launch calculator app from apps scope and return its proxy object.
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()
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')
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')
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(
755
return proxy.main_view
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')
761
def launch_ebay_webapp(self):
762
""" Launch the Ebay webapp from apps scope and return its proxy object
765
webapp_package = 'com.ubuntu.developer.webapps.webapp-ebay'
766
return self.launch_webapp(webapp_name, webapp_package)
768
def close_ebay_webapp(self):
769
""" Close the ebay webapp using task switcher """
770
if self.is_ebay_webapp_running():
772
'com.ubuntu.developer.webapps.webapp-ebay_webapp-ebay')
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)
779
def launch_here_webapp(self):
780
""" Launch the Here webapp from apps scope and return its proxy object
782
webapp_name = 'HERE Maps'
783
webapp_package = 'com.nokia.heremaps'
784
return self.launch_webapp(webapp_name, webapp_package)
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')
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)
796
def launch_music_app(self):
798
Launch the music app from apps scope and return proxy object.
800
:return: Proxy object for music application.
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()
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')
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')
816
def get_music_app_proxy(self):
818
Return music app proxy object from existing process.
820
:return: Proxy object for music application.
823
proxy = self._get_proxy_object_for_existing_qmlscene_process(
825
return proxy.wait_select_single(ubuntuuitoolkit.MainView)
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')
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)
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)