Skip to content

Commit

Permalink
Update website sanity to adapt to the new homepage. (#4611)
Browse files Browse the repository at this point in the history
  • Loading branch information
keyurva authored Sep 11, 2024
1 parent 7adc768 commit b62150b
Showing 1 changed file with 40 additions and 16 deletions.
56 changes: 40 additions & 16 deletions server/webdriver/tests/standalone/sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from enum import StrEnum
import logging
import os
import time

from absl import app
from absl import flags
Expand Down Expand Up @@ -140,46 +141,69 @@ def home(self, page: WebPage):

page.title = self.driver.title if page.title is None else page.title

# topic cards
topic_cards = find_elems(self.driver, By.CLASS_NAME, "topic-card")
if topic_cards is None or len(topic_cards) == 0:
self.add_result(fail_result(page, start, "No topic cards."))
# Wait 1 second for the page to load.
time.sleep(1)

# topic items
topic_items = find_elems(self.driver, By.CLASS_NAME, "topic-item")
if topic_items is None or len(topic_items) == 0:
self.add_result(fail_result(page, start, "No topic items."))
return

explore_landing_pages = []
for topic_card in topic_cards:
topic_title_elem = find_elem(topic_card, By.CLASS_NAME,
"topic-card-title")
if topic_title_elem is None:
for topic_item in topic_items:
topic_url_elem = find_elem(topic_item, By.TAG_NAME, "a")
if topic_url_elem is None:
self.add_result(
fail_result(
page,
start,
"No explore landing title on one of the cards.",
"No explore landing URL on one of the topic items.",
))
return

topic_url_elem = find_elem(topic_card, By.TAG_NAME, "a")
if topic_url_elem is None:
explore_landing_pages.append(
WebPage(
PageType.EXPLORE_LANDING,
topic_url_elem.text,
topic_url_elem.get_attribute("href"),
source_url=page.url,
))

# question items
question_items = find_elems(self.driver, By.CLASS_NAME, "question-item")
if question_items is None or len(question_items) == 0:
self.add_result(fail_result(page, start, "No question items."))
return

explore_pages = []
for question_item in question_items:
question_url_elem = find_elem(question_item, By.TAG_NAME, "a")
if question_url_elem is None:
self.add_result(
fail_result(
page,
start,
"No explore landing URL on one of the cards.",
"No explore URL on one of the question items.",
))
return
question_text_elem = find_elem(question_url_elem, By.TAG_NAME, "p")
question_text = question_text_elem.text if question_text_elem else question_url_elem.text

explore_landing_pages.append(
explore_pages.append(
WebPage(
PageType.EXPLORE_LANDING,
topic_title_elem.text,
topic_url_elem.get_attribute("href"),
PageType.EXPLORE,
question_text,
question_url_elem.get_attribute("href"),
source_url=page.url,
))

# Pass
self.add_result(pass_result(page, start))

for explore_page in explore_pages:
self.explore(explore_page)

for explore_landing_page in explore_landing_pages:
self.explore_landing(explore_landing_page)

Expand Down

0 comments on commit b62150b

Please sign in to comment.