From ed5a904f16ce702d9532029b91bfd55a01627602 Mon Sep 17 00:00:00 2001 From: Drikus Roor Date: Tue, 28 May 2024 14:16:31 +0200 Subject: [PATCH] fix: Add agree_to_consent method for handling informed consent in e2e tests and adapt to new order of informed conset & explainer in eurovision experiment --- e2e/tests-selenium.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/e2e/tests-selenium.py b/e2e/tests-selenium.py index c878d7e39..7eb5882fa 100644 --- a/e2e/tests-selenium.py +++ b/e2e/tests-selenium.py @@ -194,6 +194,9 @@ 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!"]'))) \ @@ -201,18 +204,6 @@ def test_eurovision(self): 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 @@ -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.")