-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
11 changed files
with
264 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
"""Unit test module for Selenium testing""" | ||
|
||
import os | ||
import sys | ||
import unittest | ||
|
||
from flask_testing import LiveServerTestCase | ||
import pytest | ||
from selenium import webdriver | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
import xvfbwrapper | ||
|
||
from tests import TestCase | ||
|
||
|
||
@unittest.skipUnless( | ||
( | ||
"SAUCE_USERNAME" in os.environ or | ||
xvfbwrapper.Xvfb().xvfb_exists() | ||
), | ||
"Xvfb not installed" | ||
) | ||
class IntegrationTestCase(TestCase, LiveServerTestCase): | ||
"""Test class for UI integration/workflow testing""" | ||
|
||
def setUp(self): | ||
"""Reset all tables before testing.""" | ||
|
||
if "SAUCE_USERNAME" in os.environ: | ||
# Configure driver for Sauce Labs | ||
# Presumes tunnel setup by Sauce Connect | ||
# On TravisCI, Sauce Connect tunnel setup by Sauce Labs addon | ||
# https://docs.travis-ci.com/user/sauce-connect | ||
platform = { | ||
"browserName": "firefox", | ||
"platform": "Windows 10", | ||
"version": "60.0", | ||
} | ||
capabilities = { | ||
"tunnel-identifier": os.environ["TRAVIS_JOB_NUMBER"], | ||
"extendedDebugging": "true", | ||
} | ||
metadata = { | ||
"name": self.id(), | ||
"build": "#%s %s" % ( | ||
os.environ["TRAVIS_BUILD_NUMBER"], | ||
os.environ["TRAVIS_BRANCH"], | ||
), | ||
"tags": [ | ||
"py" + os.environ["TRAVIS_PYTHON_VERSION"], | ||
"CI", | ||
], | ||
"passed": False, | ||
} | ||
capabilities.update(platform) | ||
capabilities.update(metadata) | ||
|
||
url = "http://{user}:{access_key}@localhost:4445/wd/hub".format( | ||
user=os.environ["SAUCE_USERNAME"], | ||
access_key=os.environ["SAUCE_ACCESS_KEY"], | ||
) | ||
|
||
self.driver = webdriver.Remote( | ||
desired_capabilities=capabilities, | ||
command_executor=url | ||
) | ||
|
||
else: | ||
if "DISPLAY" not in os.environ: | ||
# Non-graphical environment; use xvfb | ||
self.xvfb = xvfbwrapper.Xvfb() | ||
self.addCleanup(self.xvfb.stop) | ||
self.xvfb.start() | ||
self.driver = webdriver.Firefox(timeout=60) | ||
|
||
self.addCleanup(self.driver.quit) | ||
|
||
self.driver.root_uri = self.get_server_url() | ||
self.driver.implicitly_wait(30) | ||
self.verificationErrors = [] | ||
# default explicit wait time; use with Expected Conditions as needed | ||
self.wait = WebDriverWait(self.driver, 60) | ||
self.accept_next_alert = True | ||
|
||
super(IntegrationTestCase, self).setUp() | ||
|
||
def is_element_present(self, how, what): | ||
"""Detects whether or not an element can be found in DOM | ||
This function was exported from Selenium IDE | ||
""" | ||
try: | ||
self.driver.find_element(by=how, value=what) | ||
except NoSuchElementException as e: | ||
return False | ||
return True | ||
|
||
def is_alert_present(self): | ||
"""Detects whether an alert message is present | ||
This function was exported from Selenium IDE | ||
""" | ||
try: | ||
self.driver.switch_to_alert() | ||
except NoAlertPresentException as e: | ||
return False | ||
return True | ||
|
||
def close_alert_and_get_its_text(self): | ||
"""Closes an alert, if present, and returns its text | ||
If an alert is not present a NoAlertPresentException | ||
will be thrown. | ||
This function was exported from Selenium IDE | ||
""" | ||
try: | ||
alert = self.driver.switch_to_alert() | ||
alert_text = alert.text | ||
if self.accept_next_alert: | ||
alert.accept() | ||
else: | ||
alert.dismiss() | ||
return alert_text | ||
finally: | ||
self.accept_next_alert = True | ||
|
||
def tearDown(self): | ||
"""Clean db session, drop all tables.""" | ||
|
||
# Update job result metadata on Sauce Labs, if available | ||
if ( | ||
"SAUCE_USERNAME" in os.environ and | ||
|
||
# No exception being handled - test completed successfully | ||
sys.exc_info() == (None, None, None) | ||
): | ||
self.driver.execute_script("sauce:job-result=passed") | ||
|
||
self.assertEqual([], self.verificationErrors) | ||
|
||
super(IntegrationTestCase, self).tearDown() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from page_objects import PageElement, PageObject | ||
|
||
|
||
class LoginPage(PageObject): | ||
username = PageElement(name='email') | ||
password = PageElement(name='password') | ||
login_button = PageElement(css='input[type="submit"]') | ||
facebook_button = PageElement(css='.btn-facebook') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from flask import url_for | ||
import pytest | ||
from selenium.webdriver.support.ui import Select | ||
|
||
from tests import DEFAULT_PASSWORD, TEST_USERNAME | ||
from tests.integration_tests import IntegrationTestCase | ||
|
||
|
||
class TestLogin(IntegrationTestCase): | ||
"""Test class for Login integration tests""" | ||
|
||
def test_login_page(self): | ||
"""Ensure login works properly""" | ||
driver = self.driver | ||
driver.get(url_for("user.login", _external=True)) | ||
|
||
driver.find_element_by_name("email").click() | ||
driver.find_element_by_name("email").clear() | ||
driver.find_element_by_name("email").send_keys(TEST_USERNAME) | ||
driver.find_element_by_name("password").click() | ||
driver.find_element_by_name("password").clear() | ||
driver.find_element_by_name("password").send_keys(DEFAULT_PASSWORD) | ||
driver.find_element_by_xpath( | ||
"//input[@class='btn btn-tnth-primary btn-lg' and @value='LOG IN']" | ||
).click() | ||
driver.find_element_by_id("tnthUserBtn").click() | ||
driver.find_element_by_link_text("Log Out of TrueNTH").click() | ||
|
||
@pytest.mark.skip(reason="not able to complete consent page") | ||
def test_consent_after_login(self): | ||
driver = self.driver | ||
driver.get(url_for("eproms.home", _external=True)) | ||
driver.find_element_by_id("email").click() | ||
driver.find_element_by_id("email").clear() | ||
driver.find_element_by_id("email").send_keys(TEST_USERNAME) | ||
driver.find_element_by_id("password").click() | ||
driver.find_element_by_id("password").clear() | ||
driver.find_element_by_id("password").send_keys(DEFAULT_PASSWORD) | ||
driver.find_element_by_id("btnLogin").click() | ||
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='General Terms of Use'])[1]/following::i[1]").click() | ||
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='General Terms of Use'])[1]/following::i[2]").click() | ||
driver.find_element_by_id("next").click() | ||
driver.find_element_by_id("firstname").clear() | ||
driver.find_element_by_id("firstname").send_keys("Test") | ||
driver.find_element_by_id("lastname").click() | ||
driver.find_element_by_id("lastname").clear() | ||
driver.find_element_by_id("lastname").send_keys("User") | ||
driver.find_element_by_id("date").click() | ||
driver.find_element_by_id("month").click() | ||
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='(optional)'])[1]/following::option[11]").click() | ||
driver.find_element_by_id("year").click() | ||
driver.find_element_by_id("year").clear() | ||
driver.find_element_by_id("year").send_keys("1988") | ||
driver.find_element_by_id("role_patient").click() | ||
driver.find_element_by_id("next").click() | ||
driver.find_element_by_id("biopsy_no").click() | ||
driver.find_element_by_id("next").click() | ||
driver.find_element_by_id("stateSelector").click() | ||
Select(driver.find_element_by_id("stateSelector")).select_by_visible_text("Washington") | ||
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Your clinic of care.'])[1]/following::option[12]").click() | ||
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='UW Medicine (University of Washington)'])[1]/following::label[1]").click() | ||
driver.find_element_by_id("updateProfile").click() | ||
driver.find_element_by_id("tnthUserBtn").click() | ||
driver.find_element_by_link_text("Log Out of TrueNTH").click() |
Oops, something went wrong.