Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Merge pull request #195 from sashakruglov/issue_114
Browse files Browse the repository at this point in the history
Refactoring of check_article_topic and check_article_product methods
  • Loading branch information
AlinT committed May 27, 2013
2 parents c98a3b2 + 98be7f5 commit 56728f8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
2 changes: 2 additions & 0 deletions mocks/mock_article.py
Expand Up @@ -19,6 +19,8 @@ def __init__(self, suffix="", **kwargs):
self['summary'] = "this is an automated summary_%s%s" % (timestamp, suffix)
self['content'] = "automated content_%s%s" % (timestamp, suffix)
self['comment'] = "comment %s %s" % (timestamp, suffix)
self['product'] = "Firefox"
self['topic'] = "Websites"

# update with any keyword arguments passed
self.update(**kwargs)
28 changes: 19 additions & 9 deletions pages/desktop/knowledge_base_new_article.py
Expand Up @@ -27,7 +27,9 @@ def _page_title(self):
_article_content_box_locator = (By.CSS_SELECTOR, '#editor > textarea')
_article_slug_box_locator = (By.ID, 'id_slug')
_article_topic_locator = (By.CSS_SELECTOR, 'input[name=topics]')
_article_topic_label_locator = (By.CSS_SELECTOR, '.topics label')
_article_product_locator = (By.CSS_SELECTOR, 'input[name=products]')
_article_product_label_locator = (By.CSS_SELECTOR, 'label[for*="id_products_"]')
_article_preview_btn_locator = (By.CSS_SELECTOR, 'div.submit > .btn-preview')
_article_preview_content_locator = (By.CSS_SELECTOR, 'div#preview > div#doc-content')
_article_submit_btn_locator = (By.CSS_SELECTOR, '.btn.btn-important.btn-submit')
Expand All @@ -41,8 +43,8 @@ def set_article(self, mock_article):
self.set_article_title(mock_article['title'])
self.set_article_slug(mock_article['slug'])
self.set_article_category(mock_article['category'])
self.check_article_topic(1)
self.check_article_product(1)
self.check_article_topic(mock_article['topic'])
self.check_article_product(mock_article['product'])
self.set_article_keyword(mock_article['keyword'])
self.set_article_summary(mock_article['summary'])
self.set_article_content(mock_article['content'])
Expand All @@ -57,13 +59,21 @@ def set_article_category(self, category):
select_box = Select(self.selenium.find_element(*self._article_category_menu_locator))
select_box.select_by_visible_text(category)

def check_article_topic(self, index):
index = index - 1
self.selenium.find_elements(*self._article_topic_locator)[index].click()

def check_article_product(self, index):
index = index - 1
self.selenium.find_elements(*self._article_product_locator)[index].click()
def check_article_topic(self, topic):
self._check_element_by_label_text(
topic, self._article_topic_locator, self._article_topic_label_locator)

def check_article_product(self, product):
self._check_element_by_label_text(
product, self._article_product_locator, self._article_product_label_locator)

def _check_element_by_label_text(self, text_to_match, input_locator, label_locator):
inputs = self.selenium.find_elements(*input_locator)
labels = [e.text for e in self.selenium.find_elements(*label_locator)]
for i in xrange(len(labels)):
if labels[i].lower() == text_to_match.lower():
inputs[i].click()
break

def set_article_keyword(self, keyword):
self.selenium.find_element(*self._article_keywords_box_locator).send_keys(keyword)
Expand Down

0 comments on commit 56728f8

Please sign in to comment.