Permalink
Browse files

Merge pull request #302 from viorelaioia/fix_registration_tests

Update registration tests to set location
  • Loading branch information...
2 parents 02d67de + e31a334 commit c50d357b9530cd868bc65f7b11dd8f5c1ec76b1a @viorelaioia viorelaioia committed on GitHub Mar 24, 2017
Showing with 44 additions and 22 deletions.
  1. +33 −22 pages/register.py
  2. +11 −0 tests/test_register.py
View
@@ -6,8 +6,6 @@
from selenium.webdriver.common.by import By
-from selenium.webdriver.common.keys import Keys
-from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from pages.base import Base
@@ -17,25 +15,27 @@ class Register(Base):
_error_locator = (By.CSS_SELECTOR, 'div.alert.alert-error')
_full_name_field_locator = (By.ID, 'id_full_name')
- _map_search_box_locator = (By.ID, 'location_search')
- _country_locator = (By.ID, 'display_country')
_privacy_locator = (By.ID, 'id_optin')
_privacy_error_message_locator = (By.CSS_SELECTOR, '.error-message')
_create_profile_button_locator = (By.CSS_SELECTOR, '#form-submit-registration')
_recaptcha_checkbox_locator = (By.CSS_SELECTOR, '.recaptcha-checkbox-checkmark')
_recaptcha_checkbox_checked = (By.CSS_SELECTOR, '.recaptcha-checkbox-checked')
+ _country_countainer_locator = (By.ID, 'select2-id_country-container')
+ _input_locator = (By.CSS_SELECTOR, '.select2-search__field')
+ _country_results_list_locator = (By.CSS_SELECTOR, '#select2-id_country-results > li.select2-results__option--highlighted')
+ _first_country_search_result_locator = (By.CSS_SELECTOR, '#select2-id_country-results > li.select2-results__option--highlighted:first-child')
+ _region_container_locator = (By.ID, "select2-id_region-container")
+ _region_results_list_locator = (By.CSS_SELECTOR, '#select2-id_region-results > li.select2-results__option--highlighted')
+ _first_region_search_result_locator = (By.CSS_SELECTOR, '#select2-id_region-results > li.select2-results__option--highlighted:first-child')
+ _city_container_locator = (By.ID, "select2-id_city-container")
+ _city_results_list_locator = (By.CSS_SELECTOR, '#select2-id_city-results > li.select2-results__option--highlighted')
+ _first_city_search_result_locator = (By.CSS_SELECTOR, '#select2-id_city-results > li.select2-results__option--highlighted:first-child')
+
@property
def error_message(self):
return self.selenium.find_element(*self._error_locator).text
- def set_location(self, location):
- element = self.selenium.find_element(*self._map_search_box_locator)
- element.send_keys(location)
- element.send_keys(Keys.RETURN)
- WebDriverWait(self.selenium, self.timeout).until(
- lambda s: s.find_element(*self._country_locator).text != "")
-
def set_full_name(self, full_name):
element = self.selenium.find_element(*self._full_name_field_locator)
element.send_keys(full_name)
@@ -45,17 +45,28 @@ def privacy_error_message(self):
return self.selenium.find_element(*self._privacy_error_message_locator).text
def select_country(self, country):
- element = self.selenium.find_element(*self._country_locator)
- select = Select(element)
- select.select_by_value(country)
-
- def set_state(self, state_name):
- element = self.selenium.find_element(*self._state_locator)
- element.send_keys(state_name)
-
- def set_city(self, city_name):
- element = self.selenium.find_element(*self._city_locator)
- element.send_keys(city_name)
+ self.selenium.find_element(*self._country_countainer_locator).click()
+ self.selenium.find_element(*self._input_locator).send_keys(country)
+ self.wait_for_element_present(*self._first_country_search_result_locator)
+ countries_list = self.selenium.find_elements(*self._country_results_list_locator)
+ country_item = next(item for item in countries_list if country == item.text)
+ country_item.click()
+
+ def select_region(self, region):
+ self.selenium.find_element(*self._region_container_locator).click()
+ self.selenium.find_element(*self._input_locator).send_keys(region)
+ self.wait_for_element_present(*self._first_region_search_result_locator)
+ regions_list = self.selenium.find_elements(*self._region_results_list_locator)
+ region_item = next(item for item in regions_list if region in item.text)
+ region_item.click()
+
+ def select_city(self, city):
+ self.selenium.find_element(*self._city_container_locator).click()
+ self.selenium.find_element(*self._input_locator).send_keys(city)
+ self.wait_for_element_present(*self._first_city_search_result_locator)
+ cities_list = self.selenium.find_elements(*self._city_results_list_locator)
+ city_item = next(item for item in cities_list if city in item.text)
+ city_item.click()
def check_privacy(self):
self.selenium.find_element(*self._privacy_locator).click()
@@ -19,6 +19,11 @@ def test_profile_creation(self, base_url, selenium, new_user):
# Full name
profile.set_full_name("New MozilliansUser")
+ # Location
+ profile.select_country("United States")
+ profile.select_region("California")
+ profile.select_city("Mountain View")
+
# Agree to privacy policy
profile.check_privacy()
@@ -29,13 +34,19 @@ def test_profile_creation(self, base_url, selenium, new_user):
assert 'New MozilliansUser' == profile_page.name
assert new_user['email'] == profile_page.email
+ assert 'Mountain View, California, United States' == profile_page.location
def test_creating_profile_without_checking_privacy_policy_checkbox(self, base_url, selenium, new_user):
home_page = Home(base_url, selenium)
profile = home_page.create_new_user(new_user['email'])
profile.set_full_name("User that doesn't like policy")
+ # Location
+ profile.select_country("United States")
+ profile.select_region("Colorado")
+ profile.select_city("Durango")
+
# Click recaptcha box
profile.check_recaptcha()

0 comments on commit c50d357

Please sign in to comment.