Skip to content

Commit

Permalink
some improvements suggested by davehunt
Browse files Browse the repository at this point in the history
  • Loading branch information
stupchiy committed Mar 2, 2012
1 parent a2d71bf commit f773457
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
36 changes: 20 additions & 16 deletions pages/page_object.py
Expand Up @@ -19,7 +19,8 @@ class MySiteHomePage(Page):

_some_locator = (By.ID, 'some_locator')
_page_title = 'MySiteHomePage Page Title'
language_locator = (By.CSS_SELECTOR, '#language')
_language_locator = (By.ID, 'language')
_language_list_locator = (By.CSS_SELECTOR, '#language option')
_404_page_locator = (By.ID, 'mozilla-404')
_feed_link_locator = (By.CSS_SELECTOR, '#home-news-blog a')

Expand Down Expand Up @@ -88,26 +89,29 @@ def get_all_links(self):

@property
def is_change_locale_visible(self):
return self.is_element_visible(*self.language_locator)
return self.is_element_visible(*self._language_locator)

@property
def locales_count(self):
locator = (self.language_locator[0], '%s option' % self.language_locator[1])
return len(self.selenium.find_elements(*locator))
return len(self.selenium.find_elements(*self._language_list_locator))

@property
def selected_lang(self):
locator = (self.language_locator[0], '%s option' % self.language_locator[1])
return self.selenium.find_element(*locator).get_attribute('value')

def change_locale(self, lookup):
self.selenium.find_element(*self.language_locator).click()
if type(lookup) is int:
self.selenium.find_element(self.language_locator[0],
'%s option:nth-child(%i)' % (self.language_locator[1], lookup)).click()
elif type(lookup) is unicode:
self.selenium.find_element(self.language_locator[0],
'%s option[value=\'%s\']' % (self.language_locator[1], lookup)).click()
def locales(self):
return [self.LocaleOption(self.testsetup, lang)
for lang in self.selenium.find_elements(*self._language_list_locator)]

class LocaleOption(Page):

def __init__(self, testsetup, lang):
Page.__init__(self, testsetup)
self._root_element = lang

def select(self):
self._root_element.click()

@property
def value(self):
return self._root_element.get_attribute('value')

@property
def header(self):
Expand Down
20 changes: 10 additions & 10 deletions tests/test_file.py
Expand Up @@ -31,9 +31,8 @@ def test_locale(self, mozwebqa):
main_page = MySiteHomePage(mozwebqa)
if main_page.is_change_locale_visible:
for i in range(main_page.locales_count):
i += 1
main_page.change_locale(i)
selected = main_page.selected_lang
main_page.locales[i].select()
selected = main_page.locales[i].value
regex = re.search('((.*-)(.*))', selected)
try:
selected = regex.group(2) + regex.group(3).upper()
Expand Down Expand Up @@ -97,15 +96,16 @@ def test_robot_txt_present_on_site(self, mozwebqa):

def test_request_ends_with_slash(self, mozwebqa):
# BaseUrl Should be added without language in path for proper tests of locale (e.g. http://mozilla.org/firefox)
lang = 'en-US'
lang = ['en-US', 'de']
main_page = MySiteHomePage(mozwebqa, False)
url_path = urlparse(main_page.base_url)
response_path = main_page.get_response_path(main_page.base_url, lang)
url_path_re = urlparse(response_path)
if (url_path.path == '' and url_path_re.path == '/'):
Assert.true(response_path.endswith('/'))
else:
Assert.contains("/%s/" % lang, response_path)
for i in lang:
response_path = main_page.get_response_path(main_page.base_url, i)
url_path_re = urlparse(response_path)
if (url_path.path == '' and url_path_re.path == '/'):
Assert.true(response_path.endswith('/'))
else:
Assert.contains("/%s/" % i, response_path)

# def test_login(self, mozwebqa):
# pass
Expand Down

0 comments on commit f773457

Please sign in to comment.