Permalink
Browse files

Migrate to pytest-selenium

  • Loading branch information...
1 parent 29d10a6 commit aa1319a78bd2f2114a728053ace85573ef91ff75 @davehunt davehunt committed May 19, 2015
Showing with 44 additions and 33 deletions.
  1. +2 −0 .gitignore
  2. +1 −1 .travis.yml
  3. +0 −3 mozwebqa.cfg
  4. +1 −1 pages/base.py
  5. +4 −3 pages/login.py
  6. +4 −7 pages/messages.py
  7. +3 −3 pages/page.py
  8. +1 −1 requirements.txt
  9. +16 −0 tests/conftest.py
  10. +0 −2 tests/pytest.ini
  11. +8 −8 tests/test_login.py
  12. +4 −4 tests/test_messages.py
View
@@ -1,2 +1,4 @@
*.pyc
+.cache
+__pycache__
results
View
@@ -9,6 +9,6 @@ install:
- "pip install flake8"
- "pip install -r requirements.txt"
before_script: "flake8 ."
-script: "py.test -v --driver=Firefox --destructive --variables=variables.json tests"
+script: "py.test -v --driver Firefox --variables variables.json tests"
notifications:
email: false
View
@@ -1,3 +0,0 @@
-[DEFAULT]
-api = webdriver
-baseurl = http://www.allizom.org
View
@@ -16,7 +16,7 @@ class Base(Page):
def click_login(self):
self.selenium.find_element(*self._login_locator).click()
from pages.login import LoginPage
- return LoginPage(self.testsetup)
+ return LoginPage(self.base_url, self.selenium)
def click_logout(self):
self.selenium.find_element(*self._logout_locator).click()
View
@@ -2,7 +2,8 @@
# 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 flask import url_for
+from urlparse import urljoin
+
from selenium.webdriver.common.by import By
from messages import MessagesPage
@@ -27,10 +28,10 @@ def login(self, username, password):
self.type_username(username)
self.type_password(password)
self.click_login()
- return MessagesPage(self.testsetup)
+ return MessagesPage(self.base_url, self.selenium)
def open(self):
- self.selenium.get(url_for('login', _external=True))
+ self.selenium.get(urljoin(self.base_url, 'login'))
def type_password(self, value):
self.selenium.find_element(*self._password_locator).send_keys(value)
View
@@ -2,11 +2,9 @@
# 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 flask import url_for
from selenium.webdriver.common.by import By
from base import Base
-from page import Page
class MessagesPage(Base):
@@ -17,7 +15,7 @@ class MessagesPage(Base):
_title_locator = (By.ID, 'title')
def open(self):
- self.selenium.get(url_for('show_entries', _external=True))
+ self.selenium.get(self.base_url)
def create_message(self, title, text):
self.type_title(title)
@@ -29,7 +27,7 @@ def click_share(self):
@property
def messages(self):
- return [self.Message(self, el) for el in self.selenium.find_elements(
+ return [self.Message(el) for el in self.selenium.find_elements(
*self._messages_locator)]
def type_text(self, value):
@@ -38,13 +36,12 @@ def type_text(self, value):
def type_title(self, value):
self.selenium.find_element(*self._title_locator).send_keys(value)
- class Message(Page):
+ class Message(object):
_title_locator = (By.TAG_NAME, 'h2')
_text_locator = (By.CLASS_NAME, 'text')
- def __init__(self, testsetup, root_element):
- Page.__init__(self, testsetup)
+ def __init__(self, root_element):
self._root_element = root_element
@property
View
@@ -5,6 +5,6 @@
class Page(object):
- def __init__(self, testsetup):
- self.testsetup = testsetup
- self.selenium = testsetup.selenium
+ def __init__(self, base_url, selenium):
+ self.base_url = base_url
+ self.selenium = selenium
View
@@ -1,6 +1,6 @@
Flask
pytest
pytest-flask
-pytest-mozwebqa
pytest-variables
pytest-xdist
+pytest-selenium
View
@@ -19,3 +19,19 @@ def teardown():
request.addfinalizer(teardown)
return flaskr.app
+
+
+@pytest.fixture(scope='function')
+def base_url(live_server):
+ return live_server.url()
+
+
+@pytest.fixture(scope='function')
+def sensitive_url(request):
+ return False
+
+
+@pytest.fixture(scope='function', autouse=True)
+def _verify_url(request, base_url):
+ from pytest_selenium import pytest_selenium
+ pytest_selenium._verify_url(request, base_url)
View
@@ -1,2 +0,0 @@
-[pytest]
-usefixtures = live_server
View
@@ -10,33 +10,33 @@
pytestmark = pytest.mark.nondestructive
-def test_login(mozwebqa, variables):
+def test_login(base_url, selenium, variables):
"""Users can log in"""
- login_page = LoginPage(mozwebqa)
+ login_page = LoginPage(base_url, selenium)
login_page.open()
messages_page = login_page.login(variables['username'], variables['password'])
assert messages_page.notification == 'You were logged in'
-def test_invalid_username(mozwebqa, variables):
+def test_invalid_username(base_url, selenium, variables):
"""Attempt to log in with an invalid username"""
- login_page = LoginPage(mozwebqa)
+ login_page = LoginPage(base_url, selenium)
login_page.open()
login_page.login('invalid', variables['password'])
assert login_page.error == 'Error: Invalid username'
-def test_invalid_password(mozwebqa, variables):
+def test_invalid_password(base_url, selenium, variables):
"""Attempt to log in with an invalid password"""
- login_page = LoginPage(mozwebqa)
+ login_page = LoginPage(base_url, selenium)
login_page.open()
login_page.login(variables['username'], 'invalid')
assert login_page.error == 'Error: Invalid password'
-def test_logout(mozwebqa, variables):
+def test_logout(base_url, selenium, variables):
"""Make sure logout works"""
- messages_page = MessagesPage(mozwebqa)
+ messages_page = MessagesPage(base_url, selenium)
messages_page.open()
messages_page.login(variables['username'], variables['password'])
messages_page.logout()
@@ -7,9 +7,9 @@
from pages.messages import MessagesPage
-def test_create_message(mozwebqa, variables):
+def test_create_message(base_url, selenium, variables):
"""Create a message"""
- messages_page = MessagesPage(mozwebqa)
+ messages_page = MessagesPage(base_url, selenium)
messages_page.open()
messages_page.login(variables['username'], variables['password'])
messages_page.create_message('<Hello>', '<strong>HTML</strong> allowed here')
@@ -20,8 +20,8 @@ def test_create_message(mozwebqa, variables):
@pytest.mark.nondestructive
-def test_empty(mozwebqa):
+def test_empty(base_url, selenium):
"""Start with an empty list of messages"""
- messages_page = MessagesPage(mozwebqa)
+ messages_page = MessagesPage(base_url, selenium)
messages_page.open()
assert messages_page.messages == []

0 comments on commit aa1319a

Please sign in to comment.