PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/python/gaia-ui-tests/gaiatest/apps/ftu/app.py

https://gitlab.com/Guy1394/gaia
Python | 465 lines | 350 code | 92 blank | 23 comment | 9 complexity | 7e7caf42b7457e5b1504d94b9d2ece73 MD5 | raw file
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. import re
  5. import time
  6. from marionette_driver import expected, By, Wait
  7. from gaiatest.apps.base import Base
  8. from gaiatest.form_controls.binarycontrol import GaiaBinaryControl
  9. class Ftu(Base):
  10. name = 'FTU'
  11. _next_button_locator = (By.ID, 'forward')
  12. # Step Languages section
  13. _section_languages_locator = (By.ID, 'languages')
  14. _listed_languages_locator = (By.CSS_SELECTOR, "#languages ul li")
  15. _language_locator = (By.CSS_SELECTOR, "#languages ul li[data-value='%s']")
  16. _language_input_locator = (By.CSS_SELECTOR,
  17. "#languages ul li gaia-radio[name='language.current'][value='%s']")
  18. _selected_language_input_locator = (By.CSS_SELECTOR, "#languages ul li gaia-radio:checked")
  19. # Step Cell data section
  20. _section_cell_data_locator = (By.ID, 'data_3g')
  21. _enable_data_checkbox_locator = (By.ID, 'data-connection-switch')
  22. # Step Wifi
  23. _section_wifi_locator = (By.ID, 'wifi')
  24. _found_wifi_networks_locator = (By.CSS_SELECTOR, 'ul#networks-list li')
  25. _password_input_locator = (By.ID, 'wifi_password')
  26. _join_network_locator = (By.ID, 'wifi-join-button')
  27. _loading_overlay_locator = (By.ID, 'loading-overlay')
  28. # Step Date & Time
  29. _section_date_time_locator = (By.ID, 'date_and_time')
  30. _timezone_continent_locator = (By.CSS_SELECTOR, '#time-form li:nth-child(1) > .change.icon.icon-dialog')
  31. _timezone_city_locator = (By.CSS_SELECTOR, '#time-form li:nth-child(2) > .change.icon.icon-dialog')
  32. _time_zone_title_locator = (By.ID, 'time-zone-title')
  33. # Step Geolocation
  34. _section_geolocation_locator = (By.ID, 'geolocation')
  35. _enable_geolocation_checkbox_locator = (By.ID, 'geolocation-switch')
  36. # Section Import contacts
  37. _section_import_contacts_locator = (By.ID, 'import_contacts')
  38. _import_from_sim_locator = (By.ID, 'sim-import-button')
  39. _sim_import_feedback_locator = (By.ID, 'statusMsg')
  40. # Step Firefox Accounts
  41. _section_firefox_accounts_locator = (By.ID, 'firefox_accounts')
  42. # Section late customization
  43. _section_late_customization_locator = (By.ID, 'late_customization')
  44. # Section Welcome Browser
  45. _section_welcome_browser_locator = (By.ID, 'welcome_browser')
  46. _metrics_basic_locator = (By.ID, 'metrics-basic')
  47. _metrics_enhanced_locator = (By.ID, 'metrics-enhanced')
  48. _metrics_none_locator = (By.ID, 'metrics-none')
  49. # Section Privacy Choices
  50. _section_browser_privacy_locator = (By.ID, 'browser_privacy')
  51. _email_field_locator = (By.CSS_SELECTOR, 'input[type="email"]')
  52. # Section Finish
  53. _section_finish_locator = (By.ID, 'finish-screen')
  54. _skip_tour_button_locator = (By.ID, 'skip-tutorial-button')
  55. _take_tour_button_locator = (By.ID, 'lets-go-button')
  56. # Section Tour
  57. _step_header_locator = (By.ID, 'tutorial-step-title')
  58. _tour_next_button_locator = (By.ID, 'forward-tutorial')
  59. _tour_back_button_locator = (By.ID, 'back-tutorial')
  60. # Section Tutorial Finish
  61. _section_tutorial_finish_locator = (By.ID, 'tutorial-finish-tiny')
  62. _lets_go_button_locator = (By.ID, 'tutorialFinished')
  63. # Pattern for import sim contacts message
  64. _pattern_contacts = re.compile("^No contacts detected on SIM to import$|^Imported one contact$|^Imported [0-9]+ contacts$")
  65. _pattern_contacts_0 = re.compile("^No contacts detected on SIM to import$")
  66. _pattern_contacts_1 = re.compile("^Imported one contact$")
  67. _pattern_contacts_N = re.compile("^Imported ([0-9]+) contacts$")
  68. def launch(self):
  69. Base.launch(self)
  70. Wait(self.marionette).until(expected.element_displayed(*self._section_languages_locator))
  71. @property
  72. def languages_list(self):
  73. return len(self.marionette.find_elements(*self._listed_languages_locator))
  74. @property
  75. def selected_language(self):
  76. return self.marionette.find_element(*self._selected_language_input_locator).get_attribute(
  77. 'value')
  78. def tap_language(self, language):
  79. self.marionette.find_element(self._language_locator[0], self._language_locator[1] % language).tap()
  80. def a11y_click_language(self, language):
  81. self.accessibility.click(self.marionette.find_element(self._language_input_locator[0],
  82. self._language_input_locator[1] % language))
  83. @property
  84. def is_take_tour_button_visible(self):
  85. return self.is_element_displayed(*self._take_tour_button_locator)
  86. @property
  87. def is_lets_go_button_visible(self):
  88. return self.is_element_displayed(*self._lets_go_button_locator)
  89. def tap_next(self):
  90. next_button = Wait(self.marionette).until(
  91. expected.element_present(*self._next_button_locator))
  92. Wait(self.marionette).until(expected.element_displayed(next_button))
  93. Wait(self.marionette).until(expected.element_enabled(next_button))
  94. # In b2g desktop builds, this sleep prevents intermittent failures
  95. time.sleep(0.2)
  96. next_button.tap()
  97. def a11y_click_next(self):
  98. self.accessibility.click(self.marionette.find_element(*self._next_button_locator))
  99. def tap_next_to_cell_data_section(self):
  100. self.tap_next()
  101. Wait(self.marionette).until(expected.element_displayed(*self._section_cell_data_locator))
  102. def a11y_click_next_to_cell_data_section(self):
  103. self.a11y_click_next()
  104. Wait(self.marionette).until(expected.element_displayed(*self._section_cell_data_locator))
  105. def enable_data(self):
  106. checkbox = Wait(self.marionette).until(
  107. expected.element_present(*self._enable_data_checkbox_locator))
  108. Wait(self.marionette).until(expected.element_displayed(checkbox))
  109. checkbox.tap()
  110. def a11y_enable_data(self):
  111. checkbox = Wait(self.marionette).until(
  112. expected.element_present(*self._enable_data_checkbox_locator))
  113. Wait(self.marionette).until(expected.element_displayed(checkbox))
  114. self.accessibility.click(checkbox)
  115. def tap_next_to_wifi_section(self):
  116. progress = self.marionette.find_element(*self._loading_overlay_locator)
  117. self.tap_next()
  118. Wait(self.marionette).until(expected.element_not_displayed(progress))
  119. Wait(self.marionette).until(expected.element_displayed(*self._section_wifi_locator))
  120. def a11y_click_next_to_wifi_section(self):
  121. self.a11y_click_next()
  122. Wait(self.marionette).until(
  123. expected.element_not_displayed(*self._loading_overlay_locator))
  124. Wait(self.marionette).until(expected.element_displayed(*self._section_wifi_locator))
  125. def wait_for_networks_available(self):
  126. Wait(self.marionette).until(lambda m: len(m.find_elements(
  127. *self._found_wifi_networks_locator)) > 0,
  128. message='No networks listed on screen')
  129. def find_wifi_network(self, network_ssid):
  130. wifi_network_locator = (By.CSS_SELECTOR, '#networks-list li[data-ssid="%s"]' % network_ssid)
  131. wifi_network = Wait(self.marionette).until(
  132. expected.element_present(*wifi_network_locator))
  133. self.marionette.execute_script("arguments[0].scrollIntoView(false);", [wifi_network])
  134. Wait(self.marionette).until(expected.element_displayed(wifi_network))
  135. return wifi_network
  136. def connect_to_wifi(self, network_ssid, password, key_management=None):
  137. wifi_network = self.find_wifi_network(network_ssid)
  138. wifi_network.tap()
  139. # This is in the event we are using a Wifi Network that requires a password
  140. # We cannot be sure of this thus need the logic
  141. if key_management:
  142. password_element = Wait(self.marionette).until(
  143. expected.element_present(*self._password_input_locator))
  144. Wait(self.marionette).until(expected.element_displayed(password_element))
  145. password_element.send_keys(password)
  146. self.marionette.find_element(*self._join_network_locator).tap()
  147. def a11y_connect_to_wifi(self, network_ssid, password, key_management=None):
  148. wifi_network = self.find_wifi_network(network_ssid)
  149. self.accessibility.click(wifi_network)
  150. # This is in the event we are using a Wifi Network that requires a password
  151. # We cannot be sure of this thus need the logic
  152. if key_management:
  153. password_element = Wait(self.marionette).until(
  154. expected.element_present(*self._password_input_locator))
  155. Wait(self.marionette).until(expected.element_displayed(password_element))
  156. password_element.send_keys(password)
  157. self.accessibility.click(self.marionette.find_element(*self._join_network_locator))
  158. def tap_next_to_timezone_section(self):
  159. self.tap_next()
  160. Wait(self.marionette).until(expected.element_displayed(*self._section_date_time_locator))
  161. def a11y_click_next_to_timezone_section(self):
  162. self.a11y_click_next()
  163. Wait(self.marionette).until(expected.element_displayed(*self._section_date_time_locator))
  164. def set_timezone_continent(self, continent):
  165. element = Wait(self.marionette).until(
  166. expected.element_present(*self._timezone_continent_locator))
  167. Wait(self.marionette).until(expected.element_displayed(element))
  168. element.tap()
  169. self.select(continent)
  170. def a11y_set_timezone_continent(self, continent):
  171. element = Wait(self.marionette).until(
  172. expected.element_present(*self._timezone_continent_locator))
  173. Wait(self.marionette).until(expected.element_displayed(element))
  174. self.accessibility.click(element)
  175. self.a11y_select(continent)
  176. def set_timezone_city(self, city):
  177. element = Wait(self.marionette).until(
  178. expected.element_present(*self._timezone_city_locator))
  179. Wait(self.marionette).until(expected.element_displayed(element))
  180. element.tap()
  181. self.select(city)
  182. def a11y_set_timezone_city(self, city):
  183. element = Wait(self.marionette).until(
  184. expected.element_present(*self._timezone_city_locator))
  185. Wait(self.marionette).until(expected.element_displayed(element))
  186. self.accessibility.click(element)
  187. self.a11y_select(city)
  188. @property
  189. def timezone_title(self):
  190. return self.marionette.find_element(*self._time_zone_title_locator).text
  191. def tap_next_to_geolocation_section(self):
  192. self.tap_next()
  193. Wait(self.marionette).until(expected.element_displayed(*self._section_geolocation_locator))
  194. def a11y_click_next_to_geolocation_section(self):
  195. self.a11y_click_next()
  196. Wait(self.marionette).until(expected.element_displayed(*self._section_geolocation_locator))
  197. def disable_geolocation(self):
  198. self._geolocation_switch.disable()
  199. @property
  200. def is_geolocation_enabled(self):
  201. return self._geolocation_switch.is_checked
  202. @property
  203. def _geolocation_switch(self):
  204. return GaiaBinaryControl(self.marionette, self._enable_geolocation_checkbox_locator)
  205. def a11y_disable_geolocation(self):
  206. element = Wait(self.marionette).until(
  207. expected.element_present(*self._enable_geolocation_checkbox_locator))
  208. Wait(self.marionette).until(expected.element_displayed(element))
  209. self.accessibility.click(element)
  210. def tap_next_to_import_contacts_section(self):
  211. self.tap_next()
  212. Wait(self.marionette).until(expected.element_displayed(*self._section_import_contacts_locator))
  213. def a11y_click_next_to_import_contacts_section(self):
  214. self.a11y_click_next()
  215. Wait(self.marionette).until(expected.element_displayed(*self._section_import_contacts_locator))
  216. def tap_import_from_sim(self):
  217. self.marionette.find_element(*self._import_from_sim_locator).tap()
  218. def wait_for_contacts_imported(self):
  219. feedback = self.marionette.find_element(
  220. *self._sim_import_feedback_locator)
  221. Wait(self.marionette).until(
  222. lambda m: self._pattern_contacts.match(feedback.text) is not None,
  223. message='Contact did not import from sim before timeout')
  224. @property
  225. def count_imported_contacts(self):
  226. import_sim_message = self.marionette.find_element(*self._sim_import_feedback_locator).text
  227. import_sim_count = None
  228. if self._pattern_contacts_0.match(import_sim_message) is not None:
  229. import_sim_count = 0
  230. elif self._pattern_contacts_1.match(import_sim_message) is not None:
  231. import_sim_count = 1
  232. elif self._pattern_contacts_N.match(import_sim_message) is not None:
  233. count = self._pattern_contacts_N.match(import_sim_message).group(1)
  234. import_sim_count = int(count)
  235. return import_sim_count
  236. def tap_next_to_firefox_accounts_section(self):
  237. self.tap_next()
  238. Wait(self.marionette).until(
  239. expected.element_displayed(*self._section_firefox_accounts_locator))
  240. def a11y_click_next_to_firefox_accounts_section(self):
  241. self.a11y_click_next()
  242. Wait(self.marionette).until(
  243. expected.element_displayed(*self._section_firefox_accounts_locator))
  244. def tap_next_to_late_customization_section(self):
  245. self.tap_next()
  246. Wait(self.marionette).until(
  247. expected.element_displayed(*self._section_late_customization_locator))
  248. def tap_next_to_welcome_browser_section(self):
  249. self.tap_next()
  250. Wait(self.marionette).until(
  251. expected.element_displayed(*self._section_welcome_browser_locator))
  252. def a11y_click_next_to_welcome_browser_section(self):
  253. self.a11y_click_next()
  254. Wait(self.marionette).until(
  255. expected.element_displayed(*self._section_welcome_browser_locator))
  256. @property
  257. def is_metrics_basic_enabled(self):
  258. return self._metrics_basic_radio.is_checked
  259. def enable_metrics_basic(self):
  260. self._metrics_basic_radio.enable()
  261. @property
  262. def _metrics_basic_radio(self):
  263. return GaiaBinaryControl(self.marionette, self._metrics_basic_locator)
  264. @property
  265. def is_metrics_enhanced_enabled(self):
  266. return self._metrics_enhanced_radio.is_checked
  267. def enable_metrics_enhanced(self):
  268. self._metrics_enhanced_radio.enable()
  269. @property
  270. def _metrics_enhanced_radio(self):
  271. return GaiaBinaryControl(self.marionette, self._metrics_enhanced_locator)
  272. @property
  273. def is_metrics_none_enabled(self):
  274. return self._metrics_none_radio.is_checked
  275. def enable_metrics_none(self):
  276. self._metrics_none_radio.enable()
  277. @property
  278. def _metrics_none_radio(self):
  279. return GaiaBinaryControl(self.marionette, self._metrics_none_locator)
  280. def tap_next_to_privacy_browser_section(self):
  281. self.tap_next()
  282. Wait(self.marionette).until(
  283. expected.element_displayed(*self._section_browser_privacy_locator))
  284. def a11y_click_next_to_privacy_browser_section(self):
  285. self.a11y_click_next()
  286. Wait(self.marionette).until(
  287. expected.element_displayed(*self._section_browser_privacy_locator))
  288. def enter_email_address(self, email):
  289. # TODO assert that this is preserved in the system somewhere. Currently it is not used
  290. self.marionette.find_element(*self._email_field_locator).send_keys(email)
  291. self.marionette.switch_to_frame()
  292. Wait(self.marionette).until(lambda m: self.keyboard.is_keyboard_displayed)
  293. self.apps.switch_to_displayed_app()
  294. def tap_next_to_finish_section(self):
  295. self.tap_next()
  296. Wait(self.marionette).until(expected.element_displayed(*self._section_finish_locator))
  297. def a11y_click_next_to_finish_section(self):
  298. self.a11y_click_next()
  299. Wait(self.marionette).until(expected.element_displayed(*self._section_finish_locator))
  300. def tap_skip_tour(self):
  301. element = self.marionette.find_element(*self._skip_tour_button_locator)
  302. self.tap_element_from_system_app(element, add_statusbar_height=True)
  303. def a11y_click_skip_tour(self):
  304. self.accessibility.click(self.marionette.find_element(*self._skip_tour_button_locator))
  305. def run_ftu_setup_with_default_values(self):
  306. count = 0
  307. while not self.is_element_displayed(*self._take_tour_button_locator):
  308. if self.is_element_displayed(*self._next_button_locator):
  309. self.tap_next()
  310. else:
  311. count = count + 1
  312. if count > 5:
  313. break
  314. def tap_take_tour(self):
  315. take_tour = Wait(self.marionette).until(
  316. expected.element_present(*self._take_tour_button_locator))
  317. Wait(self.marionette).until(expected.element_displayed(take_tour))
  318. Wait(self.marionette).until(expected.element_enabled(take_tour))
  319. take_tour.tap()
  320. @property
  321. def step1_header_text(self):
  322. header = Wait(self.marionette).until(
  323. expected.element_present(*self._step_header_locator))
  324. Wait(self.marionette).until(expected.element_displayed(header))
  325. return header.text
  326. def tap_tour_next(self):
  327. next = Wait(self.marionette).until(
  328. expected.element_present(*self._tour_next_button_locator))
  329. Wait(self.marionette).until(expected.element_displayed(next))
  330. Wait(self.marionette).until(expected.element_enabled(next))
  331. next.tap()
  332. def tap_back(self):
  333. back = Wait(self.marionette).until(
  334. expected.element_present(*self._tour_back_button_locator))
  335. Wait(self.marionette).until(expected.element_displayed(back))
  336. back.tap()
  337. @property
  338. def step2_header_text(self):
  339. header = Wait(self.marionette).until(
  340. expected.element_present(*self._step_header_locator))
  341. Wait(self.marionette).until(expected.element_displayed(header))
  342. return header.text
  343. @property
  344. def step3_header_text(self):
  345. header = Wait(self.marionette).until(
  346. expected.element_present(*self._step_header_locator))
  347. Wait(self.marionette).until(expected.element_displayed(header))
  348. return header.text
  349. @property
  350. def step4_header_text(self):
  351. header = Wait(self.marionette).until(
  352. expected.element_present(*self._step_header_locator))
  353. Wait(self.marionette).until(expected.element_displayed(header))
  354. return header.text
  355. @property
  356. def step5_header_text(self):
  357. header = Wait(self.marionette).until(
  358. expected.element_present(*self._step_header_locator))
  359. Wait(self.marionette).until(expected.element_displayed(header))
  360. return header.text
  361. @property
  362. def step6_header_text(self):
  363. header = Wait(self.marionette).until(
  364. expected.element_present(*self._step_header_locator))
  365. Wait(self.marionette).until(expected.element_displayed(header))
  366. return header.text
  367. def wait_for_finish_tutorial_section(self):
  368. Wait(self.marionette).until(expected.element_displayed(
  369. Wait(self.marionette).until(expected.element_present(
  370. *self._section_tutorial_finish_locator))))
  371. def tap_lets_go_button(self):
  372. element = self.marionette.find_element(*self._lets_go_button_locator)
  373. self.tap_element_from_system_app(element, add_statusbar_height=True)