diff --git a/README.md b/README.md index 246a08b15c7..487069aa3d6 100755 --- a/README.md +++ b/README.md @@ -59,6 +59,15 @@ Since cfgov-refresh is based off of cf-demo we encourage you to start with the [cf-demo docs](http://cfpb.github.io/capital-framework/cf-demo/). _More specific cfgov-refresh docs are coming soon._ +### Tests + +To run browser tests, you'll need to perform the following steps: + +1. Install chromedriver: + * Mac: `brew install chromedriver` + * Manual (Linux/Mac): Download the latest [Chromedriver](http://chromedriver.storage.googleapis.com/index.html) binary and put it somehwere on your path (e.g. /path/to/your/venv/bin) +2. `pip install -r _tests/requirements.txt` +3. `nosetests -v _tests` ## How this repo is versioned diff --git a/_tests/__init__.py b/_tests/__init__.py new file mode 100644 index 00000000000..f7f3d743eab --- /dev/null +++ b/_tests/__init__.py @@ -0,0 +1,45 @@ +import os +import json + +from elasticsearch import Elasticsearch + +index_name = "cfgov_test" +root = os.getcwd() + +def setup_package(): + es = Elasticsearch() + if es.indices.exists(index_name): + es.indices.delete(index_name) + es.indices.create(index=index_name) + + # Create the mappings + create_mapping('newsroom', '_settings/posts_mappings.json') + create_mapping('watchroom', '_settings/posts_mappings.json') + + # Index the documents + index_documents('newsroom', '_tests/fixtures/newsroom.json') + index_documents('views', '_tests/fixtures/views.json') + index_documents('watchroom', '_tests/fixtures/watchroom.json') + +def teardown_package(): + es = Elasticsearch() + es.indices.delete(index_name) + +def create_mapping(doc_type, mapping_json_path): + es = Elasticsearch() + mapping_json = open(os.path.join(root, mapping_json_path)) + mapping = json.load(mapping_json) + es.indices.put_mapping(index=index_name, + doc_type=doc_type, + body={doc_type: mapping}) + +def index_documents(doc_type, json_path): + es = Elasticsearch() + json_file = open(os.path.join(root, json_path)) + documents = json.load(json_file) + + for document in documents: + es.create(index=index_name, + doc_type=doc_type, + id=document['_id'], + body=document) \ No newline at end of file diff --git a/_tests/fixtures/newsroom.json b/_tests/fixtures/newsroom.json new file mode 100644 index 00000000000..7c65311aef7 --- /dev/null +++ b/_tests/fixtures/newsroom.json @@ -0,0 +1,320 @@ +[ + { + "attachments": [], + "excerpt": "This is just an excerpt of the content", + "taxonomy_cfpb_newsroom_tag_taxonomy": [ + { + "post_count": 88, + "description": "", + "title": "Credit cards", + "id": 19, + "slug": "credit-cards" + }, + { + "post_count": 26, + "description": "", + "title": "Foreclosure", + "id": 441, + "slug": "foreclosure" + }, + { + "post_count": 188, + "description": "", + "title": "Mortgages", + "id": 23, + "slug": "mortgages" + } + ], + "taxonomy_cfpb_newsroom_cat_taxonomy": [ + { + "description": "", + "parent": 0, + "title": "Op-Ed", + "post_count": 17, + "slug": "op-ed", + "id": 443 + } + ], + "taxonomy_author": [ + { + "post_count": 30, + "description": "", + "title": "Batman", + "id": 779, + "slug": "batman" + } + ], + "id": 45929, + "custom_fields": {}, + "category": [ + "Op-Ed" + ], + "author": [ + "Batman" + ], + "content": "Some test content", + "comment_count": 0, + "categories": [], + "type": "cfpb_newsroom", + "status": "publish", + "parent": 0, + "tags": [ + "Credit cards", + "Foreclosure", + "Mortgages" + ], + "taxonomy_fj_tag": [ + { + "post_count": 112, + "description": "", + "title": "Credit cards", + "id": 19, + "slug": "credit-cards" + }, + { + "post_count": 29, + "description": "", + "title": "Foreclosure", + "id": 441, + "slug": "foreclosure" + }, + { + "post_count": 255, + "description": "", + "title": "Mortgages", + "id": 23, + "slug": "mortgages" + } + ], + "date": "2010-09-17T04:41:50Z", + "slug": "fighting-to-protect-testers", + "comment_status": "closed", + "title_plain": "Fighting to Protect Testers", + "title": "Fighting to Protect Testers", + "modified": "2010-09-17 04:41:50", + "dek": "Test dek", + "_id": "fighting-to-protect-testers", + "order": 0 + }, + { + "attachments": [], + "excerpt": "Test excerpt for this post", + "taxonomy_cfpb_newsroom_tag_taxonomy": [ + { + "post_count": 97, + "description": "", + "title": "Banking", + "id": 435, + "slug": "banking-2" + } + ], + "taxonomy_cfpb_newsroom_cat_taxonomy": [ + { + "description": "", + "parent": 0, + "title": "Op-Ed", + "post_count": 17, + "slug": "op-ed", + "id": 443 + } + ], + "taxonomy_author": [ + { + "post_count": 30, + "description": "", + "title": "Batman", + "id": 779, + "slug": "batman" + } + ], + "id": 45893, + "custom_fields": {}, + "category": [ + "Op-Ed" + ], + "author": [ + "Batman" + ], + "content": "Here is a bunch of content", + "comment_count": 0, + "categories": [], + "type": "cfpb_newsroom", + "status": "publish", + "parent": 0, + "tags": [ + "Banking" + ], + "taxonomy_fj_tag": [ + { + "post_count": 98, + "description": "", + "title": "Banking", + "id": 435, + "slug": "banking-2" + } + ], + "date": "2010-11-10T12:00:52Z", + "slug": "ttttttest", + "comment_status": "closed", + "title_plain": "Ttttttest", + "title": "Ttttttest", + "modified": "2010-11-10 12:00:52", + "dek": "The dek goes here", + "_id": "ttttttest", + "order": 0 + }, + { + "attachments": [], + "excerpt": "Excerpts are shorter versions of the real thing", + "taxonomy_cfpb_newsroom_tag_taxonomy": [ + { + "post_count": 32, + "description": "", + "title": "Personnel", + "id": 433, + "slug": "personnel" + }, + { + "post_count": 28, + "description": "", + "title": "Servicemembers", + "id": 32, + "slug": "servicemembers" + } + ], + "taxonomy_cfpb_newsroom_cat_taxonomy": [ + { + "description": "", + "parent": 0, + "title": "Press Release", + "post_count": 245, + "slug": "pressrelease", + "id": 425 + } + ], + "taxonomy_author": [], + "id": 45927, + "custom_fields": {}, + "category": [ + "Press Release" + ], + "author": [], + "content": "Some content would be cool to go here", + "comment_count": 0, + "categories": [], + "type": "cfpb_newsroom", + "status": "publish", + "parent": 0, + "tags": [ + "Personnel", + "Servicemembers" + ], + "taxonomy_fj_tag": [ + { + "post_count": 32, + "description": "", + "title": "Personnel", + "id": 433, + "slug": "personnel" + }, + { + "post_count": 69, + "description": "", + "title": "Servicemembers", + "id": 32, + "slug": "servicemembers" + } + ], + "date": "2011-01-06T04:51:16Z", + "slug": "this-is-for-testing-purposes", + "comment_status": "closed", + "title_plain": "This is for testing purposes", + "title": "This is for testing purposes", + "modified": "2011-01-06 04:51:16", + "dek": "Some sort of dek info", + "_id": "this-is-for-testing-purposes", + "order": 0 + }, + { + "attachments": [], + "excerpt": "Excerpt Excerpt Excerpt", + "taxonomy_cfpb_newsroom_tag_taxonomy": [ + { + "post_count": 88, + "description": "", + "title": "Credit cards", + "id": 19, + "slug": "credit-cards" + }, + { + "post_count": 32, + "description": "", + "title": "Personnel", + "id": 433, + "slug": "personnel" + } + ], + "taxonomy_cfpb_newsroom_cat_taxonomy": [ + { + "description": "", + "parent": 0, + "title": "Op-Ed", + "post_count": 17, + "slug": "op-ed", + "id": 443 + } + ], + "taxonomy_author": [ + { + "post_count": 30, + "description": "", + "title": "Batman", + "id": 779, + "slug": "batman" + } + ], + "id": 45923, + "custom_fields": {}, + "category": [ + "Op-Ed" + ], + "author": [ + "Batman" + ], + "content": "More blog content", + "comment_count": 0, + "categories": [], + "type": "cfpb_newsroom", + "status": "publish", + "parent": 0, + "tags": [ + "Credit cards", + "Personnel" + ], + "taxonomy_fj_tag": [ + { + "post_count": 112, + "description": "", + "title": "Credit cards", + "id": 19, + "slug": "credit-cards" + }, + { + "post_count": 32, + "description": "", + "title": "Personnel", + "id": 433, + "slug": "personnel" + } + ], + "date": "2011-01-06T20:50:14Z", + "slug": "just-more-testing", + "comment_status": "closed", + "title_plain": "Blah blah blah", + "title": "Blah blah blah", + "modified": "2011-01-06 20:50:14", + "dek": "Dek info here", + "_id": "just-more-testing", + "order": 0 + } +] \ No newline at end of file diff --git a/_tests/fixtures/views.json b/_tests/fixtures/views.json new file mode 100644 index 00000000000..36c28f75bf6 --- /dev/null +++ b/_tests/fixtures/views.json @@ -0,0 +1,247 @@ +[ + { + "attachments": [], + "excerpt": "", + "id": 62519, + "custom_fields": { + "related_hero": [ + "" + ] + }, + "related_links": [], + "author": { + "first_name": "Mike", + "last_name": "m", + "name": "Mike", + "url": "", + "slug": "mm", + "nickname": "mm", + "id": 233, + "description": "" + }, + "comments": [], + "content": "", + "comment_count": 0, + "categories": [], + "type": "view", + "status": "publish", + "parent": 0, + "tags": [], + "date": "2014-08-25 17:47:01", + "slug": "contact-us", + "comment_status": "closed", + "title_plain": "contact us", + "title": "contact us", + "modified": "2014-08-25 17:47:13", + "dek": "", + "_id": "contact-us", + "order": 0 + }, + { + "attachments": [], + "popular_posts": [ + "spring-2014-rulemaking-agenda", + "our-board-and-council-meetings-are-changing", + "save-the-date-join-us-for-a-consumer-advisory-board-meeting-in-reno-nevada", + "summer-jobs-are-a-perfect-time-to-build-financial-skills-for-young-people", + "truth-in-lending-rule-now-available-in-easier-to-navigate-format" + ], + "excerpt": "", + "id": 62331, + "custom_fields": { + "related_hero": [ + "" + ], + "related_link_2": [ + "http://www.consumerfinance.gov/askcfpb/", + "Ask CFPB" + ], + "related_link_1": [ + "http://www.consumerfinance.gov/knowbeforeyouowe/", + "Know Before You Owe" + ], + "popular_posts": [ + "spring-2014-rulemaking-agenda", + "our-board-and-council-meetings-are-changing", + "save-the-date-join-us-for-a-consumer-advisory-board-meeting-in-reno-nevada", + "summer-jobs-are-a-perfect-time-to-build-financial-skills-for-young-people", + "truth-in-lending-rule-now-available-in-easier-to-navigate-format" + ], + "related_link_0": [ + "http://www.consumerfinance.gov/newsroom/prepared-remarks-of-cfpb-director-richard-cordray-at-the-consumer-response-field-hearing/", + "Prepared Remarks of CFPB Director Richard Cordray at the Consumer Response Field Hearing" + ] + }, + "related_links": [ + [ + "http://www.consumerfinance.gov/newsroom/prepared-remarks-of-cfpb-director-richard-cordray-at-the-consumer-response-field-hearing/", + "Prepared Remarks of CFPB Director Richard Cordray at the Consumer Response Field Hearing" + ], + [ + "http://www.consumerfinance.gov/knowbeforeyouowe/", + "Know Before You Owe" + ], + [ + "http://www.consumerfinance.gov/askcfpb/", + "Ask CFPB" + ] + ], + "author": { + "first_name": "Dan", + "last_name": "f", + "name": "Dan", + "url": "", + "slug": "df", + "nickname": "df", + "id": 329, + "description": "" + }, + "comments": [], + "content": "", + "comment_count": 0, + "categories": [], + "type": "view", + "status": "publish", + "parent": 0, + "tags": [], + "date": "2014-07-14 15:23:03", + "slug": "newsroom", + "comment_status": "closed", + "title_plain": "newsroom", + "title": "newsroom", + "modified": "2014-08-26 16:14:09", + "dek": "", + "_id": "newsroom", + "order": 0 + }, + { + "attachments": [], + "excerpt": "", + "id": 62031, + "custom_fields": { + "related_link_4": [ + "http://www.consumerfinance.gov/blog/truth-in-lending-rule-now-available-in-easier-to-navigate-format", + "Truth in Lending rule now available in easier-to-navigate format" + ], + "related_link_3": [ + "http://www.consumerfinance.gov/blog/save-the-date-join-us-for-a-consumer-advisory-board-meeting-in-reno-nevada", + "Save the date: Join us for a Consumer Advisory Board meeting in Reno, Nevada" + ], + "related_link_2": [ + "http://www.consumerfinance.gov/blog/our-board-and-council-meetings-are-changing", + "Our Board and Council meetings are changing" + ], + "related_link_1": [ + "http://www.consumerfinance.gov/blog/summer-jobs-are-a-perfect-time-to-build-financial-skills-for-young-people", + "Summer jobs are a perfect time to build financial skills for young people" + ], + "related_link_0": [ + "http://www.consumerfinance.gov/blog/spring-2014-rulemaking-agenda", + "Spring 2014 rulemaking agenda" + ], + "related_hero": [ + "two-years-of-standing-up-for-consumers" + ], + "related_post": [ + "Johnson & Johnson", + "Johnson & Johnson" + ] + }, + "related_links": [ + [ + "http://www.consumerfinance.gov/blog/spring-2014-rulemaking-agenda", + "Spring 2014 rulemaking agenda" + ], + [ + "http://www.consumerfinance.gov/blog/summer-jobs-are-a-perfect-time-to-build-financial-skills-for-young-people", + "Summer jobs are a perfect time to build financial skills for young people" + ], + [ + "http://www.consumerfinance.gov/blog/our-board-and-council-meetings-are-changing", + "Our Board and Council meetings are changing" + ], + [ + "http://www.consumerfinance.gov/blog/save-the-date-join-us-for-a-consumer-advisory-board-meeting-in-reno-nevada", + "Save the date: Join us for a Consumer Advisory Board meeting in Reno, Nevada" + ], + [ + "http://www.consumerfinance.gov/blog/truth-in-lending-rule-now-available-in-easier-to-navigate-format", + "Truth in Lending rule now available in easier-to-navigate format" + ] + ], + "author": { + "first_name": "Ross", + "last_name": "K", + "name": "k", + "url": "", + "slug": "k", + "nickname": "k", + "id": 59, + "description": "" + }, + "comments": [], + "content": "", + "comment_count": 0, + "categories": [], + "type": "view", + "status": "publish", + "hero": { + "attachments": [], + "excerpt": "", + "id": 63077, + "custom_fields": { + "mobile_image": [ + "/static/img/hero-small.png" + ], + "desktop_image": [ + "/static/img/hero-large.png" + ], + "background_color": [ + "rgb(51,126,125)" + ], + "related_post": [ + "two-years-of-standing-up-for-consumers", + "Announcements & updates" + ] + }, + "author": { + "first_name": "Scott", + "last_name": "C", + "name": "sc", + "url": "", + "slug": "sc", + "nickname": "sc", + "id": 211, + "description": "" + }, + "comments": [], + "content": "", + "comment_count": 0, + "categories": [], + "related_post": "two-years-of-standing-up-for-consumers", + "type": "cfpb_hero", + "status": "publish", + "parent": 0, + "tags": [], + "date": "2014-10-28 09:28:10", + "slug": "two-years-of-standing-up-for-consumers", + "comment_status": "closed", + "title_plain": "Two years of standing up for consumers", + "title": "Two years of standing up for consumers", + "modified": "2014-10-28 09:44:19", + "dek": "", + "order": 0 + }, + "parent": 0, + "tags": [], + "date": "2014-06-02 20:40:46", + "slug": "blog", + "comment_status": "closed", + "title_plain": "blog", + "title": "blog", + "modified": "2014-10-29 12:24:47", + "dek": "", + "_id": "blog", + "order": 0 + } +] \ No newline at end of file diff --git a/_tests/fixtures/watchroom.json b/_tests/fixtures/watchroom.json new file mode 100644 index 00000000000..140ffd31474 --- /dev/null +++ b/_tests/fixtures/watchroom.json @@ -0,0 +1,54 @@ +[ +{ + "attachments": [], + "links": [ + [ + "http://www.google.com", + "Google" + ], + [ + "http://www.yahoo.com", + "Yahoo" + ], + [ + "http://www.facebook.com", + "Facebook" + ] + ], + "excerpt": "

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat […]

\n", + "id": 62449, + "custom_fields": { + "watchroom_data_2": [ + "http://www.facebook.com", + "Facebook" + ], + "watchroom_data_0": [ + "http://www.google.com", + "Google" + ], + "watchroom_data_1": [ + "http://www.yahoo.com", + "Yahoo" + ] + }, + "author": [ + "Mike" + ], + "content": "

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

\n", + "comment_count": 0, + "categories": [], + "type": "watchroom", + "status": "publish", + "parent": 0, + "tags": [], + "date": "2014-07-28T16:19:46Z", + "slug": "who-watches-the-watchroom", + "comment_status": "closed", + "title_plain": "Who watches the watchroom", + "title": "Who watches the watchroom", + "modified": "2014-08-13 13:36:30", + "dek": "", + "_id": "who-watches-the-watchroom", + "order": 0 +} +] \ No newline at end of file diff --git a/_tests/requirements.txt b/_tests/requirements.txt new file mode 100644 index 00000000000..f9f5f972418 --- /dev/null +++ b/_tests/requirements.txt @@ -0,0 +1,3 @@ +selenium==2.44.0 +Flask-Testing==0.4.2 +-e git+https://github.com/cfpb/sheer.git#egg=sheer diff --git a/_tests/test.py b/_tests/test.py new file mode 100644 index 00000000000..c3a7261b24b --- /dev/null +++ b/_tests/test.py @@ -0,0 +1,206 @@ +import nose +import os +from nose.plugins.attrib import attr +from flask import Flask + +from selenium import webdriver +from elasticsearch import Elasticsearch +from elasticsearch.client import IndicesClient + + +from flask.ext.testing import LiveServerTestCase +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC + +from .test_helpers import * + +from sheer.wsgi import app_with_config + +class NewsroomTestCase(LiveServerTestCase): + + def create_app(self): + # Setup server + config = {'debug': False, + 'index': 'cfgov_test', + 'elasticsearch': [{'host': 'localhost', 'port': 9200}], + 'location': os.getcwd()} + application = app_with_config(config) + application.config['LIVESERVER_PORT'] = 31337 + return application + + def setUp(self): + self.driver = webdriver.Chrome() + self.driver.set_window_size(1400, 850) + self.driver.get('http://localhost:31337/newsroom/') + self.filter_dropdown_button = self.driver.find_element_by_xpath('//button[contains(text(), "Filter posts")]') + click_filter_posts(self) + + def test_filter_display_button(self): + filter_posts_display_button = self.driver.find_element_by_xpath( + '//button[contains(text(), "Filter posts")]' + ) + assert filter_posts_display_button.is_displayed() + + + @attr('checkbox') + def test_filter_checkboxes(self): + category_list = ["Op-Ed", "Press Release"] + for cat in category_list: + checkbox = WebDriverWait(self.driver, 20).until( + EC.visibility_of_element_located(( + By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat) + )) + ) + # checkbox = self.driver.find_element_by_xpath( + # '//label/span[contains(text(), "{0}")]/..'.format(cat)) + checkbox.click() + assert "is-checked" in checkbox.get_attribute('class') + checkbox.click() + assert "is-checkedFocus" in checkbox.get_attribute('class') + + @attr('search') + @attr('category') + def test_filter_category_search(self): + category_list = ["Op-Ed", "Press Release"] + for cat in category_list: + click_filter_posts(self) + checkbox = WebDriverWait(self.driver, 20).until( + EC.visibility_of_element_located(( + By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat))) + ) + checkbox.click() + filter_results_button = WebDriverWait(self.driver, 20).until( + EC.visibility_of_element_located(( + By.XPATH, '//input[@value="Apply filters"]')) + ) + filter_results_button.click() + cat = coerce_category_for_dom(cat) + cat_type_elem = WebDriverWait(self.driver, 20).until( + EC.visibility_of_element_located(( + By.XPATH, '//a[@href="?filter_category={0}"]'.format(cat))) + ) + assert cat_type_elem + click_filter_posts(self) + cat = coerce_category_for_dom(cat) + checkbox = WebDriverWait(self.driver, 20).until( + EC.visibility_of_element_located(( + By.XPATH, '//label/span[contains(text(), "{0}")]/..'.format(cat))) + ) + checkbox.click() + + @attr('search') + @attr('topics') + def test_filter_topic_search(self): + topic_input = WebDriverWait(self.driver, 20).until( + EC.visibility_of_element_located(( + By.XPATH, '//input[@value="Search for topics"]' + )) + ) + topic_input.click() + topic_input.send_keys("for") + topic_choice_results = self.driver.find_element_by_xpath( + '//div[@id="filter_tags_chosen"]/div/ul[@class="chosen-results"]' + ) + assert topic_choice_results.is_displayed() + choice = WebDriverWait(self.driver, 20).until( + EC.visibility_of_element_located(( + By.XPATH, + '//div[@id="filter_tags_chosen"]/div/ul[@class="chosen-results"]/li/em[contains(text(),"For")]/..' + )) + ) + choice.click() + topic_elem = self.driver.find_element_by_xpath( + '//div[@id="filter_tags_chosen"]/ul/li/span[contains(text(), "Foreclosure")]' + ) + assert topic_elem + + @attr('search') + @attr('authors') + def test_filter_author_search(self): + author_input = WebDriverWait(self.driver, 20).until( + EC.visibility_of_element_located(( + By.XPATH, '//input[@value="Search for authors"]' + )) + ) + author_input.click() + author_input.send_keys("bat") + author_choice_results = self.driver.find_element_by_xpath( + '//div[@id="filter_author_chosen"]/div/ul[@class="chosen-results"]' + ) + assert author_choice_results.is_displayed() + choice = WebDriverWait(self.driver, 20).until( + EC.visibility_of_element_located(( + By.XPATH, + '//div[@id="filter_author_chosen"]/div/ul[@class="chosen-results"]/li/em[contains(text(),"Bat")]/..' + )) + ) + choice.click() + author_elem = self.driver.find_element_by_xpath( + '//div[@id="filter_author_chosen"]/ul/li/span[contains(text(), "Batman")]' + ) + assert author_elem + filter_results_button = WebDriverWait(self.driver, 20).until( + EC.visibility_of_element_located(( + By.XPATH, '//input[@value="Apply filters"]' + )) + ) + filter_results_button.click() + author = WebDriverWait(self.driver, 20).until( + EC.visibility_of_element_located(( + By.XPATH, '//p[@class="summary_byline"][contains(text(), "Bat")]' + )) + ) + assert author + + @attr('search') + @attr('date') + def test_filter_date_search(self): + # scroll(self.driver) + WebDriverWait(self.driver, 20).until( + EC.visibility_of_element_located(( + By.XPATH, + '//div[@id="filter_range_date_gte-replacement"]/div[1]' + )) + ) + + # click 'from month' + self.driver.find_element_by_xpath( + '//select[@id="filter_from_month"]/option[@value="01"]' + ).click() + # click 'from year' + self.driver.find_element_by_xpath( + '//select[@id="filter_from_year"]/option[@value="2011"]' + ).click() + + # click 'to month' + self.driver.find_element_by_xpath( + '//select[@id="filter_to_month"]/option[@value="02"]' + ).click() + # click 'to year' + self.driver.find_element_by_xpath( + '//select[@id="filter_to_year"]/option[@value="2011"]' + ).click() + + # Search + WebDriverWait(self.driver, 20).until( + EC.visibility_of_element_located(( + By.XPATH, '//input[@value="Apply filters"]' + )) + ).click() + + filtered_article_date = WebDriverWait(self.driver, 20).until( + EC.visibility_of_element_located(( + By.XPATH, + '//div[@id="pagination_content"]/article[1]/div[1]/span[1]' + )) + ) + filtered = 'jan' in filtered_article_date.text.lower() or 'feb' in filtered_article_date.text.lower() + assert filtered + + def tearDown(self): + self.driver.close() + +if __name__ == '__main__': + nose.main() diff --git a/tests/test_helpers.py b/_tests/test_helpers.py similarity index 63% rename from tests/test_helpers.py rename to _tests/test_helpers.py index 898e2e9bcae..dce5e0b313a 100644 --- a/tests/test_helpers.py +++ b/_tests/test_helpers.py @@ -1,12 +1,3 @@ -# import nose - -# from selenose.cases import SeleniumTestCase -# from nose.plugins.attrib import attr -# from selenium.webdriver.common.by import By -# from selenium.webdriver.support.ui import WebDriverWait -# from selenium.webdriver.support import expected_conditions as ec - - def click_filter_posts(test): test.filter_dropdown_button = test.driver.find_element_by_xpath('//button[contains(text(), "Filter posts")]') if test.filter_dropdown_button.get_attribute('aria-pressed') == 'false': diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/tests/requirements.txt b/tests/requirements.txt deleted file mode 100644 index 12895de2dab..00000000000 --- a/tests/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -nose==1.3.4 -selenium==2.44.0 -selenose==1.3 -wsgiref==0.1.2 diff --git a/tests/setup.cfg b/tests/setup.cfg deleted file mode 100644 index 402c5270ea5..00000000000 --- a/tests/setup.cfg +++ /dev/null @@ -1,7 +0,0 @@ -[nosetests] -with-selenium-driver = true -selenium-driver = chrome - -[selenium-driver:chrome] -webdriver = chrome - diff --git a/tests/test.py b/tests/test.py deleted file mode 100644 index 72067118147..00000000000 --- a/tests/test.py +++ /dev/null @@ -1,63 +0,0 @@ -import nose -from nose.plugins.attrib import attr - -from selenose.cases import SeleniumTestCase - -from selenium.webdriver.common.by import By -from selenium.webdriver.support.ui import WebDriverWait -from selenium.webdriver.support import expected_conditions as ec - -from .test_helpers import * - -class NewsroomTestCase(SeleniumTestCase): - def setUp(self): - self.driver.get('http://refresh.demo.cfpb.gov/newsroom/') - # self.filter_dropdown_button = self.driver.find_element_by_xpath('//button[contains(text(), "Filter posts")]') - click_filter_posts(self) - - def test_filter_display_button(self): - filter_options = self.driver.find_element_by_class_name('padded-container') - assert filter_options.is_displayed() - - @attr('checkbox') - def test_filter_checkboxes(self): - categoryList = ["Op-Ed", "Press Release", "Speech", "Testimony", "Blog"] - for cat in categoryList: - # use this after view changes value of checkbox input to 'Blog' - # checkbox = self.driver.find_element_by_xpath('//label/input[@value=\"'+ cat +'\"]/..') - checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') - checkbox.click() - assert "is-checked" in checkbox.get_attribute('class') - checkbox.click() - assert "is-checkedFocus" in checkbox.get_attribute('class') - - @attr('search') - @attr('category') - def test_filter_category_search(self): - categoryList = ["Op-Ed", "Press Release", "Speech", "Testimony"] # No Blog posts yet so add in when data is there - for cat in categoryList: - click_filter_posts(self) - # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') - checkbox = WebDriverWait(self.driver, 10).until( - ec.visibility_of_element_located((By.XPATH, '//label/span[contains(text(), \"'+ cat +'\")]/..')) - ) - checkbox.click() - filter_results_button = WebDriverWait(self.driver, 10).until( - ec.visibility_of_element_located((By.XPATH, '//input[@value="Apply filters"]')) - ) - filter_results_button.click() - cat = coerce_category_for_dom(cat) - cat_type_elem = WebDriverWait(self.driver, 10).until( - ec.visibility_of_element_located((By.XPATH, '//a[@href="?filter_category='+ cat +'"]')) - ) - assert cat_type_elem - click_filter_posts(self) - cat = coerce_category_for_dom(cat) - # checkbox = self.driver.find_element_by_xpath('//label/span[contains(text(), \"'+ cat +'\")]/..') - checkbox = WebDriverWait(self.driver, 10).until( - ec.visibility_of_element_located((By.XPATH, '//label/span[contains(text(), \"'+ cat +'\")]/..')) - ) - checkbox.click() - -if __name__ == '__main__': - nose.main()