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

« back to all changes in this revision

Viewing changes to ubuntu_system_tests/helpers/messaging.py

  • Committer: Tarmac
  • Author(s): Brendan Donegan
  • Date: 2015-06-22 20:29:23 UTC
  • mfrom: (122.3.19 test_send_sms)
  • Revision ID: tarmac-20150622202923-lpcbwlswoc1tm3nc
Add test_send_sms_to_contact which sends an SMS message to a contact in the address book.

Approved by PS Jenkins bot, Richard Huddie, Sergio Cazzolato.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
18
#
19
19
 
 
20
import logging
 
21
import time
 
22
 
 
23
from subprocess import check_output
 
24
 
 
25
import autopilot
20
26
import ubuntuuitoolkit as uitk
21
27
 
 
28
from autopilot.exceptions import StateNotFoundError
22
29
from urllib.parse import urlparse
23
 
 
24
30
from messaging_app import emulators as messaging_emulators
25
31
 
 
32
from ubuntu_system_tests.helpers import ofono
 
33
 
 
34
logger = logging.getLogger(__name__)
 
35
 
 
36
 
 
37
def get_default_sim_for_messages():
 
38
    # GSettings rather rudely includes single quotes
 
39
    # so we have to strip them
 
40
    return check_output(
 
41
        ['gsettings', 'get', 'com.ubuntu.phone',
 
42
         'default-sim-for-messages'],
 
43
        universal_newlines=True).strip().strip("'")
 
44
 
 
45
 
 
46
class MainView(messaging_emulators.MainView):
 
47
 
 
48
    @autopilot.logging.log_action(logger.info)
 
49
    def type_contact_name_and_select_num(self, name, number):
 
50
        text_entry = self.get_newmessage_multirecipientinput()
 
51
        self.pointing_device.click_object(text_entry)
 
52
        text_entry.focus.wait_for(True)
 
53
        time.sleep(.3)
 
54
        self.keyboard.type(str(name), delay=0.2)
 
55
        # Now select the right number from the list
 
56
        self.pointing_device.click_object(
 
57
            self.get_mobile_number_label(number)
 
58
        )
 
59
 
 
60
    def get_mobile_number_label(self, number):
 
61
        return self.wait_select_single(
 
62
            'Label', text='Mobile {}'.format(number)
 
63
        )
 
64
 
 
65
    def select_sim_if_prompted(self, sim_number):
 
66
        prompt = get_default_sim_for_messages()
 
67
        if ofono.number_of_sims() > 1 and prompt == 'ask':
 
68
            try:
 
69
                default_sim_dialog = self.wait_select_single(
 
70
                    'Dialog'
 
71
                )
 
72
            except StateNotFoundError:
 
73
                return
 
74
            if default_sim_dialog:
 
75
                self.pointing_device.click_object(
 
76
                    self.get_sim_label(sim_number)
 
77
                )
 
78
 
 
79
    def get_sim_label(self, sim_number):
 
80
        return self.wait_select_single(
 
81
            'Label', text='SIM {}'.format(sim_number)
 
82
        )
 
83
 
26
84
 
27
85
class MessageDelegateFactory(messaging_emulators.MessageDelegateFactory):
28
86
    """Class to get all the messages from the app."""