Example #1
0
    def test_dialer_clear_miss_call_notification(self):
        """
        Pre-requisites:
        Have a voicemail in the notification bar and a missed call notification

        Repro Steps:
        1) Open the notification panel and tap the missed call notification.
        2) After the call log appears, drop down the notification panel again.
        3) The notification for the call that was just tapped is no longer present.
        """
        PLIVO_TIMEOUT = 30
        plivo_phone_number = self.testvars["plivo"]["phone_number"]

        # Create a missed call notification
        from gaiatest.utils.plivo.plivo_util import PlivoUtil

        self.plivo = PlivoUtil(
            self.testvars["plivo"]["auth_id"], self.testvars["plivo"]["auth_token"], plivo_phone_number
        )
        self.call_uuid = self.plivo.make_call(
            to_number=self.testvars["local_phone_numbers"][0].replace("+", ""), timeout=PLIVO_TIMEOUT
        )

        call_screen = CallScreen(self.marionette)
        call_screen.wait_for_incoming_call()
        self.plivo.hangup_call(self.call_uuid)

        Wait(self.plivo, timeout=PLIVO_TIMEOUT).until(
            lambda p: p.is_call_completed(self.call_uuid), message="Plivo didn't report the call as completed"
        )
        self.call_uuid = None

        system = System(self.marionette)
        self.marionette.switch_to_frame()
        system.wait_for_notification_toaster_displayed()
        system.wait_for_notification_toaster_not_displayed()

        # Open the notification panel
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        # Verify the user sees the missed call event in the notification center
        notifications = utility_tray.notifications
        self.assertEqual(len(notifications), 2)
        self.assertEqual(notifications[0].title, "Missed call")
        # Remove the first digit (country code) which is not displayed for AT&T/USA - Bug 1088756
        self.assertTrue(plivo_phone_number[1:] in notifications[0].content)
        self.assertEqual(notifications[1].title, "Voicemail")

        notifications[0].tap_notification()

        self.marionette.switch_to_frame()
        system.open_utility_tray()
        notifications = utility_tray.notifications
        self.assertEqual(len(notifications), 1)
        self.assertEqual(notifications[0].title, "Voicemail")
    def test_dialer_clear_miss_call_notification(self):
        """
        Pre-requisites:
        Have a voicemail in the notification bar and a missed call notification

        Repro Steps:
        1) Open the notification panel and tap the missed call notification.
        2) After the call log appears, drop down the notification panel again.
        3) The notification for the call that was just tapped is no longer present.
        """
        plivo_phone_number = self.testvars['plivo']['phone_number']

        # Create a missed call notification
        from gaiatest.utils.plivo.plivo_util import PlivoUtil
        self.plivo = PlivoUtil(
            self.testvars['plivo']['auth_id'],
            self.testvars['plivo']['auth_token'],
            plivo_phone_number,
        )
        self.call_uuid = self.plivo.make_call(
            to_number=self.testvars['local_phone_numbers'][0].replace('+', ''))

        call_screen = CallScreen(self.marionette)
        call_screen.wait_for_incoming_call()

        self.plivo.hangup_call(self.call_uuid)
        self.plivo.wait_for_call_completed(self.call_uuid)
        self.call_uuid = None

        system = System(self.marionette)
        self.marionette.switch_to_frame()
        system.wait_for_notification_toaster_displayed()
        system.wait_for_notification_toaster_not_displayed()

        # Open the notification panel
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        # Verify the user sees the missed call event in the notification center
        notifications = utility_tray.notifications
        self.assertEqual(len(notifications), 2)
        self.assertEqual(notifications[0].title, 'Missed call')
        # Remove the first digit (country code) which is not displayed for AT&T/USA - Bug 1088756
        self.assertTrue(plivo_phone_number[1:] in notifications[0].content)
        self.assertEqual(notifications[1].title, 'Voicemail')

        notifications[0].tap_notification()

        self.marionette.switch_to_frame()
        system.open_utility_tray()
        notifications = utility_tray.notifications
        self.assertEqual(len(notifications), 1)
        self.assertEqual(notifications[0].title, 'Voicemail')
Example #3
0
    def test_dialer_clear_miss_call_notification(self):
        """
        Pre-requisites:
        Have a voicemail in the notification bar and a missed call notification

        Repro Steps:
        1) Open the notification panel and tap the missed call notification.
        2) After the call log appears, drop down the notification panel again.
        3) The notification for the call that was just tapped is no longer present.
        """
        plivo_phone_number = self.testvars['plivo']['phone_number']

        # Create a missed call notification
        from gaiatest.utils.plivo.plivo_util import PlivoUtil
        self.plivo = PlivoUtil(
            self.testvars['plivo']['auth_id'],
            self.testvars['plivo']['auth_token'],
            plivo_phone_number,
        )
        self.call_uuid = self.plivo.make_call(
            to_number=self.environment.phone_numbers[0].replace('+', ''))

        call_screen = CallScreen(self.marionette)
        call_screen.wait_for_incoming_call()

        self.plivo.hangup_call(self.call_uuid)
        self.plivo.wait_for_call_completed(self.call_uuid)
        self.call_uuid = None

        system = System(self.marionette)
        self.marionette.switch_to_frame()
        system.wait_for_notification_toaster_displayed()
        system.wait_for_notification_toaster_not_displayed()

        # Open the notification panel
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        # Verify the user sees the missed call event in the notification center
        notifications = utility_tray.notifications
        self.assertEqual(len(notifications), 2)
        self.assertEqual(notifications[0].title, 'Missed call')
        # Remove the first digit (country code) which is not displayed for AT&T/USA - Bug 1088756
        self.assertTrue(plivo_phone_number[1:] in notifications[0].content)
        self.assertEqual(notifications[1].title, 'Voicemail')

        notifications[0].tap_notification()

        self.marionette.switch_to_frame()
        system.open_utility_tray()
        notifications = utility_tray.notifications
        self.assertEqual(len(notifications), 1)
        self.assertEqual(notifications[0].title, 'Voicemail')
    def test_notification_bar(self):
        system = System(self.marionette)

        # Push a notification
        self.marionette.execute_script('navigator.mozNotification.createNotification("%s", "%s").show();'
                                       % (self._notification_title, self._notification_body))

        system.wait_for_notification_toaster_displayed()

        system.wait_for_notification_toaster_not_displayed()

        # Expand the notification bar
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()

        utility_tray.wait_for_notification_container_displayed()

        # Assert there is one notification is listed in notifications-container
        notifications = utility_tray.notifications
        self.assertEqual(1, len(notifications), 'Expected one notification.')

        # Assert notification is listed in notifications-container
        self.assertEqual(self._notification_body, notifications[0].content)

        # Clear the notification by "Clear all"
        utility_tray.clear_all_notifications()

        # wait for the notifications to be cleared
        self.wait_for_condition(lambda m: len(utility_tray.notifications) == 0)

        # Assert there is no notification is listed in notifications-container
        self.assertEqual(0, len(utility_tray.notifications))
    def test_sms_notification_removed_when_sms_deleted(self):
        """
        https://moztrap.mozilla.org/manage/case/8778/
        """

        _text_message_content = "Automated Test %s" % str(time.time())

        messages = Messages(self.marionette)
        messages.launch()

        self.data_layer.send_sms(self.environment.phone_numbers[0], _text_message_content, skip_verification=True)

        system = System(self.marionette)

        # We will wait upto 300 seconds for the SMS to arrive due to network latency
        system.wait_for_notification_toaster_displayed(timeout=300)
        system.wait_for_notification_toaster_not_displayed()

        self.apps.switch_to_displayed_app()

        message_thread = messages.tap_first_received_message()
        Wait(self.marionette).until(lambda m: len(message_thread.received_messages) > 0)
        messages_number = len(message_thread.all_messages)
        last_received_message = message_thread.received_messages[-1]

        activities = last_received_message.long_press_message()
        activities.tap_delete_message()
        activities.confirm_delete_message()

        Wait(self.marionette).until(lambda m: len(message_thread.all_messages) == messages_number - 1)

        self.marionette.switch_to_frame()

        utility_tray = system.open_utility_tray()
        self.assertEqual(0, len(utility_tray.notifications))
    def test_receive_active_sync_email(self):
        # setup ActiveSync account
        email = Email(self.marionette)
        email.launch()

        email.setup_active_sync_email(self.testvars['email']['ActiveSync'])

        # wait for sync to complete
        email.wait_for_emails_to_sync()

        # Touch home button to exit email app
        self.device.touch_home_button()

        # send email to active sync account
        mock_email = MockEmail(
            senders_email=self.testvars['email']['IMAP']['email'],
            recipients_email=self.testvars['email']['ActiveSync']['email'])
        EmailUtil().send(self.testvars['email']['IMAP'], mock_email)

        self.marionette.switch_to_frame()
        system = System(self.marionette)

        # Wait for email notification
        system.wait_for_notification_toaster_displayed(timeout=60)
        system.wait_for_notification_toaster_not_displayed()

        # Expand the notification bar
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        # Assert there is one notification is listed in notifications-container
        notifications = utility_tray.notifications
        self.assertEqual(1, len(notifications), 'Expected one notification.')
        email = notifications[0].tap_notification()

        self.wait_for_condition(
            lambda m: self.apps.displayed_app.name == "E-Mail")
        self.apps.switch_to_displayed_app()

        # check if the sender's email address is fine
        self.assertEqual(
            email.senders_email, mock_email.senders_email,
            'Senders\'s email on the inbox screen is incorrect. '
            'Expected email is %s. Actual email is %s.' %
            (mock_email.senders_email, email.senders_email))

        # check if the subject is fine
        self.assertEqual(
            email.subject, mock_email.subject,
            'Senders\'s email on the inbox scrseen is incorrect. '
            'Expected subject is %s. Actual subject is %s.' %
            (mock_email.subject, email.subject))

        # check if the email message is fine
        self.assertEqual(
            email.body, mock_email.message,
            'Email message on read email screen is incorrect. '
            'Expected message is "%s". Actual message is '
            '"%s".' % (mock_email.message, email.body))
    def test_notification_bar(self):
        system = System(self.marionette)

        # Push a notification
        self.marionette.execute_script(
            'new Notification("%s", {body: "%s"});' %
            (self._notification_title, self._notification_body))

        system.wait_for_notification_toaster_displayed(for_app='system')

        system.wait_for_notification_toaster_not_displayed()

        # Expand the notification bar
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()

        utility_tray.wait_for_notification_container_displayed()

        notifications = utility_tray.get_notifications(for_app='system')
        self.assertEqual(1, len(notifications),
                         'Expected one system notification.')
        email = notifications[0].tap_notification()

        # We cannot disable app update yet so let's wait for it to pass
        if system.is_app_update_notification_displayed:
            system.wait_for_app_update_to_clear()

        # Clear the notification by "Clear all"
        utility_tray.clear_all_notifications()

        # wait for the notifications to be cleared
        self.wait_for_condition(lambda m: len(utility_tray.notifications) == 0)

        # Assert there is no notification is listed in notifications-container
        self.assertEqual(0, len(utility_tray.notifications))
    def test_receive_active_sync_email(self):
        # setup ActiveSync account
        email = Email(self.marionette)
        email.launch()

        email.setup_active_sync_email(
            self.testvars['email']['ActiveSync'])

        # wait for sync to complete
        email.wait_for_emails_to_sync()

        # Touch home button to exit email app
        self.device.touch_home_button()

        # send email to active sync account
        mock_email = MockEmail(senders_email=self.testvars['email']['IMAP']['email'],
                               recipients_email=self.testvars['email']['ActiveSync']['email'])
        EmailUtil().send(self.testvars['email']['IMAP'], mock_email)

        self.marionette.switch_to_frame()

        system = System(self.marionette)

        # Wait for email notification
        system.wait_for_notification_toaster_displayed(timeout=30)
        system.wait_for_notification_toaster_not_displayed()

        # Expand the notification bar
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()

        utility_tray.wait_for_notification_container_displayed()

        # Assert there is one notification is listed in notifications-container
        notifications = utility_tray.notifications
        self.assertEqual(1, len(notifications), 'Expected one notification.')
        email = notifications[0].tap_notification()

        self.apps.switch_to_displayed_app()

        # check if the sender's email address is fine
        self.assertEqual(email.senders_email,
                         mock_email.senders_email,
                         'Senders\'s email on the inbox screen is incorrect. '
                         'Expected email is %s. Actual email is %s.' % (
                             mock_email.senders_email,
                             email.senders_email))

        # check if the subject is fine
        self.assertEqual(email.subject, mock_email.subject,
                         'Senders\'s email on the inbox scrseen is incorrect. '
                         'Expected subject is %s. Actual subject is %s.' % (
                             mock_email.subject, email.subject))

        # check if the email message is fine
        self.assertEqual(email.body, mock_email.message,
                         'Email message on read email screen is incorrect. '
                         'Expected message is "%s". Actual message is '
                         '"%s".' % (mock_email.message,
                                    email.body))
    def test_notification_bar(self):
        system = System(self.marionette)

        # Push a notification
        self.marionette.execute_script(
            'navigator.mozNotification.createNotification("%s", "%s").show();'
            % (self._notification_title, self._notification_body))

        system.wait_for_notification_toaster_displayed()

        system.wait_for_notification_toaster_not_displayed()

        # Expand the notification bar
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()

        utility_tray.wait_for_notification_container_displayed()

        # Assert there is one notification is listed in notifications-container
        notifications = utility_tray.notifications
        self.assertEqual(1, len(notifications), 'Expected one notification.')

        # Assert notification is listed in notifications-container
        self.assertEqual(self._notification_body, notifications[0].content)

        # Clear the notification by "Clear all"
        utility_tray.clear_all_notifications()

        # wait for the notifications to be cleared
        self.wait_for_condition(lambda m: len(utility_tray.notifications) == 0)

        # Assert there is no notification is listed in notifications-container
        self.assertEqual(0, len(utility_tray.notifications))
    def test_IMAP_email_notification(self):
        """ https://moztrap.mozilla.org/manage/case/10744/"""
        # setup email account
        self.email.setup_IMAP_email(self.testvars['email']['IMAP'])

        # check account has emails
        self.email.wait_for_emails_to_sync()
        self.assertGreater(len(self.email.mails), 0)

        # Touch home button to exit email app
        self.device.touch_home_button()

        # send email to IMAP account
        mock_email = MockEmail(senders_email=self.testvars['email']['IMAP']['email'],
                               recipients_email=self.testvars['email']['IMAP']['email'])
        EmailUtil().send(self.testvars['email']['IMAP'], mock_email)

        self.marionette.switch_to_frame()
        system = System(self.marionette)

        # Wait for email notification
        system.wait_for_notification_toaster_displayed(timeout=60)
        system.wait_for_notification_toaster_not_displayed()

        # Expand the notification bar
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        # Assert there is one notification and is listed in notifications-container
        notifications = utility_tray.notifications
        self.assertEqual(1, len(notifications), 'Expected one notification.')
        email = notifications[0].tap_notification()

        self.wait_for_condition(lambda m: self.apps.displayed_app.name == self.email.name)
        self.apps.switch_to_displayed_app()

        # Wait for senders email to be shown
        email.wait_for_senders_email_displayed()

        # check if the sender's email address is fine
        self.assertEqual(email.senders_email,
                         mock_email.senders_email,
                         'Senders\'s email on the inbox screen is incorrect. '
                         'Expected email is %s. Actual email is %s.' % (
                             mock_email.senders_email,
                             email.senders_email))

        # check if the subject is fine
        self.assertEqual(email.subject, mock_email.subject,
                         'Senders\'s email on the inbox screen is incorrect. '
                         'Expected subject is %s. Actual subject is %s.' % (
                             mock_email.subject, email.subject))

        # check if the email message is fine
        self.assertEqual(email.body, mock_email.message,
                         'Email message on read email screen is incorrect. '
                         'Expected message is "%s". Actual message is '
                         '"%s".' % (mock_email.message,
                                    email.body))
    def test_notification_bar(self):
        system = System(self.marionette)

        # Push a notification
        self.marionette.execute_script('new Notification("%s", {body: "%s"});'
                                       % (self._notification_title, self._notification_body))

        system.wait_for_notification_toaster_displayed(for_app='system')

        system.wait_for_notification_toaster_not_displayed()

        # Expand the notification bar
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()

        utility_tray.wait_for_notification_container_displayed()

        notifications = utility_tray.get_notifications(for_app='system')
        self.assertEqual(1, len(notifications), 'Expected one system notification.')

        self.assertEqual(self._notification_body, notifications[0].content)

        # We cannot disable app update yet so let's wait for it to pass
        if system.is_app_update_notification_displayed:
            system.wait_for_app_update_to_clear()

        # Clear the notification by "Clear all"
        utility_tray.clear_all_notifications()

        # wait for the notifications to be cleared
        self.wait_for_condition(lambda m: len(utility_tray.notifications) == 0)

        # Assert there is no notification is listed in notifications-container
        self.assertEqual(0, len(utility_tray.notifications))
Example #12
0
    def test_quick_settings_button(self):
        system = System(self.marionette)

        utility_tray = system.open_utility_tray()
        utility_tray.tap_settings_button()

        Settings(self.marionette).wait_to_be_displayed()
    def test_notification_bar(self):
        system = System(self.marionette)

        # Push a notification
        self.marionette.execute_script(
            'new Notification("%s", {body: "%s"});' %
            (self._notification_title, self._notification_body))

        system.wait_for_notification_toaster_displayed(for_app='system')
        system.wait_for_notification_toaster_not_displayed()
        system.wait_for_status_bar_displayed()

        utility_tray = system.open_utility_tray()
        notifications = utility_tray.get_notifications(for_app='system')
        self.assertEqual(1, len(notifications),
                         'Expected one system notification.')
        self.assertEqual(self._notification_body, notifications[0].content)

        # We cannot disable app update yet so let's wait for it to pass
        if system.is_app_update_notification_displayed:
            system.wait_for_app_update_to_clear()

        utility_tray.clear_all_notifications()

        self.assertEqual(0, len(utility_tray.notifications))
Example #14
0
    def test_IMAP_email_notification(self):
        """ https://moztrap.mozilla.org/manage/case/10744/"""
        # setup email account
        self.email.setup_IMAP_email(self.environment.email['imap'],
                                    self.environment.email['smtp'])

        # check account has emails
        self.email.wait_for_emails_to_sync()
        self.assertGreater(len(self.email.mails), 0)

        # Touch home button to exit email app
        self.device.touch_home_button()

        # send email to IMAP account
        mock_email = MockEmail(self.environment.host['smtp']['email'],
                               self.environment.email['imap']['email'])
        EmailUtil().send(self.environment.host['smtp'], mock_email)

        self.marionette.switch_to_frame()
        system = System(self.marionette)

        # Wait for email notification
        system.wait_for_notification_toaster_displayed(timeout=60,
                                                       for_app='email')
        system.wait_for_notification_toaster_not_displayed()

        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()

        notifications = utility_tray.get_notifications(for_app='email')
        self.assertEqual(1, len(notifications),
                         'Expected one email notification.')
        email = notifications[0].tap_notification()

        email.wait_to_be_displayed()
        self.apps.switch_to_displayed_app()

        # Wait for senders email to be shown
        email.wait_for_senders_email_displayed()

        # check if the sender's email address is fine
        self.assertEqual(
            email.senders_email, mock_email['from'],
            'Senders\'s email on the inbox screen is incorrect. '
            'Expected email is %s. Actual email is %s.' %
            (mock_email['from'], email.senders_email))

        # check if the subject is fine
        self.assertEqual(
            email.subject, mock_email['subject'],
            'Senders\'s email on the inbox screen is incorrect. '
            'Expected subject is %s. Actual subject is %s.' %
            (mock_email['subject'], email.subject))

        # check if the email message is fine
        self.assertEqual(
            email.body, mock_email['message'],
            'Email message on read email screen is incorrect. '
            'Expected message is "%s". Actual message is '
            '"%s".' % (mock_email['message'], email.body))
Example #15
0
    def test_IMAP_email_notification(self):
        """ https://moztrap.mozilla.org/manage/case/10744/"""
        # setup email account
        self.email.setup_IMAP_email(self.testvars['email']['IMAP'])

        # check account has emails
        self.email.wait_for_emails_to_sync()
        self.assertGreater(len(self.email.mails), 0)

        # Touch home button to exit email app
        self.device.touch_home_button()

        # send email to IMAP account
        mock_email = MockEmail(
            senders_email=self.testvars['email']['IMAP']['email'],
            recipients_email=self.testvars['email']['IMAP']['email'])
        EmailUtil().send(self.testvars['email']['IMAP'], mock_email)

        self.marionette.switch_to_frame()
        system = System(self.marionette)

        # Wait for email notification
        system.wait_for_notification_toaster_displayed(timeout=60)
        system.wait_for_notification_toaster_not_displayed()

        # Expand the notification bar
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        # Assert there is one notification and is listed in notifications-container
        notifications = utility_tray.notifications
        self.assertEqual(1, len(notifications), 'Expected one notification.')
        email = notifications[0].tap_notification()

        self.wait_for_condition(
            lambda m: self.apps.displayed_app.name == self.email.name)
        self.apps.switch_to_displayed_app()

        # check if the sender's email address is fine
        self.assertEqual(
            email.senders_email, mock_email.senders_email,
            'Senders\'s email on the inbox screen is incorrect. '
            'Expected email is %s. Actual email is %s.' %
            (mock_email.senders_email, email.senders_email))

        # check if the subject is fine
        self.assertEqual(
            email.subject, mock_email.subject,
            'Senders\'s email on the inbox screen is incorrect. '
            'Expected subject is %s. Actual subject is %s.' %
            (mock_email.subject, email.subject))

        # check if the email message is fine
        self.assertEqual(
            email.body, mock_email.message,
            'Email message on read email screen is incorrect. '
            'Expected message is "%s". Actual message is '
            '"%s".' % (mock_email.message, email.body))
    def test_dialer_miss_call_from_known_contact_notification(self):
        """
        https://moztrap.mozilla.org/manage/case/9294/
        """
        PLIVO_TIMEOUT = 30

        self.device.lock()

        from gaiatest.utils.plivo.plivo_util import PlivoUtil
        self.plivo = PlivoUtil(
            self.testvars['plivo']['auth_id'],
            self.testvars['plivo']['auth_token'],
            self.testvars['plivo']['phone_number']
        )
        self.call_uuid = self.plivo.make_call(
            to_number=self.testvars['local_phone_numbers'][0].replace('+', ''),
            timeout=PLIVO_TIMEOUT)

        call_screen = CallScreen(self.marionette)
        call_screen.wait_for_incoming_call_with_locked_screen()
        self.plivo.hangup_call(self.call_uuid)

        Wait(self.plivo, timeout=PLIVO_TIMEOUT).until(
            lambda p: p.is_call_completed(self.call_uuid),
            message="Plivo didn't report the call as completed")
        self.call_uuid = None

        lock_screen = LockScreen(self.marionette)
        lock_screen.switch_to_frame()
        lock_screen.wait_for_notification()

        # Check if the screen is turned on
        self.assertTrue(self.device.is_screen_enabled)

        # Verify the user sees a missed call notification message
        # and the known contacts info is shown.
        self.assertTrue(lock_screen.notifications[0].is_visible)
        self.assertEqual(lock_screen.notifications[0].title, 'Missed call')
        self.assertTrue(self.contact.givenName in lock_screen.notifications[0].content)

        self.device.unlock()

        system = System(self.marionette)
        system.wait_for_notification_toaster_not_displayed()

        # Expand the notification bar
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        # Verify the user sees the missed call event in the notification center
        # and the known contacts info is shown.
        notifications = utility_tray.notifications
        self.assertEqual(notifications[0].title, 'Missed call')
        self.assertTrue(self.contact.givenName in notifications[0].content)
    def test_IMAP_email_notification(self):
        """ https://moztrap.mozilla.org/manage/case/10744/"""
        # setup email account
        self.email.setup_IMAP_email(self.environment.email['imap'],
                                    self.environment.email['smtp'])

        # check account has emails
        self.email.wait_for_emails_to_sync()
        self.assertGreater(len(self.email.mails), 0)

        # Touch home button to exit email app
        self.device.touch_home_button()

        # send email to IMAP account
        mock_email = MockEmail(self.environment.host['smtp']['email'],
                               self.environment.email['imap']['email'])
        EmailUtil().send(self.environment.host['smtp'], mock_email)

        self.marionette.switch_to_frame()
        system = System(self.marionette)

        # Wait for email notification
        system.wait_for_notification_toaster_displayed(timeout=60, for_app='email')
        system.wait_for_notification_toaster_not_displayed()

        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()

        notifications = utility_tray.get_notifications(for_app='email')
        self.assertEqual(1, len(notifications), 'Expected one email notification.')
        email = notifications[0].tap_notification()

        email.wait_to_be_displayed()
        self.apps.switch_to_displayed_app()

        # Wait for senders email to be shown
        email.wait_for_senders_email_displayed()

        # check if the sender's email address is fine
        self.assertEqual(email.senders_email, mock_email['from'],
                         'Senders\'s email on the inbox screen is incorrect. '
                         'Expected email is %s. Actual email is %s.' % (
                             mock_email['from'], email.senders_email))

        # check if the subject is fine
        self.assertEqual(email.subject, mock_email['subject'],
                         'Senders\'s email on the inbox screen is incorrect. '
                         'Expected subject is %s. Actual subject is %s.' % (
                             mock_email['subject'], email.subject))

        # check if the email message is fine
        self.assertEqual(email.body, mock_email['message'],
                         'Email message on read email screen is incorrect. '
                         'Expected message is "%s". Actual message is '
                         '"%s".' % (mock_email['message'], email.body))
Example #18
0
    def test_cost_control_data_alert_mobile(self):
        """https://moztrap.mozilla.org/manage/case/8938/"""

        cost_control = CostControl(self.marionette)
        cost_control.launch()

        cost_control.switch_to_ftu()
        cost_control.run_ftu_accepting_defaults()

        self.assertTrue(cost_control.is_mobile_data_tracking_on)
        self.assertFalse(cost_control.is_wifi_data_tracking_on)

        settings = cost_control.tap_settings()
        self.assertFalse(settings.is_data_alert_switch_checked)
        settings.toggle_data_alert_switch()
        self.assertTrue(settings.is_data_alert_switch_checked)
        settings.reset_mobile_usage()
        settings.select_when_use_is_above_unit_and_value(u'MB', '0.1')
        settings.tap_done()
        self.assertTrue(cost_control.is_mobile_data_tracking_on)

        # open browser to get some data downloaded
        search = Search(self.marionette)
        search.launch(launch_timeout=30000)
        browser = search.go_to_url(
            'http://mozqa.com/qa-testcase-data/Images/sample_png_02.png')
        browser.wait_for_page_to_load(180)

        browser.switch_to_content()
        Wait(self.marionette,
             timeout=60).until(lambda m: "sample_png_02.png" in m.title)
        browser.switch_to_chrome()

        system = System(self.marionette)
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        # switch to cost control widget
        usage_iframe = self.marionette.find_element(
            *self._cost_control_widget_locator)
        self.marionette.switch_to_frame(usage_iframe)

        # make sure the color changed
        # The timeout is increased, because for some reason, it takes some time
        # before the limit view is shown (the browser has to finish loading?)
        usage_view = self.marionette.find_element(
            *self._data_usage_view_locator)
        Wait(self.marionette, timeout=40).until(
            lambda m: 'reached-limit' in usage_view.get_attribute('class'),
            message='Data usage bar did not breach limit')
        usage_view.tap()

        self.wait_for_condition(
            lambda m: self.apps.displayed_app.name == cost_control.name)
    def test_dialer_miss_call_from_known_contact_notification(self):
        """
        https://moztrap.mozilla.org/manage/case/9294/
        """
        PLIVO_TIMEOUT = 30

        self.device.lock()

        from gaiatest.utils.plivo.plivo_util import PlivoUtil
        self.plivo = PlivoUtil(self.testvars['plivo']['auth_id'],
                               self.testvars['plivo']['auth_token'],
                               self.testvars['plivo']['phone_number'])
        self.call_uuid = self.plivo.make_call(
            to_number=self.testvars['local_phone_numbers'][0].replace('+', ''),
            timeout=PLIVO_TIMEOUT)

        call_screen = CallScreen(self.marionette)
        call_screen.wait_for_incoming_call_with_locked_screen()
        self.plivo.hangup_call(self.call_uuid)

        Wait(self.plivo, timeout=PLIVO_TIMEOUT).until(
            lambda p: p.is_call_completed(self.call_uuid),
            message="Plivo didn't report the call as completed")
        self.call_uuid = None

        lock_screen = LockScreen(self.marionette)
        lock_screen.switch_to_frame()
        lock_screen.wait_for_notification()

        # Check if the screen is turned on
        self.assertTrue(self.device.is_screen_enabled)

        # Verify the user sees a missed call notification message
        # and the known contacts info is shown.
        self.assertTrue(lock_screen.notifications[0].is_visible)
        self.assertEqual(lock_screen.notifications[0].title, 'Missed call')
        self.assertTrue(
            self.contact.givenName in lock_screen.notifications[0].content)

        self.device.unlock()

        system = System(self.marionette)
        system.wait_for_notification_toaster_not_displayed()

        # Expand the notification bar
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        # Verify the user sees the missed call event in the notification center
        # and the known contacts info is shown.
        notifications = utility_tray.notifications
        self.assertEqual(notifications[0].title, 'Missed call')
        self.assertTrue(self.contact.givenName in notifications[0].content)
Example #20
0
    def test_quick_settings_button(self):
        system = System(self.marionette)

        # Expand the utility tray
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        #tap the settings button
        utility_tray.tap_settings_button()

        #wait for and assert that settings app is launched
        self.wait_for_condition(lambda m: self.apps.displayed_app.name == "Settings")
Example #21
0
    def test_quick_settings_button(self):
        system = System(self.marionette)

        # Expand the utility tray
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        #tap the settings button
        utility_tray.tap_settings_button()

        #wait for and assert that settings app is launched
        self.wait_for_condition(
            lambda m: self.apps.displayed_app.name == "Settings")
Example #22
0
    def test_quick_settings_button(self):
        system = System(self.marionette)

        # Expand the utility tray
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        #tap the settings button
        utility_tray.tap_settings_button()

        #wait for and assert that settings app is launched
        from gaiatest.apps.settings.app import Settings
        Settings(self.marionette).wait_to_be_displayed()
Example #23
0
    def test_quick_settings_button(self):
        system = System(self.marionette)

        # Expand the utility tray
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        #tap the settings button
        utility_tray.tap_settings_button()

        #wait for and assert that settings app is launched
        from gaiatest.apps.settings.app import Settings
        Settings(self.marionette).wait_to_be_displayed()
    def test_dialer_miss_call_from_known_contact_notification(self):
        """
        https://moztrap.mozilla.org/manage/case/9294/
        """
        self.device.lock()

        from gaiatest.utils.plivo.plivo_util import PlivoUtil

        self.plivo = PlivoUtil(
            self.testvars["plivo"]["auth_id"],
            self.testvars["plivo"]["auth_token"],
            self.testvars["plivo"]["phone_number"],
        )
        self.call_uuid = self.plivo.make_call(to_number=self.environment.phone_numbers[0].replace("+", ""))

        call_screen = CallScreen(self.marionette)
        call_screen.wait_for_incoming_call()

        self.plivo.hangup_call(self.call_uuid)
        self.plivo.wait_for_call_completed(self.call_uuid)
        self.call_uuid = None

        lock_screen = LockScreen(self.marionette)
        lock_screen.switch_to_frame()
        lock_screen.wait_for_notification()

        # Check if the screen is turned on
        self.assertTrue(self.device.is_screen_enabled)

        # Verify the user sees a missed call notification message
        # and the known contacts info is shown.
        self.assertTrue(lock_screen.notifications[0].is_visible)
        self.assertEqual(lock_screen.notifications[0].title, "Missed call")
        self.assertTrue(self.contact.givenName in lock_screen.notifications[0].content)

        self.device.unlock()

        system = System(self.marionette)
        system.wait_for_notification_toaster_not_displayed()

        # Expand the notification bar
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        # Verify the user sees the missed call event in the notification center
        # and the known contacts info is shown.
        notifications = utility_tray.notifications
        self.assertEqual(notifications[0].title, "Missed call")
        self.assertTrue(self.contact.givenName in notifications[0].content)
class TestUtilityTraySettingsAccessibility(GaiaTestCase):

    def setUp(self):
        GaiaTestCase.setUp(self)
        self.system = System(self.marionette)

    def test_a11y_utility_tray_settings(self):
        self.system.wait_for_status_bar_displayed()

        utility_tray = self.system.open_utility_tray()
        settings = utility_tray.a11y_click_quick_settings_full_app()

        # Make sure that Settings is the currently displayed app.
        Wait(self.marionette).until(lambda m: self.apps.displayed_app.name == settings.name)
class TestUtilityTraySettingsAccessibility(GaiaTestCase):
    def setUp(self):
        GaiaTestCase.setUp(self)
        self.system = System(self.marionette)

    def test_a11y_utility_tray_settings(self):
        self.system.wait_for_status_bar_displayed()

        utility_tray = self.system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        settings = utility_tray.a11y_click_quick_settings_full_app()

        # Make sure that Settings is the currently displayed app.
        self.assertEquals(self.apps.displayed_app.name, settings.name)
    def test_cost_control_data_alert_mobile(self):
        """https://moztrap.mozilla.org/manage/case/8938/"""

        cost_control = CostControl(self.marionette)
        cost_control.launch()

        cost_control.switch_to_ftu()
        cost_control.run_ftu_accepting_defaults()

        self.assertTrue(cost_control.is_mobile_data_tracking_on)
        self.assertFalse(cost_control.is_wifi_data_tracking_on)

        settings = cost_control.tap_settings()
        self.assertFalse(settings.is_data_alert_switch_checked)
        settings.toggle_data_alert_switch()
        self.assertTrue(settings.is_data_alert_switch_checked)
        settings.reset_mobile_usage()
        settings.select_when_use_is_above_unit_and_value(u'MB', '0.1')
        settings.tap_done()
        self.assertTrue(cost_control.is_mobile_data_tracking_on)

        # open browser to get some data downloaded
        search = Search(self.marionette)
        search.launch(launch_timeout=30000)
        browser = search.go_to_url('http://mozqa.com/qa-testcase-data/Images/sample_png_02.png')
        browser.wait_for_page_to_load(180)

        browser.switch_to_content()
        Wait(self.marionette, timeout=60).until(lambda m: "sample_png_02.png" in m.title)
        browser.switch_to_chrome()

        system = System(self.marionette)
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        # switch to cost control widget
        usage_iframe = self.marionette.find_element(*self._cost_control_widget_locator)
        self.marionette.switch_to_frame(usage_iframe)

        # make sure the color changed
        # The timeout is increased, because for some reason, it takes some time
        # before the limit view is shown (the browser has to finish loading?)
        usage_view = self.marionette.find_element(*self._data_usage_view_locator)
        Wait(self.marionette, timeout=40).until(lambda m: 'reached-limit' in usage_view.get_attribute('class'),
             message='Data usage bar did not breach limit')
        usage_view.tap()

        self.wait_for_condition(lambda m: self.apps.displayed_app.name == cost_control.name)
class TestUtilityTraySettingsAccessibility(GaiaTestCase):

    def setUp(self):
        GaiaTestCase.setUp(self)
        self.system = System(self.marionette)

    def test_a11y_utility_tray_settings(self):
        self.system.wait_for_status_bar_displayed()

        utility_tray = self.system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        settings = utility_tray.a11y_click_quick_settings_full_app()

        # Make sure that Settings is the currently displayed app.
        self.assertEquals(self.apps.displayed_app.name, settings.name)
    def test_sms_notification_removed_when_sms_deleted(self):
        """
        https://moztrap.mozilla.org/manage/case/8778/
        """

        _text_message_content = "Automated Test %s" % str(time.time())

        # launch messages app
        messages = Messages(self.marionette)
        messages.launch()

        # Send a SMS to the device
        self.data_layer.send_sms(self.environment.phone_numbers[0],
                                 _text_message_content,
                                 skip_verification=True)

        system = System(self.marionette)

        # We will wait upto 300 seconds for the SMS to arrive due to network latency
        system.wait_for_notification_toaster_displayed(
            timeout=300,
            message="Notification did not appear. SMS database dump: %s " %
            self.data_layer.get_all_sms())
        system.wait_for_notification_toaster_not_displayed()

        self.apps.switch_to_displayed_app()

        # Tap on the latest received SMS
        message_thread = messages.tap_first_received_message()
        Wait(self.marionette).until(
            lambda m: len(message_thread.received_messages) > 0)
        messages_number = len(message_thread.all_messages)
        last_received_message = message_thread.received_messages[-1]

        # Delete latest received SMS
        activities = last_received_message.long_press_message()
        activities.tap_delete_message()
        activities.confirm_delete_message()

        Wait(self.marionette).until(
            lambda m: len(message_thread.all_messages) == messages_number - 1)

        self.marionette.switch_to_frame()

        # Check that SMS notification no longer appears in utility tray
        utility_tray = system.open_utility_tray()
        self.assertEqual(0, len(utility_tray.notifications))
Example #30
0
    def test_sms_notification_removed_when_sms_deleted(self):
        """
        https://moztrap.mozilla.org/manage/case/8778/
        """

        _text_message_content = "Automated Test %s" % str(time.time())

        # launch messages app
        messages = Messages(self.marionette)
        messages.launch()

        # Send a SMS to the device
        self.data_layer.send_sms(self.testvars["local_phone_numbers"][0], _text_message_content)

        system = System(self.marionette)

        # We will wait upto 300 seconds for the SMS to arrive due to network latency
        system.wait_for_notification_toaster_displayed(
            timeout=300, message="Notification did not appear. SMS database dump: %s " % self.data_layer.get_all_sms()
        )
        system.wait_for_notification_toaster_not_displayed()

        self.apps.switch_to_displayed_app()

        # Tap on the latest received SMS
        message_thread = messages.tap_first_received_message()
        Wait(self.marionette).until(lambda m: len(message_thread.received_messages) > 0)
        messages_number = len(message_thread.all_messages)
        last_received_message = message_thread.received_messages[-1]

        # Delete latest received SMS
        activities = last_received_message.long_press_message()
        activities.tap_delete_message()
        activities.confirm_delete_message()

        Wait(self.marionette).until(lambda m: len(message_thread.all_messages) == messages_number - 1)

        self.marionette.switch_to_frame()

        # Check that SMS notification no longer appears in utility tray
        utility_tray = system.open_utility_tray()
        self.assertEqual(0, len(utility_tray.notifications))
class TestUtilityTrayNotificationsAccessibility(GaiaTestCase):
    def setUp(self):
        GaiaTestCase.setUp(self)
        self.system = System(self.marionette)

    def test_a11y_utility_tray_notifications(self):
        self.system.wait_for_status_bar_displayed()

        utility_tray = self.system.open_utility_tray()

        self.marionette.execute_script(
            'new Notification("Title", {body: "Body"});')
        # Assert there is one notification is listed in notifications-container
        notifications = utility_tray.notifications
        self.assertEqual(1, len(notifications), 'Expected one notification.')

        # Clear the notification by "Clear all"
        utility_tray.a11y_clear_all_notifications()

        # wait for the notifications to be cleared
        self.wait_for_condition(lambda m: len(utility_tray.notifications) == 0)
class TestUtilityTrayNotificationsAccessibility(GaiaTestCase):

    def setUp(self):
        GaiaTestCase.setUp(self)
        self.system = System(self.marionette)

    def test_a11y_utility_tray_notifications(self):
        self.system.wait_for_status_bar_displayed()

        utility_tray = self.system.open_utility_tray()

        self.marionette.execute_script('new Notification("Title", {body: "Body"});')
        # Assert there is one notification is listed in notifications-container
        notifications = utility_tray.notifications
        self.assertEqual(1, len(notifications), 'Expected one notification.')

        # Clear the notification by "Clear all"
        utility_tray.a11y_clear_all_notifications()

        # wait for the notifications to be cleared
        self.wait_for_condition(lambda m: len(utility_tray.notifications) == 0)
    def test_cost_control_data_alert_mobile(self):
        """https://moztrap.mozilla.org/manage/case/8938/"""

        cost_control = CostControl(self.marionette)
        cost_control.launch()

        cost_control.switch_to_ftu()
        cost_control.run_ftu_accepting_defaults()

        self.assertTrue(cost_control.is_mobile_data_tracking_on)
        self.assertFalse(cost_control.is_wifi_data_tracking_on)

        settings = cost_control.tap_settings()
        self.assertFalse(settings.is_data_alert_switch_checked)
        settings.toggle_data_alert_switch()
        self.assertTrue(settings.is_data_alert_switch_checked)
        settings.reset_mobile_usage()
        settings.select_when_use_is_above_unit_and_value(u'MB', '0.1')
        settings.tap_done()
        self.assertTrue(cost_control.is_mobile_data_tracking_on)

        # open browser to get some data downloaded
        search = Search(self.marionette)
        search.launch(launch_timeout=30000)
        search.go_to_url('http://mozqa.com/qa-testcase-data/Images/sample_png_02.png')

        system = System(self.marionette)
        # We could have waited on the page to be loaded, but the toaster can appear before
        # the end of the load. That's why the timeout is expanded, the webpage loaded just above
        # might take longer.
        system.wait_for_notification_toaster_displayed(timeout=180)
        system.wait_for_notification_toaster_not_displayed()
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        cost_control_widget = utility_tray.cost_control_widget
        cost_control_widget.wait_for_limit_to_be_reached()
        cost_control_widget.tap()
        Wait(self.marionette).until(lambda m: self.apps.displayed_app.name == cost_control.name)
    def test_cost_control_data_alert_mobile(self):
        """https://moztrap.mozilla.org/manage/case/8938/"""

        cost_control = CostControl(self.marionette)
        cost_control.launch()

        cost_control.switch_to_ftu()
        cost_control.run_ftu_accepting_defaults()

        self.assertTrue(cost_control.is_mobile_data_tracking_on)
        self.assertFalse(cost_control.is_wifi_data_tracking_on)

        settings = cost_control.tap_settings()
        settings.enable_data_alert_switch()
        settings.reset_mobile_usage()
        settings.select_when_use_is_above_unit_and_value(u'MB', '0.1')
        settings.tap_done()
        self.assertTrue(cost_control.is_mobile_data_tracking_on)

        # open browser to get some data downloaded
        search = Search(self.marionette)
        search.launch(launch_timeout=30000)
        search.go_to_url(
            'http://mozqa.com/qa-testcase-data/Images/sample_png_02.png')

        system = System(self.marionette)
        # We could have waited on the page to be loaded, but the toaster can appear before
        # the end of the load. That's why the timeout is expanded, the webpage loaded just above
        # might take longer.
        system.wait_for_notification_toaster_displayed(timeout=180)
        system.wait_for_notification_toaster_not_displayed()
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        cost_control_widget = utility_tray.cost_control_widget
        cost_control_widget.wait_for_limit_to_be_reached()
        cost_control_widget.tap()
        cost_control.wait_to_be_displayed()
    def test_notification_bar(self):
        system = System(self.marionette)

        # Push a notification
        self.marionette.execute_script('new Notification("%s", {body: "%s"});'
                                       % (self._notification_title, self._notification_body))

        system.wait_for_notification_toaster_displayed(for_app='system')
        system.wait_for_notification_toaster_not_displayed()
        system.wait_for_status_bar_displayed()

        utility_tray = system.open_utility_tray()
        notifications = utility_tray.get_notifications(for_app='system')
        self.assertEqual(1, len(notifications), 'Expected one system notification.')
        self.assertEqual(self._notification_body, notifications[0].content)

        # We cannot disable app update yet so let's wait for it to pass
        if system.is_app_update_notification_displayed:
            system.wait_for_app_update_to_clear()

        utility_tray.clear_all_notifications()

        self.assertEqual(0, len(utility_tray.notifications))
    def test_receive_active_sync_email(self):
        # setup ActiveSync account
        email = Email(self.marionette)
        email.launch()

        email.setup_active_sync_email(self.environment.email["activesync"])

        # wait for sync to complete
        email.wait_for_emails_to_sync()

        # Touch home button to exit email app
        self.device.touch_home_button()

        # send email to active sync account
        mock_email = MockEmail(self.environment.host["smtp"]["email"], self.environment.email["activesync"]["email"])
        EmailUtil().send(self.environment.host["smtp"], mock_email)

        self.marionette.switch_to_frame()
        system = System(self.marionette)

        # Wait for email notification
        system.wait_for_notification_toaster_displayed(timeout=60)
        system.wait_for_notification_toaster_not_displayed()

        # Expand the notification bar
        system.wait_for_status_bar_displayed()
        utility_tray = system.open_utility_tray()
        utility_tray.wait_for_notification_container_displayed()

        # Assert there is one notification is listed in notifications-container
        notifications = utility_tray.notifications
        self.assertEqual(1, len(notifications), "Expected one notification.")
        email = notifications[0].tap_notification()

        self.wait_for_condition(lambda m: self.apps.displayed_app.name == "E-Mail")
        self.apps.switch_to_displayed_app()

        # check if the sender's email address is fine
        self.assertEqual(
            email.senders_email,
            mock_email["from"],
            "Senders's email on the inbox screen is incorrect. "
            "Expected email is %s. Actual email is %s." % (mock_email["from"], email.senders_email),
        )

        # check if the subject is fine
        self.assertEqual(
            email.subject,
            mock_email["subject"],
            "Senders's email on the inbox scrseen is incorrect. "
            "Expected subject is %s. Actual subject is %s." % (mock_email["subject"], email.subject),
        )

        # check if the email message is fine
        self.assertEqual(
            email.body,
            mock_email["message"],
            "Email message on read email screen is incorrect. "
            'Expected message is "%s". Actual message is '
            '"%s".' % (mock_email["message"], email.body),
        )
Example #37
0
class statusbar(object):

    def __init__(self, parent):
        self.parent = parent
        self.marionette = parent.marionette
        self.system = System(self.marionette)

    def clearAllStatusBarNotifs(self):
        """Open the system tray and clear all notifications.
        """
        self.marionette.switch_to_frame()
        utility_tray = self.system.open_utility_tray()
        # utility_tray.wait_for_notification_container_displayed()
        # Gaiatestcase wait_for_notification_container_displayed not working properly
        # so we have to manually wait some time in order to make sure the statusbar
        # is fully shown
        time.sleep(2)
        utility_tray.clear_all_notifications()

    def displayStatusBar(self):
        """
        Displays the status / notification bar in the home screen.
        The only reliable way I have to do this at the moment is via JS
        (tapping it only worked sometimes).
        """
        self.marionette.switch_to_frame()
        self.marionette.execute_script("window.wrappedJSObject.UtilityTray.show()")
        time.sleep(0.5)

    def hideStatusBar(self):
        """
        Displays the status / notification bar in the home screen.
        The only reliable way I have to do this at the moment is via JS
        (tapping it only worked sometimes).
        """
        self.marionette.switch_to_frame()
        self.marionette.execute_script("window.wrappedJSObject.UtilityTray.hide()")

    def isIconInStatusBar(self, p_dom):
        """
        Check an icon is in the statusbar, then return to the
        given frame (doesn't wait, just expects it to be there).
        """
        orig_iframe = self.parent.iframe.currentIframe()
        self.marionette.switch_to_frame()

        found = False
        try:
            self.parent.parent.wait_for_element_displayed(*p_dom, timeout=1)
            found = True
        except:
            pass

        if orig_iframe:
            self.parent.iframe.switchToFrame("src", orig_iframe)

        return found

    def openSettingFromStatusbar(self):
        """
        As it says on the tin - opens the settings
        app via the statusbar.
        """
        self.displayStatusBar()
        x = self.parent.element.getElement(DOM.Statusbar.settings_button, "Settings button")
        x.tap()

        time.sleep(2)

        self.marionette.switch_to_frame()
        self.parent.iframe.switchToFrame(*DOM.Settings.frame_locator)

    def toggleViaStatusBar(self, p_type):
        """
        Uses the statusbar to toggle items on or off. Just toggles.
        Accepted 'types' are: data, wifi, airplane, bluetooth
        """
        self.parent.reporting.logResult("info", "Toggling " + p_type + " mode via statusbar ...")

        # Toggle (and wait)
        if p_type == "data":
            locator = DOM.Statusbar.toggle_dataconn
        if p_type == "wifi":
            locator = DOM.Statusbar.toggle_wifi
        if p_type == "bluetooth":
            locator = DOM.Statusbar.toggle_bluetooth
        if p_type == "airplane":
            locator = DOM.Statusbar.toggle_airplane

        return self._toggle_and_wait(locator, p_type)

    def _toggle_and_wait(self, locator, p_type):
        """
        (private) Toggle a button in the statusbar and waits for the item to be enabled/disabled
        Don't call this directly, it's used by toggleViaStatusBar().
        """

        # Open the status bar.
        self.displayStatusBar()
        boolWasEnabled = self.parent.network.is_network_type_enabled(p_type)

        toggle_icon = self.parent.element.getElement(locator, "Toggle {} icon".format(p_type))
        toggle_icon.tap()
        """
        Sometimes, when we activate data connection, the devices goes till settings and
        show a confirmation screen. We have to accept it.
        """
        success = self.parent.iframe.switchToFrame(DOM.Settings.frame_locator[0], DOM.Settings.frame_locator[1],
                                         quit_on_error=True, via_root_frame=True, test=False)
        if success:
            self.parent.element.waitForElements(DOM.Settings.celldata_DataConn_confirm_header,
                "Confirmation header", True, 40)

            ok_btn = self.marionette.find_element(*DOM.Settings.celldata_DataConn_ON)
            ok_btn.tap()
        else:
            # No confirmation required
            self.parent.reporting.logResult("debug", "No 3G confirmation asked")

        if boolWasEnabled:
            boolReturn = self.parent.network.wait_for_network_item_disabled(p_type)
        else:
            boolReturn = self.parent.network.wait_for_network_item_enabled(p_type)

        self.hideStatusBar()
        return boolReturn

    def waitForStatusBarNew(self, p_dom=DOM.Statusbar.status_bar_new, p_displayed=True, p_timeOut=20):

        # Waits for a new notification in the status bar (20s timeout by default).
        orig_iframe = self.parent.iframe.currentIframe()
        self.marionette.switch_to_frame()

        x = self.parent.element.waitForElements(p_dom, "This statusbar icon", p_displayed, p_timeOut)

        # Only switch if not called from the 'start' screen ...
        if orig_iframe != '':
            self.parent.iframe.switchToFrame("src", orig_iframe, False)

        return x

    def click_on_notification(self, dom, text, frame_to_change=None, timeout=30):
        """
        Clicks on a certain notification looking for the given text in the
        given DOM element (title or detail) for the specified timeout.
        If frame_to_change is not None, frame will be set to its value.
        """
        self.displayStatusBar()
        time.sleep(1)
        elem_dom = (dom[0], dom[1].format(text))
        self.parent.parent.wait_for_element_displayed(elem_dom[0], elem_dom[1], timeout)
        notif = self.marionette.find_element(elem_dom[0], elem_dom[1])
        notif.tap()

        if frame_to_change:
            self.parent.iframe.switchToFrame(*frame_to_change)

    def click_on_notification_title(self, text, frame_to_change=None, timeout=30):
        """Clicks on a certain notification (given by its title)
        """
        self.click_on_notification(DOM.Statusbar.notification_statusbar_title, text, frame_to_change, timeout)

    def click_on_notification_detail(self, text, frame_to_change=None, timeout=30):
        """Clicks on a certain notification (given by its body)
        """
        self.click_on_notification(DOM.Statusbar.notification_statusbar_detail, text, frame_to_change, timeout)

    @retry(2, 10)
    def wait_for_notification_toaster_title(self, text, frame_to_change=None, notif_text=None, timeout=30):
        """
        Waits for a new popup notification which contains a certain title
        """
        self.marionette.switch_to_frame()

        dom = (DOM.Statusbar.notification_toaster_title[0], DOM.Statusbar.notification_toaster_title[1].format(text))
        self.parent.reporting.debug(u"** Waiting for notification toaster title: [{}]".format(dom))
        self.parent.parent.wait_for_element_present(dom[0], dom[1], timeout)

        # Check if the notification actually exists or if it is a "ghost" one.
        # Note that we can use either @text or @notif_text
        self.wait_for_notification_statusbar_title(notif_text if notif_text else text)

        if frame_to_change:
            f = self.marionette.find_element(*frame_to_change)
            self.marionette.switch_to_frame(f)

    @retry(5, 10)
    def wait_for_notification_toaster_detail(self, text, frame_to_change=None, notif_text=None, timeout=30):
        """
        Waits for a new popup notification which contains a certain body
        """
        self.marionette.switch_to_frame()

        dom = (DOM.Statusbar.notification_toaster_detail[0], DOM.Statusbar.notification_toaster_detail[1].format(text))
        self.parent.reporting.debug(u"** Waiting for notification toaster detail: [{}]".format(dom))
        self.parent.parent.wait_for_element_present(dom[0], dom[1], timeout)

        # Check if the notification actually exists or if it is a "ghost" one.
        # Note that we can use either @text or @notif_text
        self.wait_for_notification_statusbar_detail(notif_text if notif_text else text)

        if frame_to_change:
            self.parent.iframe.switchToFrame(*frame_to_change)

    def wait_for_notification_toaster_with_titles(self, titles, dom=DOM.Statusbar.notification_toaster_title,
                                                  frame_to_change=None, timeout=30):
        """
        Waits for a new toaster notification whose title is one of the texts in the titles list.
        """
        self.marionette.switch_to_frame()

        exception = None
        title = None
        for t in titles:
            self.parent.reporting.log_to_file(u"Waiting for notification with title {}".format(t))
            toaster = (dom[0], dom[1].format(t))
            try:
                self.parent.parent.wait_for_element_present(toaster[0], toaster[1], timeout)
                if frame_to_change:
                    self.parent.iframe.switchToFrame(*frame_to_change)
                # Success. Clear the exception, if any
                exception = None
                self.parent.reporting.log_to_file(u"Title found: {}".format(t))
                title = t
                break
            except Exception as e:
                # If the element is not displayed before timeout, store exception, just in case another
                # title appears
                exception = e

        # Oops! Error, raise the exception
        if exception is not None:
            raise exception
        # Return the title found, so it can be used later, to click on or whatever
        return title

    def wait_for_notification_statusbar_title(self, text):
        self.marionette.switch_to_frame()

        self.parent.reporting.debug(u"** Waiting for notification statusbar title: [{}]".format(text))
        dom = (DOM.Statusbar.notification_statusbar_title[0],
               DOM.Statusbar.notification_statusbar_title[1].format(text))
        self.marionette.find_element(dom[0], dom[1])

    def wait_for_notification_statusbar_detail(self, text):
        self.marionette.switch_to_frame()

        self.parent.reporting.debug(u"** Waiting for notification statusbar detail: [{}]".format(text))
        dom = (DOM.Statusbar.notification_statusbar_detail[0],
             DOM.Statusbar.notification_statusbar_detail[1].format(text))
        self.marionette.find_element(dom[0], dom[1])
Example #38
0
class statusbar(object):
    def __init__(self, parent):
        self.parent = parent
        self.marionette = parent.marionette
        self.system = System(self.marionette)

    def clearAllStatusBarNotifs(self):
        """Open the system tray and clear all notifications.
        """
        self.marionette.switch_to_frame()
        utility_tray = self.system.open_utility_tray()
        # utility_tray.wait_for_notification_container_displayed()
        # Gaiatestcase wait_for_notification_container_displayed not working properly
        # so we have to manually wait some time in order to make sure the statusbar
        # is fully shown
        time.sleep(2)
        utility_tray.clear_all_notifications()

    def displayStatusBar(self):
        """
        Displays the status / notification bar in the home screen.
        The only reliable way I have to do this at the moment is via JS
        (tapping it only worked sometimes).
        """
        self.marionette.switch_to_frame()
        self.marionette.execute_script(
            "window.wrappedJSObject.UtilityTray.show()")
        time.sleep(0.5)

    def hideStatusBar(self):
        """
        Displays the status / notification bar in the home screen.
        The only reliable way I have to do this at the moment is via JS
        (tapping it only worked sometimes).
        """
        self.marionette.switch_to_frame()
        self.marionette.execute_script(
            "window.wrappedJSObject.UtilityTray.hide()")

    def isIconInStatusBar(self, p_dom):
        """
        Check an icon is in the statusbar, then return to the
        given frame (doesn't wait, just expects it to be there).
        """
        orig_iframe = self.parent.iframe.currentIframe()
        self.marionette.switch_to_frame()

        found = False
        try:
            self.parent.parent.wait_for_element_displayed(*p_dom, timeout=1)
            found = True
        except:
            pass

        if orig_iframe:
            self.parent.iframe.switchToFrame("src", orig_iframe)

        return found

    def openSettingFromStatusbar(self):
        """
        As it says on the tin - opens the settings
        app via the statusbar.
        """
        self.displayStatusBar()
        x = self.parent.element.getElement(DOM.Statusbar.settings_button,
                                           "Settings button")
        x.tap()

        time.sleep(2)

        self.marionette.switch_to_frame()
        self.parent.iframe.switchToFrame(*DOM.Settings.frame_locator)

    def toggleViaStatusBar(self, p_type):
        """
        Uses the statusbar to toggle items on or off. Just toggles.
        Accepted 'types' are: data, wifi, airplane, bluetooth
        """
        self.parent.reporting.logResult(
            "info", "Toggling " + p_type + " mode via statusbar ...")

        # Toggle (and wait)
        if p_type == "data":
            locator = DOM.Statusbar.toggle_dataconn
        if p_type == "wifi":
            locator = DOM.Statusbar.toggle_wifi
        if p_type == "bluetooth":
            locator = DOM.Statusbar.toggle_bluetooth
        if p_type == "airplane":
            locator = DOM.Statusbar.toggle_airplane

        return self._toggle_and_wait(locator, p_type)

    def _toggle_and_wait(self, locator, p_type):
        """
        (private) Toggle a button in the statusbar and waits for the item to be enabled/disabled
        Don't call this directly, it's used by toggleViaStatusBar().
        """

        # Open the status bar.
        self.displayStatusBar()
        boolWasEnabled = self.parent.network.is_network_type_enabled(p_type)

        toggle_icon = self.parent.element.getElement(
            locator, "Toggle {} icon".format(p_type))
        toggle_icon.tap()
        """
        Sometimes, when we activate data connection, the devices goes till settings and
        show a confirmation screen. We have to accept it.
        """
        success = self.parent.iframe.switchToFrame(
            DOM.Settings.frame_locator[0],
            DOM.Settings.frame_locator[1],
            quit_on_error=True,
            via_root_frame=True,
            test=False)
        if success:
            self.parent.element.waitForElements(
                DOM.Settings.celldata_DataConn_confirm_header,
                "Confirmation header", True, 40)

            ok_btn = self.marionette.find_element(
                *DOM.Settings.celldata_DataConn_ON)
            ok_btn.tap()
        else:
            # No confirmation required
            self.parent.reporting.logResult("debug",
                                            "No 3G confirmation asked")

        if boolWasEnabled:
            boolReturn = self.parent.network.wait_for_network_item_disabled(
                p_type)
        else:
            boolReturn = self.parent.network.wait_for_network_item_enabled(
                p_type)

        self.hideStatusBar()
        return boolReturn

    def waitForStatusBarNew(self,
                            p_dom=DOM.Statusbar.status_bar_new,
                            p_displayed=True,
                            p_timeOut=20):

        # Waits for a new notification in the status bar (20s timeout by default).
        orig_iframe = self.parent.iframe.currentIframe()
        self.marionette.switch_to_frame()

        x = self.parent.element.waitForElements(p_dom, "This statusbar icon",
                                                p_displayed, p_timeOut)

        # Only switch if not called from the 'start' screen ...
        if orig_iframe != '':
            self.parent.iframe.switchToFrame("src", orig_iframe, False)

        return x

    def click_on_notification(self,
                              dom,
                              text,
                              frame_to_change=None,
                              timeout=30):
        """
        Clicks on a certain notification looking for the given text in the
        given DOM element (title or detail) for the specified timeout.
        If frame_to_change is not None, frame will be set to its value.
        """
        self.displayStatusBar()
        time.sleep(1)
        elem_dom = (dom[0], dom[1].format(text))
        self.parent.parent.wait_for_element_displayed(elem_dom[0], elem_dom[1],
                                                      timeout)
        notif = self.marionette.find_element(elem_dom[0], elem_dom[1])
        notif.tap()

        if frame_to_change:
            self.parent.iframe.switchToFrame(*frame_to_change)

    def click_on_notification_title(self,
                                    text,
                                    frame_to_change=None,
                                    timeout=30):
        """Clicks on a certain notification (given by its title)
        """
        self.click_on_notification(DOM.Statusbar.notification_statusbar_title,
                                   text, frame_to_change, timeout)

    def click_on_notification_detail(self,
                                     text,
                                     frame_to_change=None,
                                     timeout=30):
        """Clicks on a certain notification (given by its body)
        """
        self.click_on_notification(DOM.Statusbar.notification_statusbar_detail,
                                   text, frame_to_change, timeout)

    @retry(2, 10)
    def wait_for_notification_toaster_title(self,
                                            text,
                                            frame_to_change=None,
                                            notif_text=None,
                                            timeout=30):
        """
        Waits for a new popup notification which contains a certain title
        """
        self.marionette.switch_to_frame()

        dom = (DOM.Statusbar.notification_toaster_title[0],
               DOM.Statusbar.notification_toaster_title[1].format(text))
        self.parent.reporting.debug(
            u"** Waiting for notification toaster title: [{}]".format(dom))
        self.parent.parent.wait_for_element_present(dom[0], dom[1], timeout)

        # Check if the notification actually exists or if it is a "ghost" one.
        # Note that we can use either @text or @notif_text
        self.wait_for_notification_statusbar_title(
            notif_text if notif_text else text)

        if frame_to_change:
            f = self.marionette.find_element(*frame_to_change)
            self.marionette.switch_to_frame(f)

    @retry(5, 10)
    def wait_for_notification_toaster_detail(self,
                                             text,
                                             frame_to_change=None,
                                             notif_text=None,
                                             timeout=30):
        """
        Waits for a new popup notification which contains a certain body
        """
        self.marionette.switch_to_frame()

        dom = (DOM.Statusbar.notification_toaster_detail[0],
               DOM.Statusbar.notification_toaster_detail[1].format(text))
        self.parent.reporting.debug(
            u"** Waiting for notification toaster detail: [{}]".format(dom))
        self.parent.parent.wait_for_element_present(dom[0], dom[1], timeout)

        # Check if the notification actually exists or if it is a "ghost" one.
        # Note that we can use either @text or @notif_text
        self.wait_for_notification_statusbar_detail(
            notif_text if notif_text else text)

        if frame_to_change:
            self.parent.iframe.switchToFrame(*frame_to_change)

    def wait_for_notification_toaster_with_titles(
            self,
            titles,
            dom=DOM.Statusbar.notification_toaster_title,
            frame_to_change=None,
            timeout=30):
        """
        Waits for a new toaster notification whose title is one of the texts in the titles list.
        """
        self.marionette.switch_to_frame()

        exception = None
        title = None
        for t in titles:
            self.parent.reporting.log_to_file(
                u"Waiting for notification with title {}".format(t))
            toaster = (dom[0], dom[1].format(t))
            try:
                self.parent.parent.wait_for_element_present(
                    toaster[0], toaster[1], timeout)
                if frame_to_change:
                    self.parent.iframe.switchToFrame(*frame_to_change)
                # Success. Clear the exception, if any
                exception = None
                self.parent.reporting.log_to_file(u"Title found: {}".format(t))
                title = t
                break
            except Exception as e:
                # If the element is not displayed before timeout, store exception, just in case another
                # title appears
                exception = e

        # Oops! Error, raise the exception
        if exception is not None:
            raise exception
        # Return the title found, so it can be used later, to click on or whatever
        return title

    def wait_for_notification_statusbar_title(self, text):
        self.marionette.switch_to_frame()

        self.parent.reporting.debug(
            u"** Waiting for notification statusbar title: [{}]".format(text))
        dom = (DOM.Statusbar.notification_statusbar_title[0],
               DOM.Statusbar.notification_statusbar_title[1].format(text))
        self.marionette.find_element(dom[0], dom[1])

    def wait_for_notification_statusbar_detail(self, text):
        self.marionette.switch_to_frame()

        self.parent.reporting.debug(
            u"** Waiting for notification statusbar detail: [{}]".format(text))
        dom = (DOM.Statusbar.notification_statusbar_detail[0],
               DOM.Statusbar.notification_statusbar_detail[1].format(text))
        self.marionette.find_element(dom[0], dom[1])