Merge lp:~canonical-platform-qa/messaging-app/test_helper_to_send_sms_from_suggested_contact_list into lp:messaging-app

Proposed by Omer Akram
Status: Needs review
Proposed branch: lp:~canonical-platform-qa/messaging-app/test_helper_to_send_sms_from_suggested_contact_list
Merge into: lp:messaging-app
Diff against target: 192 lines (+56/-25)
5 files modified
debian/control (+1/-0)
src/qml/Messages.qml (+1/-0)
tests/autopilot/messaging_app/emulators.py (+36/-21)
tests/autopilot/messaging_app/tests/__init__.py (+0/-4)
tests/autopilot/messaging_app/tests/test_messaging.py (+18/-0)
To merge this branch: bzr merge lp:~canonical-platform-qa/messaging-app/test_helper_to_send_sms_from_suggested_contact_list
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Leo Arias (community) Needs Fixing
Ubuntu Phablet Team Pending
Review via email: mp+227817@code.launchpad.net

Commit message

Autopilot: add test to send sms by selecting contact from the suggested contact list

Description of the change

Autopilot: add test to send sms by selecting contact from the suggested contact list

Note this branch depends on an new package address-book-service-testability to land. I just need a code review for now.

prereq: https://code.launchpad.net/~canonical-platform-qa/ubuntu-ui-toolkit/add_helpers_for_TextArea/+merge/228385

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:158
http://jenkins.qa.ubuntu.com/job/messaging-app-ci/299/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/2343/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/1924/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/messaging-app-utopic-amd64-ci/93
    SUCCESS: http://jenkins.qa.ubuntu.com/job/messaging-app-utopic-armhf-ci/93
        deb: http://jenkins.qa.ubuntu.com/job/messaging-app-utopic-armhf-ci/93/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/messaging-app-utopic-i386-ci/93
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/2526/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/3556
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/3556/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/10249
    FAILURE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/1613/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/2157
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/2157/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/messaging-app-ci/299/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Leo Arias (elopio) wrote :

19 text_entry = self.get_newmessage_textarea()
20 - self.pointing_device.click_object(text_entry)
21 - text_entry.focus.wait_for(True)
22 - time.sleep(.3)
23 + self._focus_field(text_entry)
24 self.keyboard.type(str(message), delay=0.2)

Replace this with something like
text_field = self.select_single(ubuntuuitoolkit.TextField, objectName='...')
text_field.write('...')

It will take care of clicking and waiting for it to be focused. It won't sleep the extra .3. Why is that needed? If it's not, just remove it. If it is, you can overwrite the write method, but please comment with the reason.

29 + def type_contact_phone_num(self, num_or_contact, select=False):

You need to explain that select argument in a docstring.

45 + self.keyboard.press_and_release("Enter")

Pressing Enter is something that you can't do from the phone, as a real user. Is there a button to click instead?

50 + def select_contact_from_list(self, name):
51 + """Select the given contact from the list
52 +
53 + :parameter name: name of the contact
54 + """
55 +
56 + contact_list = self.get_root_instance().select_single(
57 + 'ContactSimpleListView')
58 + list_item = contact_list.wait_select_single(
59 + 'Label', text='<b>{}</b>'.format(name))
60 + self.pointing_device.click_object(list_item)

This needs to be improved to follow closely the page object pattern.
First, the method shouldn't be in main_view. It should be on the component that executes the action. That's the new chat page, right?

Then, the you can make an object for ContactSimpleListView and add a method select_contact there.

Let me know if you need any kind of help with this.

The test you added is nice, thanks for that.

review: Needs Fixing
Revision history for this message
Omer Akram (om26er) wrote :

> 19 text_entry = self.get_newmessage_textarea()
> 20 - self.pointing_device.click_object(text_entry)
> 21 - text_entry.focus.wait_for(True)
> 22 - time.sleep(.3)
> 23 + self._focus_field(text_entry)
> 24 self.keyboard.type(str(message), delay=0.2)
>
> Replace this with something like
> text_field = self.select_single(ubuntuuitoolkit.TextField, objectName='...')
> text_field.write('...')

Hi! I didn't know TextField emulator existed, thanks for that. The component I am trying to interact with, is not a TextField, its a custom component used only in messaging-app I believe.

>
> It will take care of clicking and waiting for it to be focused. It won't sleep
> the extra .3. Why is that needed? If it's not, just remove it. If it is, you
> can overwrite the write method, but please comment with the reason.

I am not sure about the sleep, I did not add it, it was already there and is in a few other places as well, I will not remove since there was probably a reason for that.

>
> 29 + def type_contact_phone_num(self, num_or_contact, select=False):
>
> You need to explain that select argument in a docstring.

Added.

>
> 45 + self.keyboard.press_and_release("Enter")
>
> Pressing Enter is something that you can't do from the phone, as a real user.
> Is there a button to click instead?

It was already there. Now that I poked through the app, the only way to lose focus in that field is by focusing the 'message' box, there is no other button in this page. We can go with that but I am not sure.
>
> 50 + def select_contact_from_list(self, name):
> 51 + """Select the given contact from the list
> 52 +
> 53 + :parameter name: name of the contact
> 54 + """
> 55 +
> 56 + contact_list = self.get_root_instance().select_single(
> 57 + 'ContactSimpleListView')
> 58 + list_item = contact_list.wait_select_single(
> 59 + 'Label', text='<b>{}</b>'.format(name))
> 60 + self.pointing_device.click_object(list_item)
>
> This needs to be improved to follow closely the page object pattern.
> First, the method shouldn't be in main_view. It should be on the component
> that executes the action. That's the new chat page, right?
>
> Then, the you can make an object for ContactSimpleListView and add a method
> select_contact there.
>
> Let me know if you need any kind of help with this.

Done, thanks.
>
> The test you added is nice, thanks for that.

Thanks!

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:160
http://jenkins.qa.ubuntu.com/job/messaging-app-ci/307/
Executed test runs:
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/2463/console
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/1996/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/messaging-app-utopic-amd64-ci/101
    SUCCESS: http://jenkins.qa.ubuntu.com/job/messaging-app-utopic-armhf-ci/101
        deb: http://jenkins.qa.ubuntu.com/job/messaging-app-utopic-armhf-ci/101/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/messaging-app-utopic-i386-ci/101
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/2623/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/3706
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/3706/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/10380
    FAILURE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/1669/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/2246
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/2246/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/messaging-app-ci/307/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Leo Arias (elopio) :
review: Needs Fixing
Revision history for this message
Leo Arias (elopio) wrote :

Omer, it would be nice if you try to improve all the code you are touching, even if you didn't write it originally. That's the only way we can get the tests to a better shape.

34 + to select it by tapping from the suggeted list.

You have a typo there ^. It's suggeSted.

> > 19 text_entry = self.get_newmessage_textarea()
> > 20 - self.pointing_device.click_object(text_entry)
> > 21 - text_entry.focus.wait_for(True)
> > 22 - time.sleep(.3)
> > 23 + self._focus_field(text_entry)
> > 24 self.keyboard.type(str(message), delay=0.2)
> >
> Hi! I didn't know TextField emulator existed, thanks for that. The component I
> am trying to interact with, is not a TextField, its a custom component used
> only in messaging-app I believe.

It's a text area, not a text field.
We have an open bug to make a helper for text area. https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1327354
It's really simple, as it should just inherit from TextField. Now that you need it, it will be the perfect moment for you to contribute to the toolkit :D

> I am not sure about the sleep, I did not add it, it was already there and is
> in a few other places as well, I will not remove since there was probably a
> reason for that.

Try removing the sleep and if all the tests pass, that's good enough. If we need to add it in the future, then we will understand the reason for it and put a comment. If you get new errors because of the removed sleep, you will be able to find the reason.
Any thing that's not clear is broken.

> It was already there. Now that I poked through the app, the only way to lose
> focus in that field is by focusing the 'message' box, there is no other button
> in this page. We can go with that but I am not sure.

It sounds like type_contact_phone_num should leave the focus on that textfield. The next helper will click the other text area, so I think it's not needed to press enter.

Revision history for this message
Omer Akram (om26er) wrote :

> Omer, it would be nice if you try to improve all the code you are touching,
> even if you didn't write it originally. That's the only way we can get the
> tests to a better shape.
>
> 34 + to select it by tapping from the suggeted list.
>
> You have a typo there ^. It's suggeSted.

Fixed.

>
>
> > > 19 text_entry = self.get_newmessage_textarea()
> > > 20 - self.pointing_device.click_object(text_entry)
> > > 21 - text_entry.focus.wait_for(True)
> > > 22 - time.sleep(.3)
> > > 23 + self._focus_field(text_entry)
> > > 24 self.keyboard.type(str(message), delay=0.2)
> > >
> > Hi! I didn't know TextField emulator existed, thanks for that. The component
> I
> > am trying to interact with, is not a TextField, its a custom component used
> > only in messaging-app I believe.
>
> It's a text area, not a text field.
> We have an open bug to make a helper for text area. https://bugs.launchpad.net
> /ubuntu-ui-toolkit/+bug/1327354
> It's really simple, as it should just inherit from TextField. Now that you
> need it, it will be the perfect moment for you to contribute to the toolkit :D
>

Ok, proposed a branch for uitoolkit, please review: https://code.launchpad.net/~canonical-platform-qa/ubuntu-ui-toolkit/add_helpers_for_TextArea/+merge/228385

> > I am not sure about the sleep, I did not add it, it was already there and is
> > in a few other places as well, I will not remove since there was probably a
> > reason for that.
>
> Try removing the sleep and if all the tests pass, that's good enough. If we
> need to add it in the future, then we will understand the reason for it and
> put a comment. If you get new errors because of the removed sleep, you will be
> able to find the reason.
> Any thing that's not clear is broken.

Done, no random sleep.

>
> > It was already there. Now that I poked through the app, the only way to lose
> > focus in that field is by focusing the 'message' box, there is no other
> button
> > in this page. We can go with that but I am not sure.
>
> It sounds like type_contact_phone_num should leave the focus on that
> textfield. The next helper will click the other text area, so I think it's not
> needed to press enter.

Yeah, didn't think of that. Removed the Enter hack.

Revision history for this message
Leo Arias (elopio) wrote :

Thanks Omer. Now you can either wait for the toolkit to land with your TextArea helper, or duplicate the code of the TextArea helper in the messaging app branch.
If duplicate, please make sure that you report a bug assigned to you, and that you comment on the duplicate code with a link to the bug.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:166
http://jenkins.qa.ubuntu.com/job/messaging-app-ci/359/
Executed test runs:
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/3080
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/2427/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/messaging-app-utopic-amd64-ci/153
    SUCCESS: http://jenkins.qa.ubuntu.com/job/messaging-app-utopic-armhf-ci/153
        deb: http://jenkins.qa.ubuntu.com/job/messaging-app-utopic-armhf-ci/153/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/messaging-app-utopic-i386-ci/153
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/3120
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/4323
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/4323/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/11055
    FAILURE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/2008/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/2695
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/2695/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/messaging-app-ci/359/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
169. By Omer Akram

merge trunk

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Omer Akram (om26er) wrote :

Are there any related MPs required for this MP to build/function as expected? Please list.

None. manual test run of your code change and any related functionality on device or emulator?

Did you successfully run all tests found in your component's Test Plan on device or emulator?

Yes

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
170. By Omer Akram

merge trunk

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Unmerged revisions

170. By Omer Akram

merge trunk

169. By Omer Akram

merge trunk

168. By Omer Akram

fix import

167. By Omer Akram

merge trunk

166. By Omer Akram

merge trunk

165. By Omer Akram

mallit-server does not work on desktop so don't try to stop it

164. By Omer Akram

remove hack to lose focus from the input field

163. By Omer Akram

fix docstring typo

162. By Omer Akram

make right use of ubuntuuitoolkit module

161. By Omer Akram

make use of uitoolkit helpers to write into input boxes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2014-08-19 15:24:14 +0000
3+++ debian/control 2014-09-03 13:53:56 +0000
4@@ -51,6 +51,7 @@
5 python3-autopilot,
6 ubuntu-ui-toolkit-autopilot,
7 ofono-phonesim-autostart,
8+ address-book-service-testability,
9 Description: autopilot tests for messaging-app
10 This package contains the autopilot tests for messaging-app
11 .
12
13=== modified file 'src/qml/Messages.qml'
14--- src/qml/Messages.qml 2014-08-28 21:59:17 +0000
15+++ src/qml/Messages.qml 2014-09-03 13:53:56 +0000
16@@ -834,6 +834,7 @@
17
18 TextArea {
19 id: messageTextArea
20+ objectName: 'newMessageInput'
21 anchors {
22 top: attachments.count == 0 ? textEntry.top : attachmentThumbnails.bottom
23 left: parent.left
24
25=== modified file 'tests/autopilot/messaging_app/emulators.py'
26--- tests/autopilot/messaging_app/emulators.py 2014-08-20 12:38:05 +0000
27+++ tests/autopilot/messaging_app/emulators.py 2014-09-03 13:53:56 +0000
28@@ -15,10 +15,10 @@
29 import time
30
31 from autopilot import logging as autopilot_logging
32-from autopilot.input import Keyboard
33 from autopilot.platform import model
34 from autopilot.introspection.dbus import StateNotFoundError
35-from ubuntuuitoolkit import emulators as toolkit_emulators
36+
37+import ubuntuuitoolkit
38 from ubuntuuitoolkit._custom_proxy_objects import _common
39
40
41@@ -29,11 +29,11 @@
42 """Exception raised when there is an error with the emulator."""
43
44
45-class MainView(toolkit_emulators.MainView):
46+class MainView(ubuntuuitoolkit.MainView):
47 def __init__(self, *args):
48 super(MainView, self).__init__(*args)
49- self.pointing_device = toolkit_emulators.get_pointing_device()
50- self.keyboard = Keyboard.create()
51+ self.pointing_device = ubuntuuitoolkit.get_pointing_device()
52+ self.keyboard = ubuntuuitoolkit.get_keyboard()
53 self.logger = logging.getLogger(__name__)
54
55 def get_pagestack(self):
56@@ -241,26 +241,27 @@
57 :parameter message: the message to type
58 """
59
60- text_entry = self.get_newmessage_textarea()
61- self.pointing_device.click_object(text_entry)
62- text_entry.focus.wait_for(True)
63- time.sleep(.3)
64- self.keyboard.type(str(message), delay=0.2)
65+ text_entry = self.select_single(
66+ ubuntuuitoolkit.TextArea, objectName='newMessageInput')
67+ text_entry.write(str(message))
68 self.logger.info(
69 'typed: "{}" expected: "{}"'.format(text_entry.text, message))
70
71- def type_contact_phone_num(self, num_or_contact):
72+ def type_contact_phone_num(self, num_or_contact, select=False):
73 """Select and type phone number or contact
74
75 :parameter num_or_contact: number or contact to type
76+ :parameter select: set True if a contact already exists and
77+ you want to select it by tapping from the suggested list.
78 """
79
80- text_entry = self.get_newmessage_multirecipientinput()
81- self.pointing_device.click_object(text_entry)
82- text_entry.focus.wait_for(True)
83- time.sleep(.3)
84- self.keyboard.type(str(num_or_contact), delay=0.2)
85- self.keyboard.press_and_release("Enter")
86+ text_entry = self.select_single(
87+ ubuntuuitoolkit.TextField, objectName='contactSearchInput')
88+ text_entry.write(str(num_or_contact))
89+ if select:
90+ root = self.get_root_instance()
91+ message_page = root.select_single(Messages)
92+ message_page.select_contact_from_list(num_or_contact)
93 self.logger.info(
94 'typed "{}" expected "{}"'.format(
95 self.get_newmessage_textfield().text, num_or_contact))
96@@ -391,15 +392,17 @@
97 message.confirm_removal()
98
99 @autopilot_logging.log_action(logger.info)
100- def send_message(self, number, message):
101+ def send_message(self, num_or_name, message, select=False):
102 """Write a new message and send it.
103
104- :param number: number of the contact to send message to.
105+ :param num_or_name: number or name of the contact to send message to.
106 :param message: the message to be sent.
107+ :param select: whether to select the contact from the autocomplete
108+ list or just press 'Enter'.
109
110 """
111 self.start_new_message()
112- self.type_contact_phone_num(number)
113+ self.type_contact_phone_num(num_or_name, select=select)
114 self.type_message(message)
115 old_message_count = self.get_multiple_selection_list_view().count
116 self.click_send_button()
117@@ -452,7 +455,7 @@
118 return root.wait_select_single(Messages, participants=participants)
119
120
121-class Messages(toolkit_emulators.UbuntuUIToolkitEmulatorBase):
122+class Messages(ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase):
123 """Autopilot helper for the Messages Page."""
124
125 def get_messages_count(self):
126@@ -506,6 +509,18 @@
127 messages.append((date, text))
128 return messages
129
130+ def select_contact_from_list(self, name):
131+ """Select the given contact from the list
132+
133+ :parameter name: name of the contact
134+ """
135+
136+ contact_list = self.select_single(
137+ 'ContactSimpleListView')
138+ list_item = contact_list.wait_select_single(
139+ 'Label', text='<b>{}</b>'.format(name))
140+ self.pointing_device.click_object(list_item)
141+
142
143 class ListItemWithActions(_common.UbuntuUIToolkitCustomProxyObjectBase):
144
145
146=== modified file 'tests/autopilot/messaging_app/tests/__init__.py'
147--- tests/autopilot/messaging_app/tests/__init__.py 2014-07-15 16:32:16 +0000
148+++ tests/autopilot/messaging_app/tests/__init__.py 2014-09-03 13:53:56 +0000
149@@ -35,10 +35,6 @@
150
151 """
152
153- # Don't use keyboard on desktop
154- if model() == 'Desktop':
155- subprocess.call(['/sbin/initctl', 'stop', 'maliit-server'])
156-
157 if model() == 'Desktop':
158 scenarios = [
159 ('with mouse', dict(input_device_class=Mouse)),
160
161=== modified file 'tests/autopilot/messaging_app/tests/test_messaging.py'
162--- tests/autopilot/messaging_app/tests/test_messaging.py 2014-08-01 19:40:26 +0000
163+++ tests/autopilot/messaging_app/tests/test_messaging.py 2014-09-03 13:53:56 +0000
164@@ -18,6 +18,7 @@
165 from testtools.matchers import Equals, HasLength
166 from testtools import skip
167
168+from address_book_service_testability import fixture_setup as contact_fixture
169 from messaging_app import emulators
170 from messaging_app import fixture_setup
171 from messaging_app import helpers
172@@ -344,3 +345,20 @@
173 _, remaining_message_text = remaining_messages[0]
174 self.assertEqual(
175 remaining_message_text, self.messages[0])
176+
177+
178+class TestMessagingWithExistingContacts(BaseMessagingTestCase):
179+
180+ def setUp(self):
181+ self.useFixture(contact_fixture.AddressBookServiceDummyBackend())
182+ super(TestMessagingWithExistingContacts, self).setUp()
183+
184+ def test_send_message_to_existing_contact(self):
185+ """Verify we can write and send a new text message
186+ to an existing contact.
187+ """
188+ contact = 'UX User'
189+ message = 'hi!'
190+ bubble = self.main_view.send_message(contact, message, select=True)
191+
192+ self.assertProperty(bubble, visible=True)

Subscribers

People subscribed via source and target branches