Skip to content

Commit

Permalink
fix: Add agree_to_consent method for handling informed consent in e2e…
Browse files Browse the repository at this point in the history
… tests and adapt to new order of informed conset & explainer in eurovision experiment
  • Loading branch information
drikusroor committed May 28, 2024
1 parent 2a41043 commit ed5a904
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions e2e/tests-selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,25 +194,16 @@ def test_eurovision(self):
# if page body contains the word "Error", raise an exception
self.check_for_error(experiment_name, experiment_slug)

# Check & Agree to Informed Consent
self.agree_to_consent()

# Explainer
WebDriverWait(self.driver, 5, poll_frequency=1) \
.until(expected_conditions.element_to_be_clickable((By.XPATH, '//button[text()="Let\'s go!"]'))) \
.click()

print("Let's go! button clicked")

# If consent present, agree
informed_consent_heading = self.driver.find_element(By.TAG_NAME,"h4").text.lower() == "informed consent"

if not informed_consent_heading:
raise Exception("Informed consent not found")

WebDriverWait(self.driver, 5, poll_frequency=1) \
.until(expected_conditions.element_to_be_clickable((By.XPATH, '//button[text()="I agree"]'))) \
.click()

print("I agree button clicked")

h4_text = None
bonus_rounds = False

Expand Down Expand Up @@ -439,6 +430,19 @@ def test_categorization(self):
except Exception as e:
self.handle_error(e, experiment_name)

def agree_to_consent(self, h4_text='informed consent', button_text='I agree'):
# If consent present, agree
informed_consent_heading = self.driver.find_element(By.TAG_NAME,"h4").text.lower() == h4_text.lower()

if not informed_consent_heading:
raise Exception("Informed consent not found")

WebDriverWait(self.driver, 5, poll_frequency=1) \
.until(expected_conditions.element_to_be_clickable((By.XPATH, f'//button[text()="{button_text}"]'))) \
.click()

print("I agree button clicked")

def check_for_error(self, experiment_name, experiment_slug='[no slug provided]'):
if "Error" in self.driver.find_element(By.TAG_NAME, "body").text:
raise Exception(f"Could not load {experiment_name} experiment, please check the server logs and make sure the slug ({experiment_slug}) is correct.")
Expand Down

0 comments on commit ed5a904

Please sign in to comment.