def test_charts_from_url(self): """ Given the url directly, test the page shows up correctly """ # Load Scatter Tool page with Statistical Variables. self.driver.get(self.url_ + SCATTER_URL + URL_HASH_1) # Wait until the chart has loaded. shared.wait_for_loading(self.driver) element_present = EC.presence_of_element_located( (By.ID, 'scatterplot')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) # Assert place name is correct. place_name = self.driver.find_element_by_xpath( '//*[@id="place-list"]/div/span') self.assertEqual(place_name.text, 'California') # Assert chart is correct. chart_title_y = self.driver.find_element_by_xpath( '//*[@id="chart"]/div[1]/div[1]/h3[1]') chart_title_x = self.driver.find_element_by_xpath( '//*[@id="chart"]/div[1]/div[1]/h3[2]') self.assertEqual(chart_title_y.text, "Population: Asian Alone Per Capita (2020)") self.assertEqual(chart_title_x.text, "Median Income (2020)") chart = self.driver.find_element_by_xpath('//*[@id="scatterplot"]') circles = chart.find_elements_by_tag_name('circle') self.assertGreater(len(circles), 20)
def test_manually_enter_options(self): """ Test entering place and stat var options manually will cause chart to show up. """ self.driver.get(self.url_ + MAP_URL) # Wait until search box is present. element_present = EC.presence_of_element_located((By.ID, 'ac')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) search_box_input = self.driver.find_element_by_id('ac') # Type california into the search box. search_box_input.send_keys(PLACE_SEARCH_CA) # Wait until there is at least one result in autocomplete results. element_present = EC.presence_of_element_located( (By.CLASS_NAME, 'pac-item')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) # Click on the first result. first_result = self.driver.find_element_by_css_selector( '.pac-item:nth-child(1)') first_result.click() element_present = EC.presence_of_element_located( (By.CLASS_NAME, 'mdl-chip')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) # Choose stat var shared.wait_for_loading(self.driver) demographics = self.driver.find_element_by_class_name('node-title') demographics.click() element_present = EC.presence_of_element_located( (By.ID, 'Median_Age_Persondc/g/Demographics-Median_Age_Person')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) self.driver.find_element_by_id( 'Median_Age_Persondc/g/Demographics-Median_Age_Person').click() # Assert chart is correct. element_present = EC.presence_of_element_located( (By.ID, 'choropleth-map')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) chart_title = self.driver.find_element_by_xpath( '//*[@id="chart-row"]/div/div[1]/div/div/div[1]/h3') self.assertEqual(chart_title.text, "Median Age (2019)") chart_map = self.driver.find_element_by_id('choropleth-map') map_regions = chart_map.find_elements_by_tag_name('path') self.assertEqual(len(map_regions), 58) chart_legend = self.driver.find_element_by_id('choropleth-legend') legend_ticks = chart_legend.find_elements_by_class_name('tick') self.assertGreater(len(legend_ticks), 5)
def test_landing_page_link(self): self.driver.get(self.url_ + MAP_URL) # Click on first link on landing page element_present = EC.presence_of_element_located( (By.ID, 'placeholder-container')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) self.driver.find_element_by_xpath( '//*[@id="placeholder-container"]/ul/li[1]/a[1]').click() # Assert chart loads shared.wait_for_loading(self.driver) element_present = EC.presence_of_element_located( (By.ID, 'choropleth-map')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) chart_map = self.driver.find_element_by_id('choropleth-map') map_regions = chart_map.find_elements_by_tag_name('path') self.assertGreater(len(map_regions), 1)
def test_landing_page_link(self): self.driver.get(self.url_ + SCATTER_URL) # Click on first link on landing page element_present = EC.presence_of_element_located( (By.ID, 'placeholder-container')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) self.driver.find_element_by_xpath( '//*[@id="placeholder-container"]/ul/li[1]/a[1]').click() # Assert chart loads shared.wait_for_loading(self.driver) element_present = EC.presence_of_element_located( (By.ID, 'scatterplot')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) chart = self.driver.find_element_by_xpath('//*[@id="scatterplot"]') circles = chart.find_elements_by_tag_name('circle') self.assertGreater(len(circles), 1)
def test_check_statvar_and_uncheck(self): """Test check and uncheck one statvar.""" # Load Timeline Tool page for California. self.driver.get(self.url_ + TIMELINE_URL + GEO_URL_1) element_present = EC.presence_of_element_located( (By.ID, 'hierarchy-section')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) charts = self.driver.find_elements_by_xpath( '//*[@id="chart-region"]/div[@class="chart-container"]') # Assert there is no chart. self.assertEqual(len(charts), 0) # Expand the Demographics section of the stat var hierarchy. shared.click_sv_group(self.driver, "Demographics") # Wait until stat vars are present and click on Population. shared.wait_for_loading(self.driver) element_present = EC.presence_of_element_located( (By.CLASS_NAME, "svg-node-child")) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) self.driver.find_element_by_id( "Count_Persondc/g/Demographics-Count_Person").click() # Wait until there is a card present. shared.wait_for_loading(self.driver) element_present = EC.presence_of_element_located( (By.XPATH, '//*[@id="chart-region"]/div')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) # Assert there is one chart. charts = self.driver.find_elements_by_xpath( '//*[@id="chart-region"]/div[@class="chart-container"]') self.assertEqual(len(charts), 1) # Uncheck the checked stat var. self.driver.find_element_by_id( "Count_Persondc/g/Demographics-Count_Person").click() # Assert there are no charts. shared.wait_for_loading(self.driver) charts = self.driver.find_elements_by_xpath( '//*[@id="chart-region"]/div[@class="chart-container"]') self.assertEqual(len(charts), 0)
def test_manually_enter_options(self): """ Test entering place and stat var options manually will cause chart to show up. """ self.driver.get(self.url_ + SCATTER_URL) # Wait until search box is present. element_present = EC.presence_of_element_located((By.ID, 'ac')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) search_box_input = self.driver.find_element_by_id('ac') # Type california into the search box. search_box_input.send_keys(PLACE_SEARCH_CA) # Wait until there is at least one result in autocomplete results. element_present = EC.presence_of_element_located( (By.CLASS_NAME, 'pac-item')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) # Click on the first result. first_result = self.driver.find_element_by_css_selector( '.pac-item:nth-child(1)') first_result.click() element_present = EC.presence_of_element_located( (By.CLASS_NAME, 'chip')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) # Choose place type element_present = EC.text_to_be_present_in_element( (By.ID, 'place-selector-place-type'), "County") WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) selects = Select( self.driver.find_element_by_id('place-selector-place-type')) selects.select_by_value('County') # Choose stat vars shared.wait_for_loading(self.driver) shared.click_sv_group(self.driver, "Demographics") # Click on median age button shared.wait_for_loading(self.driver) element_present = EC.presence_of_element_located( (By.ID, 'Median_Age_Persondc/g/Demographics-Median_Age_Person')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) self.driver.find_element_by_id( 'Median_Age_Persondc/g/Demographics-Median_Age_Person').click() # Click on median income button shared.wait_for_loading(self.driver) element_present = EC.presence_of_element_located( (By.ID, 'Median_Income_Persondc/g/Demographics-Median_Income_Person')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) self.driver.find_element_by_id( 'Median_Income_Persondc/g/Demographics-Median_Income_Person' ).click() # Assert chart is correct. element_present = EC.presence_of_element_located( (By.ID, 'scatterplot')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) chart_title_y = self.driver.find_element_by_xpath( '//*[@id="chart"]/div[1]/div[1]/h3[1]') chart_title_x = self.driver.find_element_by_xpath( '//*[@id="chart"]/div[1]/div[1]/h3[2]') self.assertEqual(chart_title_y.text, "Median Income (2020)") self.assertEqual(chart_title_x.text, "Median Age (2020)") chart = self.driver.find_element_by_xpath('//*[@id="scatterplot"]') circles = chart.find_elements_by_tag_name('circle') self.assertGreater(len(circles), 20)
def test_manually_enter_options(self): """ Test entering options will show preview and allow download of a file """ self.driver.get(self.url_ + DOWNLOAD_URL) # Wait until search box is present. element_present = EC.presence_of_element_located((By.ID, 'ac')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) search_box_input = self.driver.find_element_by_id('ac') # Type california into the search box. search_box_input.send_keys(PLACE_SEARCH_CA) # Wait until there is at least one result in autocomplete results. element_present = EC.presence_of_element_located( (By.CLASS_NAME, 'pac-item')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) # Click on the first result. first_result = self.driver.find_element_by_css_selector( '.pac-item:nth-child(1)') first_result.click() element_present = EC.presence_of_element_located( (By.CLASS_NAME, 'chip')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) # Choose place type shared.wait_for_loading(self.driver) element_present = EC.text_to_be_present_in_element( (By.ID, 'place-selector-place-type'), "County") WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) selects = Select( self.driver.find_element_by_id('place-selector-place-type')) selects.select_by_value('County') # Choose stat var shared.wait_for_loading(self.driver) shared.click_sv_group(self.driver, "Demographics") element_present = EC.presence_of_element_located( (By.ID, 'Median_Age_Persondc/g/Demographics-Median_Age_Person')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) self.driver.find_element_by_id( 'Median_Age_Persondc/g/Demographics-Median_Age_Person').click() # Choose another stat var shared.wait_for_loading(self.driver) shared.click_sv_group(self.driver, "Demographics") element_present = EC.presence_of_element_located( (By.ID, 'Count_Persondc/g/Demographics-Count_Person')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) self.driver.find_element_by_id( 'Count_Persondc/g/Demographics-Count_Person').click() # Click preview shared.wait_for_loading(self.driver) self.driver.find_element_by_xpath( '//*[@id="plot-container"]/div[1]/div/div/button').click() # Assert preview table is correct shared.wait_for_loading(self.driver) element_present = EC.presence_of_element_located( (By.XPATH, '//*[@id="preview-section"]/table')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) # Assert table headers are correct table_headers = self.driver.find_elements_by_tag_name('th') for idx, header in enumerate(table_headers): self.assertEqual(header.text, TABLE_HEADERS[idx]) # Assert table body is correct table_body = self.driver.find_elements_by_tag_name('tbody')[0] table_rows = table_body.find_elements_by_tag_name('tr') self.assertGreater(len(table_rows), 1) first_row_cells = table_rows[0].find_elements_by_tag_name('td') for idx, cell in enumerate(first_row_cells): self.assertEqual(cell.text, TABLE_ROW_1[idx]) # Click download self.driver.find_element_by_xpath( '//*[@id="preview-section"]/button').click() shared.wait_for_loading(self.driver) # Assert file downloaded downloaded_files = os.listdir(self.downloads_folder.name) self.assertEqual(downloaded_files[0], "California_County.csv")
def test_place_search_box_and_remove_place(self): """Test the timeline tool place search can work correctly.""" # Load Timeline Tool page with Statistical Variables. self.driver.get(self.url_ + TIMELINE_URL + STATVAR_URL_1) # Wait until search box is present. element_present = EC.presence_of_element_located((By.ID, 'ac')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) search_box_input = self.driver.find_element_by_id('ac') # Type California into the search box. search_box_input.send_keys(PLACE_SEARCH_CA) # Wait until there is at least one result in autocomplete results. element_present = EC.presence_of_element_located( (By.CLASS_NAME, 'pac-item')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) # Click on the first result. first_result = self.driver.find_element_by_css_selector( ".pac-item:nth-child(1)") first_result.click() # Type USA into the search box. search_box_input.clear() search_box_input.send_keys(PLACE_SEARCH_USA) # Wait until there is at least one result in autocomplete results. element_present = EC.presence_of_element_located( (By.CLASS_NAME, 'pac-item')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) # Click on the first result. first_result = self.driver.find_element_by_css_selector( ".pac-item:nth-child(1)") first_result.click() # Wait until the second line element within the card is present. element_present = EC.presence_of_element_located( (By.CSS_SELECTOR, '.line:nth-child(2)')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) # Store a list of all the charts and lines. charts = self.driver.find_elements_by_xpath( '//*[@id="chart-region"]/div') lines = charts[0].find_elements_by_class_name("line") # Assert number of charts and lines is correct. self.assertEqual(len(charts), 1) self.assertEqual(len(lines), 2) # Wait until the delete button is present. element_present = EC.presence_of_element_located( (By.XPATH, '//*[@id="place-list"]/div[1]/button')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) # Click on the delete button and remove California. delete_button = self.driver.find_element_by_xpath( '//*[@id="place-list"]/div[1]/button') delete_button.click() # Wait until the second line element within the card disappears. shared.wait_for_loading(self.driver) element_present = EC.invisibility_of_element_located( (By.CSS_SELECTOR, '.line:nth-child(2)')) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(element_present) # Store a list of all the charts and lines. charts = self.driver.find_elements_by_xpath( '//*[@id="chart-region"]/div') lines = charts[0].find_elements_by_class_name("line") # Assert number of charts and lines is correct. self.assertEqual(len(charts), 1) self.assertEqual(len(lines), 1)