Skip to content

Commit

Permalink
Fix custom DC tests (NL goldens, shared tests) (#4737)
Browse files Browse the repository at this point in the history
- In one file, don't reference h1 by a selector only present in main DC
- In another file, add some CSS selectors specifically for tests to use
- Add option to run_cdc_tests for regenerating goldens

To prevent failures from recurring, we should make custom DC tests run
before merge instead of just after autopush.
  • Loading branch information
hqpho authored Nov 18, 2024
1 parent c7dc534 commit 3899039
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 25 deletions.
5 changes: 5 additions & 0 deletions run_cdc_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
}
],
"denom": "Count_Person",
"description": "Gender wage gap.",
"title": "Gender Wage Gap in Countries of Europe"
}
],
Expand Down
4 changes: 2 additions & 2 deletions server/templates/custom_dc/custom/browser_landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

{% block content %}
<div class="container">
<h1 class="mb-4">Knowledge Graph</h1>
<p>
<h1 id="kg-title"class="mb-4">Knowledge Graph</h1>
<p id="kg-desc">
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
Expand Down
20 changes: 10 additions & 10 deletions server/webdriver/shared_tests/browser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 2 additions & 4 deletions server/webdriver/shared_tests/ranking_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 3 additions & 6 deletions server/webdriver/tests/homepage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions static/js/apps/browser_landing/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export function App(): ReactElement {
<>
<IntroText>
<header>
<h1>Knowledge Graph</h1>
<p>
<h1 id="kg-title">Knowledge Graph</h1>
<p id="kg-desc">
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
Expand Down

0 comments on commit 3899039

Please sign in to comment.