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

Added Login/Logout test #12

Merged
merged 1 commit into from Mar 3, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions credentials.yaml
@@ -0,0 +1,3 @@
default:
username: <username>
password: <password>
4 changes: 4 additions & 0 deletions pages/base.py
Expand Up @@ -17,6 +17,10 @@ def login_region(self):
from regions.login import LoginRegion from regions.login import LoginRegion
return LoginRegion(self.testsetup) return LoginRegion(self.testsetup)


@property
def is_logged_in(self):
return self.login_region.is_logout_visible

@property @property
def page_title(self): def page_title(self):
return self.selenium.find_element(*self._page_title_locator).text return self.selenium.find_element(*self._page_title_locator).text
23 changes: 22 additions & 1 deletion pages/regions/login.py
Expand Up @@ -4,15 +4,36 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.


from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException


from page import Page from page import Page




class LoginRegion(Page): class LoginRegion(Page):


_sign_up_link_locator = (By.CSS_SELECTOR, ".signup a") _sign_up_link_locator = (By.CSS_SELECTOR, '.signup a')
_login_username_field_locator = (By.ID, 'log')
_login_password_field_locator = (By.ID, 'pwd')
_login_submit_button_locator = (By.CSS_SELECTOR, '.login .submit button')
_logout_link_locator = (By.CSS_SELECTOR, '.howdy .user-logout a')

@property
def is_logout_visible(self):
try:
return self.selenium.find_element(*self._logout_link_locator).text == 'Log Out'
except NoSuchElementException:
return False


def click_sign_up(self): def click_sign_up(self):
self.selenium.find_element(*self._sign_up_link_locator).click() self.selenium.find_element(*self._sign_up_link_locator).click()
from pages.registration import RegistrationPage from pages.registration import RegistrationPage
return RegistrationPage(self.testsetup) return RegistrationPage(self.testsetup)

def login(self, user='default'):
credentials = self.testsetup.credentials[user]
self.selenium.find_element(*self._login_username_field_locator).send_keys(credentials['username'])
self.selenium.find_element(*self._login_password_field_locator).send_keys(credentials['password'])
self.selenium.find_element(*self._login_submit_button_locator).click()

def logout(self):
self.selenium.find_element(*self._logout_link_locator).click()
1 change: 0 additions & 1 deletion pages/registration.py
Expand Up @@ -6,7 +6,6 @@
import time import time


from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from unittestzero import Assert


from base import BasePage from base import BasePage


Expand Down
26 changes: 26 additions & 0 deletions tests/test_login_logout.py
@@ -0,0 +1,26 @@
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from unittestzero import Assert

from pages.home import HomePage


class TestLoginLogout:

def test_login(self, mozwebqa):
home_pg = HomePage(mozwebqa)
home_pg.go_to_home_page()
home_pg.login_region.login()
Assert.true(home_pg.is_logged_in)


def test_logout(self, mozwebqa):
home_pg = HomePage(mozwebqa)
home_pg.go_to_home_page()
home_pg.login_region.login()
Assert.true(home_pg.is_logged_in)
home_pg.login_region.logout()
Assert.true(not home_pg.is_logged_in)
11 changes: 9 additions & 2 deletions tests/test_user_registration.py
Expand Up @@ -3,15 +3,19 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.


import pytest
import random import random


from unittestzero import Assert from unittestzero import Assert


from pages.home import HomePage from pages.home import HomePage


xfail = pytest.mark.xfail



class TestUserRegistration: class TestUserRegistration:


@xfail(reason="There is a capcha on the registration page")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for xfailing this.

def test_new_user_can_register(self, mozwebqa): def test_new_user_can_register(self, mozwebqa):
home_pg = HomePage(mozwebqa) home_pg = HomePage(mozwebqa)
home_pg.go_to_home_page() home_pg.go_to_home_page()
Expand All @@ -26,8 +30,11 @@ def test_username_only_allows_lower_case_letters_and_numbers(self, mozwebqa):
registration_pg = home_pg.login_region.click_sign_up() registration_pg = home_pg.login_region.click_sign_up()


invalid_characters = range(32, 47) + range(58, 96) + range(123, 127) invalid_characters = range(32, 47) + range(58, 96) + range(123, 127)
invalid_username = "automatedtest%s" % chr(random.choice(invalid_characters)) invalid_username = "automatedtest%s" % chr(random.choice(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines too long for you, eh? Fair enough. :P

invalid_characters))

print "invalid_username : %s" % invalid_username print "invalid_username : %s" % invalid_username
registration_pg.type_username(invalid_username) registration_pg.type_username(invalid_username)
registration_pg.submit_registration() registration_pg.submit_registration()
Assert.equal(registration_pg.username_error, "Only lowercase letters and numbers allowed") Assert.equal(registration_pg.username_error,
"Only lowercase letters and numbers allowed")