From 0c56df4f33d90ee65eec4d79d51ac5fc803c7c7e Mon Sep 17 00:00:00 2001 From: Hannah Pho Date: Thu, 14 Nov 2024 16:57:31 -0500 Subject: [PATCH] Fix custom DC tests (NL goldens, shared tests) - Add some CSS selectors specifically for tests to use - Run all webdriver tests with `-n auto` to maybe speed them up - Add option to run_cdc_tests for regenerating goldens --- run_cdc_tests.sh | 5 +++++ .../test_data/cdc_nl/chart_config.json | 1 - .../custom_dc/custom/browser_landing.html | 4 ++-- server/webdriver/shared_tests/browser_test.py | 20 +++++++++---------- server/webdriver/shared_tests/ranking_test.py | 6 ++---- server/webdriver/tests/homepage_test.py | 9 +++------ static/js/apps/browser_landing/app.tsx | 4 ++-- 7 files changed, 24 insertions(+), 25 deletions(-) diff --git a/run_cdc_tests.sh b/run_cdc_tests.sh index 22bf9c83be..aeb59cbf52 100755 --- a/run_cdc_tests.sh +++ b/run_cdc_tests.sh @@ -20,4 +20,9 @@ set -e source .env/bin/activate export FLASK_ENV=webdriver +# Like run_test.sh, use flag -g for updating goldens. +if [[ "$1" == "-g" ]]; then + export TEST_MODE=write +fi + python3 -m pytest -n 5 --reruns 2 server/webdriver/cdc_tests/ diff --git a/server/integration_tests/test_data/cdc_nl/chart_config.json b/server/integration_tests/test_data/cdc_nl/chart_config.json index 1db1631f67..baeecad893 100644 --- a/server/integration_tests/test_data/cdc_nl/chart_config.json +++ b/server/integration_tests/test_data/cdc_nl/chart_config.json @@ -34,7 +34,6 @@ } ], "denom": "Count_Person", - "description": "Gender wage gap.", "title": "Gender Wage Gap in Countries of Europe" } ], diff --git a/server/templates/custom_dc/custom/browser_landing.html b/server/templates/custom_dc/custom/browser_landing.html index bf4ce6face..d2504865f9 100644 --- a/server/templates/custom_dc/custom/browser_landing.html +++ b/server/templates/custom_dc/custom/browser_landing.html @@ -26,8 +26,8 @@ {% block content %}
-

Knowledge Graph

-

+

Knowledge Graph

+

The Data Commons Knowledge Graph is constructed by synthesizing a single database from many different data sources. This knowledge graph can be used both to explore what data is available and diff --git a/server/webdriver/shared_tests/browser_test.py b/server/webdriver/shared_tests/browser_test.py index 5f766c4c00..a789b481a3 100644 --- a/server/webdriver/shared_tests/browser_test.py +++ b/server/webdriver/shared_tests/browser_test.py @@ -44,21 +44,21 @@ def test_page_landing(self): self.assertIn(title_text, self.driver.title) # Wait for title to be present - h1_locator = (By.CSS_SELECTOR, '#intro-text h1') + title_locator = (By.CSS_SELECTOR, '#kg-title') WebDriverWait(self.driver, self.TIMEOUT_SEC).until( - EC.text_to_be_present_in_element(h1_locator, 'Knowledge Graph')) - h1_element = self.driver.find_element(*h1_locator) - self.assertEqual("Knowledge Graph", h1_element.text) + EC.text_to_be_present_in_element(title_locator, 'Knowledge Graph')) + title_element = self.driver.find_element(*title_locator) + self.assertEqual("Knowledge Graph", title_element.text) # Assert intro is correct - intro_locator = (By.CSS_SELECTOR, '#intro-text .container header p') + description_locator = (By.CSS_SELECTOR, '#kg-desc') WebDriverWait(self.driver, self.TIMEOUT_SEC).until( - EC.presence_of_element_located(intro_locator)) - intro_element = self.driver.find_element(*intro_locator) - expected_intro_start = 'The Data Commons Knowledge Graph is constructed' + EC.presence_of_element_located(description_locator)) + description_element = self.driver.find_element(*description_locator) + expected_description_start = 'The Data Commons Knowledge Graph is constructed' self.assertTrue( - intro_element.text.startswith(expected_intro_start), - f"Intro text does not start with expected text. Found: {intro_element.text}" + description_element.text.startswith(expected_description_start), + f"Intro text does not start with expected text. Found: {description_element.text}" ) def test_page_serve_ca_population(self): diff --git a/server/webdriver/shared_tests/ranking_test.py b/server/webdriver/shared_tests/ranking_test.py index deae7c5d76..3b13fe5c21 100644 --- a/server/webdriver/shared_tests/ranking_test.py +++ b/server/webdriver/shared_tests/ranking_test.py @@ -61,8 +61,7 @@ def test_energy_consumption_bottom_ranking_hi(self): ) title_present = EC.text_to_be_present_in_element( - (By.CSS_SELECTOR, '#main-navbar-container .navbar-brand'), - self.dc_title_string) + (By.CSS_SELECTOR, '.navbar-brand'), self.dc_title_string) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(title_present) subtitle_present = EC.text_to_be_present_in_element( @@ -109,8 +108,7 @@ def test_energy_consumption_top_ranking_ko(self): ) title_present = EC.text_to_be_present_in_element( - (By.CSS_SELECTOR, '#main-navbar-container .navbar-brand'), - self.dc_title_string) + (By.CSS_SELECTOR, '.navbar-brand'), self.dc_title_string) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(title_present) subtitle_present = EC.text_to_be_present_in_element( diff --git a/server/webdriver/tests/homepage_test.py b/server/webdriver/tests/homepage_test.py index 3f7b8bda0e..53a3b469ec 100644 --- a/server/webdriver/tests/homepage_test.py +++ b/server/webdriver/tests/homepage_test.py @@ -29,8 +29,7 @@ def test_homepage_en_by_css(self): self.driver.get(self.url_ + '/') title_present = EC.text_to_be_present_in_element( - (By.CSS_SELECTOR, '#main-navbar-container .navbar-brand'), - self.dc_title_string) + (By.CSS_SELECTOR, '.navbar-brand'), self.dc_title_string) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(title_present) hero_msg = self.driver.find_elements(By.ID, 'hero')[0] @@ -44,8 +43,7 @@ def test_homepage_it(self): self.driver.get(self.url_ + '/?hl=it') title_present = EC.text_to_be_present_in_element( - (By.CSS_SELECTOR, '#main-navbar-container .navbar-brand'), - self.dc_title_string) + (By.CSS_SELECTOR, '.navbar-brand'), self.dc_title_string) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(title_present) hero_msg = self.driver.find_elements(By.ID, 'hero')[0] @@ -101,8 +99,7 @@ def test_homepage_autocomplete(self): self.driver.get(self.url_ + '/?ac_on=true') title_present = EC.text_to_be_present_in_element( - (By.CSS_SELECTOR, '#main-navbar-container .navbar-brand'), - self.dc_title_string) + (By.CSS_SELECTOR, '.navbar-brand'), self.dc_title_string) WebDriverWait(self.driver, self.TIMEOUT_SEC).until(title_present) search_box_input = self.driver.find_element(By.ID, 'query-search-input') diff --git a/static/js/apps/browser_landing/app.tsx b/static/js/apps/browser_landing/app.tsx index 6908890e48..28a11a1580 100644 --- a/static/js/apps/browser_landing/app.tsx +++ b/static/js/apps/browser_landing/app.tsx @@ -35,8 +35,8 @@ export function App(): ReactElement { <>

-

Knowledge Graph

-

+

Knowledge Graph

+

The Data Commons Knowledge Graph is constructed by synthesizing a single database from many different data sources. This knowledge graph can be used both to explore what data is available and to