Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added Login/Logout test #12

Merged
merged 1 commit into from

4 participants

@tallowen
Collaborator

Added appropriate methods to login region. Also, marked registration test as
xfail because of captcha

tests/test_login_logout.py
@@ -0,0 +1,23 @@
+#!/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/.
+
+import random
@bebef1987 Collaborator

we don't use this import here you should remove it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
pages/regions/login.py
((5 lines not shown))
from page import 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 = (By.CSS_SELECTOR, '.login #log')
+ _login_password_field = (By.CSS_SELECTOR, '.login #pwd')
+ _login_submit_button = (By.CSS_SELECTOR, '.login .submit button')
+ _logout_link = (By.CSS_SELECTOR, '.howdy .user-logout a')
+
+ @property
+ def is_logout_visable(self):
@zacc
zacc added a note

/s/visable/visible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
pages/regions/login.py
((24 lines not shown))
def click_sign_up(self):
self.selenium.find_element(*self._sign_up_link_locator).click()
from pages.registration import RegistrationPage
return RegistrationPage(self.testsetup)
+
+ def login(self, user='user'):
+ credentials = self.testsetup.credentials['user']
@zacc
zacc added a note

this needs to be user without the ' otherwise it will ignore the user setting passed in :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@tallowen
Collaborator

Mistakes have been fixed, pep8 passes except for the 80 character rule.

pages/regions/login.py
((5 lines not shown))
from page import 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 = (By.CSS_SELECTOR, '.login #log')
@davehunt Owner

As 'log' is a unique ID, we should use (By.ID, 'log')

@davehunt Owner

For all locator variables please could you add a _locator suffix? Thanks :)

@tallowen Collaborator

How am I going to keep my lines under 30 characters??? i kid :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
pages/regions/login.py
((5 lines not shown))
from page import 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 = (By.CSS_SELECTOR, '.login #log')
+ _login_password_field = (By.CSS_SELECTOR, '.login #pwd')
@davehunt Owner

As above, we can just reference this by ID

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
pages/regions/login.py
((5 lines not shown))
from page import 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 = (By.CSS_SELECTOR, '.login #log')
+ _login_password_field = (By.CSS_SELECTOR, '.login #pwd')
+ _login_submit_button = (By.CSS_SELECTOR, '.login .submit button')
+ _logout_link = (By.CSS_SELECTOR, '.howdy .user-logout a')
+
+ @property
+ def is_logout_visible(self):
+ try:
@davehunt Owner

Could we try using return self.is_element_visible(self._logout_link_locator)

@tallowen Collaborator

Hmm I cant seem to find reference to this in the docs or with a google search. Can you point me towards where I should be looking for these things?

@zacc
zacc added a note

is_element_visible is our own method, it is situated in page.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
credentials.yaml
@@ -0,0 +1,3 @@
+user:
@davehunt Owner

Could we use 'default' in place of 'user' as this would make it consistent with other projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
pages/regions/login.py
((24 lines not shown))
def click_sign_up(self):
self.selenium.find_element(*self._sign_up_link_locator).click()
from pages.registration import RegistrationPage
return RegistrationPage(self.testsetup)
+
+ def login(self, user='user'):
@davehunt Owner

See previous suggest of 'default' instead of 'user'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tests/test_login_logout.py
@@ -0,0 +1,19 @@
+#!/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_logout(self, mozwebqa):
@davehunt Owner

Tests are cheap, let's split this into two :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@davehunt davehunt commented on the diff
tests/test_user_registration.py
((13 lines not shown))
class TestUserRegistration:
+ @xfail(reason="There is a capcha on the registration page")
@davehunt Owner

Thanks for xfailing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@davehunt davehunt commented on the diff
tests/test_user_registration.py
@@ -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()
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(
@davehunt Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@tallowen tallowen Added Login/Logout test
Added appropriate methods to login region. Also, marked failing test as
xfail because of captcha
4d34ecd
@bebef1987 bebef1987 commented on the diff
credentials.yaml
@@ -0,0 +1,3 @@
@bebef1987 Collaborator

Can you add the MPL2 license block here pls

@davehunt Owner
davehunt added a note

We probably don't need the license in the yaml file.

@tallowen Collaborator
tallowen added a note

If its really a big deal one could just put the license in the root of the repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@davehunt davehunt merged commit 4d34ecd into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 27, 2012
  1. @tallowen

    Added Login/Logout test

    tallowen authored
    Added appropriate methods to login region. Also, marked failing test as
    xfail because of captcha
This page is out of date. Refresh to see the latest.
View
3  credentials.yaml
@@ -0,0 +1,3 @@
+default:
+ username: <username>
+ password: <password>
View
4 pages/base.py
@@ -18,5 +18,9 @@ def login_region(self):
return LoginRegion(self.testsetup)
@property
+ def is_logged_in(self):
+ return self.login_region.is_logout_visible
+
+ @property
def page_title(self):
return self.selenium.find_element(*self._page_title_locator).text
View
23 pages/regions/login.py
@@ -4,15 +4,36 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from selenium.webdriver.common.by import By
+from selenium.common.exceptions import NoSuchElementException
from page import 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):
self.selenium.find_element(*self._sign_up_link_locator).click()
from pages.registration import RegistrationPage
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()
View
1  pages/registration.py
@@ -6,7 +6,6 @@
import time
from selenium.webdriver.common.by import By
-from unittestzero import Assert
from base import BasePage
View
26 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)
View
11 tests/test_user_registration.py
@@ -3,15 +3,19 @@
# 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/.
+import pytest
import random
from unittestzero import Assert
from pages.home import HomePage
+xfail = pytest.mark.xfail
+
class TestUserRegistration:
+ @xfail(reason="There is a capcha on the registration page")
@davehunt Owner

Thanks for xfailing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
def test_new_user_can_register(self, mozwebqa):
home_pg = HomePage(mozwebqa)
home_pg.go_to_home_page()
@@ -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()
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(
@davehunt Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ invalid_characters))
+
print "invalid_username : %s" % invalid_username
registration_pg.type_username(invalid_username)
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")
Something went wrong with that request. Please try again.