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

Commit

Permalink
Switch to using pytest-variables for credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
davehunt committed May 18, 2015
1 parent be1ff58 commit df597f0
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 111 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -92,7 +92,7 @@ Some of the tests in sumo-tests require logging in to https://support.allizom.or

1. Create two username and password combinations on https://support.allizom.org
2. Join [#sumo][sumo] and ask for one of these users to be upgraded to admin (or ask someone on [#mozwebqa][mozwebqa] to do this for you)
3. Copy sumo-tests/credentials.yaml to a location outside of sumo-tests. update the 'default' and 'admin' users in credentials.yaml with those credentials
3. Copy sumo-tests/variables.json to a location outside of sumo-tests. update the 'default' and 'admin' users in variables.json with those credentials

[mozwebqa]:http://chat.mibbit.com/?server=irc.mozilla.org&channel=#mozwebqa
[sumo]:http://chat.mibbit.com/?server=irc.mozilla.org&channel=#sumo
Expand All @@ -104,9 +104,9 @@ Some of the tests in sumo-tests require logging in to https://support.allizom.or
Before each test run, clean up the repo:
find . \( -name 'results*' -or -name '*.pyc' \) -print0 | xargs -0 rm -Rf

To run tests locally its a simple case of calling the command below from this directory
To run tests locally it's a simple case of calling the command below from this directory:

py.test --driver=firefox --destructive --credentials=/full/path/to/credentials.yaml .
py.test --driver=firefox --destructive --variables=/full/path/to/variables.json .

__Output__
Output of a test run should look like this:
Expand Down
43 changes: 0 additions & 43 deletions credentials.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions pages/desktop/base.py
Expand Up @@ -25,9 +25,9 @@ def click_card_grid(self, locator):
def header(self):
return self.HeaderRegion(self.testsetup)

def sign_in(self, user="default"):
def sign_in(self, username, password):
login = self.header.click_login()
login.log_in(user)
login.log_in(username, password)

def sign_out(self):
self.header.click_logout()
Expand Down
10 changes: 4 additions & 6 deletions pages/desktop/login_page.py
Expand Up @@ -23,14 +23,12 @@ class LoginPage(Base):
_logged_in_as_div_locator = (By.CSS_SELECTOR, 'div#mod-login_box > div')
_logged_in_text = 'Logged in as'

def log_in(self, user='default'):
credentials = self.testsetup.credentials[user]

self.selenium.find_element(*self._username_box_locator).send_keys(credentials['name'])
self.selenium.find_element(*self._password_box_locator).send_keys(credentials['password'])
def log_in(self, username, password):
self.selenium.find_element(*self._username_box_locator).send_keys(username)
self.selenium.find_element(*self._password_box_locator).send_keys(password)
self.selenium.find_element(*self._log_in_button_locator).click()

if not self.header.is_user_logged_in:
error = self.selenium.find_element(*self._login_error_locator).text
error = "login failed for %s\n" % credentials['name'] + error
error = "login failed for %s\n" % username + error
Assert.fail(error)
34 changes: 17 additions & 17 deletions pages/desktop/page_provider.py
Expand Up @@ -18,21 +18,21 @@ def _set_window_size(self):
if self.selenium.get_window_size()['width'] < 1920:
self.selenium.set_window_size(1920, 1080)

def _go_to_page(self, page_object, do_login=False, user='default'):
def _go_to_page(self, page_object, username=None, password=None):
self._set_window_size()
self.selenium.get(self.base_url + page_object._page_url)
page_object.is_the_current_page
if (do_login):
page_object.sign_in(user)
if all((username, password)):
page_object.sign_in(username, password)
page_object.header.dismiss_staging_site_warning_if_present()
return page_object

def _go_to_page_with_login_redirect(self, page_object, user='default'):
def _go_to_page_with_login_redirect(self, page_object, username, password):
self._set_window_size()
from pages.desktop.login_page import LoginPage
self.selenium.get(self.base_url + page_object._page_url)
login_page = LoginPage(self.testsetup)
login_page.log_in(user)
login_page.log_in(username, password)
page_object.is_the_current_page
page_object.header.dismiss_staging_site_warning_if_present()
return page_object
Expand All @@ -45,28 +45,28 @@ def new_user_registration_page(self):

''' pages for which login is optional '''

def home_page(self, do_login=False, user='default'):
def home_page(self, username=None, password=None):
from pages.desktop.support_home_page import SupportHomePage
return self._go_to_page(SupportHomePage(self.testsetup), do_login, user)
return self._go_to_page(SupportHomePage(self.testsetup), username, password)

def new_question_page(self, do_login=True, user='default'):
def new_question_page(self, username=None, password=None):
from pages.desktop.questions_page import AskNewQuestionsPage
return self._go_to_page(AskNewQuestionsPage(self.testsetup), do_login, user)
return self._go_to_page(AskNewQuestionsPage(self.testsetup), username, password)

def questions_page(self, do_login=False, user='default'):
def questions_page(self, username=None, password=None):
from pages.desktop.questions_page import QuestionsPage
return self._go_to_page(QuestionsPage(self.testsetup), do_login, user)
return self._go_to_page(QuestionsPage(self.testsetup), username, password)

def search_page(self, do_login=False, user='default'):
def search_page(self, username=None, password=None):
from pages.desktop.search_page import SearchPage
return self._go_to_page(SearchPage(self.testsetup), do_login, user)
return self._go_to_page(SearchPage(self.testsetup), username, password)

def refine_search_page(self, do_login=True, user='default'):
def refine_search_page(self, username=None, password=None):
from pages.desktop.refine_search_page import RefineSearchPage
return self._go_to_page(RefineSearchPage(self.testsetup), do_login, user)
return self._go_to_page(RefineSearchPage(self.testsetup), username, password)

''' pages for which login is required '''

def new_kb_article_page(self, user='admin'):
def new_kb_article_page(self, username, password):
from pages.desktop.knowledge_base_new_article import KnowledgeBaseNewArticle
return self._go_to_page_with_login_redirect(KnowledgeBaseNewArticle(self.testsetup), user)
return self._go_to_page_with_login_redirect(KnowledgeBaseNewArticle(self.testsetup), username, password)
4 changes: 0 additions & 4 deletions pages/page.py
Expand Up @@ -94,7 +94,3 @@ def wait_for_ajax(self):
if self.selenium.execute_script("return jQuery.active == 0"):
return
raise Exception("Wait for AJAX timed out after %s seconds" % count)

def get_user_name(self, user='default'):
credentials = self.testsetup.credentials[user]
return credentials['name']
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -8,5 +8,6 @@ chardet==2.1.1
py==1.4.26
pytest==2.7.0
pytest-mozwebqa
pytest-variables
requests==2.4.3
selenium
30 changes: 20 additions & 10 deletions tests/desktop/test_kb_article.py
Expand Up @@ -10,13 +10,15 @@

class TestKnowledgeBaseArticle:

def test_that_article_can_be_created(self, mozwebqa):
def test_that_article_can_be_created(self, mozwebqa, variables):
"""
Creates a new knowledge base article.
Verifies creation.
Deletes the article
"""
kb_new_article = PageProvider(mozwebqa).new_kb_article_page()
user = variables['users']['admin']
kb_new_article = PageProvider(mozwebqa).new_kb_article_page(
user['username'], user['password'])

# create a new article
mock_article = MockArticle()
Expand All @@ -37,14 +39,16 @@ def test_that_article_can_be_created(self, mozwebqa):
kb_article = kb_edit_article.navigation.click_show_history()
kb_article.delete_entire_article_document()

def test_that_article_can_be_edited(self, mozwebqa):
def test_that_article_can_be_edited(self, mozwebqa, variables):
"""
Creates a new knowledge base article.
Verifies creation.
Edits the article, verifies the edition.
Deletes the article
"""
kb_new_article = PageProvider(mozwebqa).new_kb_article_page()
user = variables['users']['admin']
kb_new_article = PageProvider(mozwebqa).new_kb_article_page(
user['username'], user['password'])

# create a new article
mock_article = MockArticle()
Expand Down Expand Up @@ -74,13 +78,15 @@ def test_that_article_can_be_edited(self, mozwebqa):
kb_article_history = kb_edit_article.navigation.click_show_history()
kb_article_history.delete_entire_article_document()

def test_that_article_can_be_deleted(self, mozwebqa):
def test_that_article_can_be_deleted(self, mozwebqa, variables):
"""
Creates a new knowledge base article.
Deletes the article.
Verifies the deletion.
"""
kb_new_article = PageProvider(mozwebqa).new_kb_article_page()
user = variables['users']['admin']
kb_new_article = PageProvider(mozwebqa).new_kb_article_page(
user['username'], user['password'])

# create a new article
mock_article = MockArticle()
Expand All @@ -100,13 +106,15 @@ def test_that_article_can_be_deleted(self, mozwebqa):
actual_page_title = kb_article_history.page_title
Assert.contains("Page Not Found", actual_page_title)

def test_that_article_can_be_previewed_before_submitting(self, mozwebqa):
def test_that_article_can_be_previewed_before_submitting(self, mozwebqa, variables):
"""
Start a new knowledge base article.
Preview.
Verify the contents in the preview
"""
kb_new_article = PageProvider(mozwebqa).new_kb_article_page()
user = variables['users']['default']
kb_new_article = PageProvider(mozwebqa).new_kb_article_page(
user['username'], user['password'])

# create a new article
mock_article = MockArticle()
Expand All @@ -119,12 +127,14 @@ def test_that_article_can_be_previewed_before_submitting(self, mozwebqa):

# Does not need to be deleted as it does not commit the article

def test_that_article_can_be_translated(self, mozwebqa):
def test_that_article_can_be_translated(self, mozwebqa, variables):
"""
Creates a new knowledge base article.
Translate article
"""
kb_new_article = PageProvider(mozwebqa).new_kb_article_page()
user = variables['users']['admin']
kb_new_article = PageProvider(mozwebqa).new_kb_article_page(
user['username'], user['password'])

# create a new article
mock_article = MockArticle()
Expand Down
29 changes: 19 additions & 10 deletions tests/desktop/test_login_logout.py
Expand Up @@ -13,9 +13,10 @@
class TestLoginLogout:

@pytest.mark.nondestructive
def test_login(self, mozwebqa):
def test_login(self, mozwebqa, variables):
user = variables['users']['default']
home_page = PageProvider(mozwebqa).home_page()
home_page.sign_in(user='default')
home_page.sign_in(user['username'], user['password'])

Assert.true(home_page.header.is_user_logged_in, 'User not shown to be logged in')

Expand All @@ -29,8 +30,10 @@ def test_login(self, mozwebqa):
'search_page',
'refine_search_page',
])
def test_logout_from_pages(self, mozwebqa, page_method):
page_under_test = getattr(PageProvider(mozwebqa), page_method)(do_login=True, user='default')
def test_logout_from_pages(self, mozwebqa, variables, page_method):
user = variables['users']['default']
page_under_test = getattr(PageProvider(mozwebqa), page_method)(
user['username'], user['password'])
Assert.true(page_under_test.header.is_user_logged_in, 'User not shown to be logged in')

# sign out
Expand All @@ -39,8 +42,10 @@ def test_logout_from_pages(self, mozwebqa, page_method):
Assert.true(page_under_test.header.is_user_logged_out)

@pytest.mark.native
def test_logout_from_new_kb_article_page(self, mozwebqa):
new_kb_page = PageProvider(mozwebqa).new_kb_article_page()
def test_logout_from_new_kb_article_page(self, mozwebqa, variables):
user = variables['users']['default']
new_kb_page = PageProvider(mozwebqa).new_kb_article_page(
user['username'], user['password'])
Assert.true(new_kb_page.header.is_user_logged_in, 'User not shown to be logged in')

# sign out
Expand All @@ -49,8 +54,10 @@ def test_logout_from_new_kb_article_page(self, mozwebqa):
Assert.true(register_page.header.is_user_logged_out)

@pytest.mark.native
def test_logout_from_edit_kb_article_page(self, mozwebqa):
kb_new_article = PageProvider(mozwebqa).new_kb_article_page()
def test_logout_from_edit_kb_article_page(self, mozwebqa, variables):
user = variables['users']['default']
kb_new_article = PageProvider(mozwebqa).new_kb_article_page(
user['username'], user['password'])

# create a new article
mock_article = MockArticle()
Expand All @@ -66,8 +73,10 @@ def test_logout_from_edit_kb_article_page(self, mozwebqa):
Assert.true(register_page.header.is_user_logged_out)

@pytest.mark.native
def test_logout_from_translate_kb_article_page(self, mozwebqa):
kb_new_article = PageProvider(mozwebqa).new_kb_article_page()
def test_logout_from_translate_kb_article_page(self, mozwebqa, variables):
user = variables['users']['default']
kb_new_article = PageProvider(mozwebqa).new_kb_article_page(
user['username'], user['password'])

# create a new article
mock_article = MockArticle()
Expand Down
30 changes: 16 additions & 14 deletions tests/desktop/test_questions.py
Expand Up @@ -13,14 +13,16 @@
class TestQuestions:

@pytest.mark.native
def test_that_posting_question_works(self, mozwebqa):
def test_that_posting_question_works(self, mozwebqa, variables):
"""Posts a question to /questions"""
user = variables['users']['default']
timestamp = datetime.datetime.today()
q_to_ask = "automation test question %s" % (timestamp)
q_details = "This is a test. %s" % (timestamp)

# go to the /questions/new page and log in
ask_new_questions_page = PageProvider(mozwebqa).new_question_page()
ask_new_questions_page = PageProvider(mozwebqa).new_question_page(
user['username'], user['password'])

# post a question
ask_new_questions_page.click_firefox_product_link()
Expand Down Expand Up @@ -90,19 +92,20 @@ def test_that_questions_problem_count_increments(self, mozwebqa):

Assert.equal(initial_count + 1, post_click_count)

def test_contributor_flow_to_support_forum_post(self, mozwebqa):
def test_contributor_flow_to_support_forum_post(self, mozwebqa, variables):
"""
Shows a contributor can start on the home page and move
all the way to answering a question in the forum.
"""
reply_text = "reply"

# 1. Start on the home page
# 2. Log in
# 3. Use the contributor bar to go to the forums.
# The questions page should list 20 posts.
# 3.1 go to the question page
questions_page = PageProvider(mozwebqa).questions_page(do_login=True)
user = variables['users']['default']
questions_page = PageProvider(mozwebqa).questions_page(
user['username'], user['password'])

questions_page.click_all_products()
# 3.2 ensure the size of the list is 20
Assert.greater(questions_page.questions_count, 0,
Expand All @@ -117,11 +120,10 @@ def test_contributor_flow_to_support_forum_post(self, mozwebqa):
# 5. Go to the thread
# 6. Scroll to the bottom and click into the text field
# 7. Type reply
# 7.1 get the login-user name to check the author of the reply
username = forum_page.header.login_user_name
# 7.2 reply the post
forum_page.post_reply(reply_text)
# 7.3 check if posting a reply finishes without an error
is_reply_present = forum_page.is_reply_text_present(username, reply_text)
Assert.true(is_reply_present,
u'reply with "%s" text posted by %s is not present' % (reply_text, username))
# 7.1 reply the post
reply = "reply"
forum_page.post_reply(reply)
# 7.2 check if posting a reply finishes without an error
Assert.true(forum_page.is_reply_text_present(user['username'], reply),
u'reply with "%s" text posted by %s is not present' % (
reply, user['username']))

0 comments on commit df597f0

Please sign in to comment.