This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/
app.py
126 lines (99 loc) · 5.55 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from marionette.by import By
from marionette.errors import JavascriptException
from marionette import Wait
from gaiatest.apps.base import Base
from gaiatest.apps.base import PageRegion
class Contacts(Base):
name = "Contacts"
_new_contact_button_locator = (By.ID, 'add-contact-button')
_settings_button_locator = (By.ID, 'settings-button')
_favorites_list_locator = (By.ID, 'contacts-list-favorites')
_select_all_wrapper_locator = (By.ID, 'select-all-wrapper')
_select_all_button_locator = (By.CSS_SELECTOR, 'button[data-l10n-id="selectAll"]')
_export_button_locator = (By.ID, 'select-action')
_status_message_locator = (By.ID, 'statusMsg')
# contacts
_contact_locator = (By.CSS_SELECTOR, 'li.contact-item:not([data-group="ice"])')
def launch(self):
Base.launch(self)
Wait(self.marionette, ignored_exceptions=JavascriptException).until(
lambda m: m.execute_script('return window.wrappedJSObject.Contacts.asyncScriptsLoaded') is True)
self.wait_for_element_displayed(*self._settings_button_locator)
def switch_to_contacts_frame(self):
self.wait_for_condition(lambda m: self.apps.displayed_app.name == self.name)
self.apps.switch_to_displayed_app()
Wait(self.marionette, ignored_exceptions=JavascriptException).until(
lambda m: m.execute_script('return window.wrappedJSObject.Contacts.asyncScriptsLoaded') is True)
@property
def contacts(self):
return [self.Contact(marionette=self.marionette, element=contact)
for contact in self.marionette.find_elements(*self._contact_locator)]
def wait_for_contacts(self, number_to_wait_for=1):
self.wait_for_condition(lambda m: len(m.find_elements(*self._contact_locator)) == number_to_wait_for)
def contact(self, name):
for contact in self.contacts:
if contact.name == name:
return contact
def tap_new_contact(self):
self.marionette.find_element(*self._new_contact_button_locator).tap()
from gaiatest.apps.contacts.regions.contact_form import NewContact
new_contact = NewContact(self.marionette)
new_contact.wait_for_new_contact_form_to_load()
return new_contact
def a11y_click_new_contact(self):
self.accessibility.click(self.marionette.find_element(*self._new_contact_button_locator))
from gaiatest.apps.contacts.regions.contact_form import NewContact
new_contact = NewContact(self.marionette)
new_contact.wait_for_new_contact_form_to_load()
return new_contact
def tap_settings(self):
self.marionette.find_element(*self._settings_button_locator).tap()
self.wait_for_element_not_displayed(*self._settings_button_locator)
from gaiatest.apps.contacts.regions.settings_form import SettingsForm
return SettingsForm(self.marionette)
def tap_select_all(self):
window_height = self.marionette.execute_script('return window.wrappedJSObject.innerHeight')
wrapper = self.marionette.find_element(*self._select_all_wrapper_locator)
self.wait_for_condition(lambda m: int(wrapper.size['height'] + wrapper.location['y']) == window_height)
self.marionette.find_element(*self._select_all_button_locator).tap()
def tap_export(self):
self.marionette.find_element(*self._export_button_locator).tap()
@property
def is_favorites_list_displayed(self):
return self.marionette.find_element(*self._favorites_list_locator).is_displayed()
@property
def status_message(self):
self.wait_for_element_displayed(*self._status_message_locator)
return self.marionette.find_element(*self._status_message_locator).text
class Contact(PageRegion):
_name_locator = (By.CSS_SELECTOR, 'p > strong')
_full_name_locator = (By.CSS_SELECTOR, 'p')
@property
def name(self):
return self.root_element.find_element(*self._name_locator).text
@property
def full_name(self):
return self.root_element.find_element(*self._full_name_locator).text
def tap(self, return_class='ContactDetails'):
self.root_element.find_element(*self._name_locator).tap()
return self._return_class_from_tap(return_class)
def a11y_click(self, return_class='ContactDetails'):
self.accessibility.click(self.root_element)
return self._return_class_from_tap(return_class)
def _return_class_from_tap(self, return_class='ContactDetails'):
if return_class == 'ContactDetails':
from gaiatest.apps.contacts.regions.contact_details import ContactDetails
return ContactDetails(self.marionette)
elif return_class == 'EditContact':
# This may seem superfluous but we can enter EditContact from Contacts, or from ActivityPicker
self.wait_for_condition(lambda m: self.apps.displayed_app.name == Contacts.name)
self.apps.switch_to_displayed_app()
from gaiatest.apps.contacts.regions.contact_form import EditContact
return EditContact(self.marionette)
else:
# We are using contacts picker in activity - after choosing, fall back to open app
self.wait_for_condition(lambda m: self.apps.displayed_app.name != Contacts.name)
self.apps.switch_to_displayed_app()