From 79537e38ff462fc6ea9aabc7db70a6490491b015 Mon Sep 17 00:00:00 2001 From: albertas-jn <24507839+albertas-jn@users.noreply.github.com> Date: Mon, 2 Oct 2023 12:54:33 +0200 Subject: [PATCH 1/3] Categorization: allow multiple sessions in development --- backend/experiment/rules/categorization.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/experiment/rules/categorization.py b/backend/experiment/rules/categorization.py index 5097c0c39..0c7bb496f 100644 --- a/backend/experiment/rules/categorization.py +++ b/backend/experiment/rules/categorization.py @@ -12,6 +12,8 @@ from .base import Base import random +from django.conf import settings + SCORE_AVG_MIN_TRAINING = 0.8 @@ -288,7 +290,7 @@ def plan_experiment(self, session): participant=session.participant) # Check if this participant already has a previous session - if current_sessions.count() > 1: + if current_sessions.count() > 1 and not settings.DEBUG: json_data = 'REPEAT' else: # Check wether a group falls behind in the count From f0c370b00e39e08a110dcf28574fbfb52789b4fc Mon Sep 17 00:00:00 2001 From: albertas-jn <24507839+albertas-jn@users.noreply.github.com> Date: Tue, 3 Oct 2023 14:56:08 +0200 Subject: [PATCH 2/3] Selenium test for categorization experiment --- frontend/src/components/Question/Question.js | 3 + .../src/components/Question/Question.scss | 4 ++ tests/tests-selenium.py | 58 +++++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/frontend/src/components/Question/Question.js b/frontend/src/components/Question/Question.js index 0026b6d4e..2dca2484b 100644 --- a/frontend/src/components/Question/Question.js +++ b/frontend/src/components/Question/Question.js @@ -81,6 +81,9 @@ const Question = ({ )}

{question.question}

{render(question.view)}
+ {question.expected_response && +

{question.expected_response}

+ } ); }; diff --git a/frontend/src/components/Question/Question.scss b/frontend/src/components/Question/Question.scss index 498b85083..7de512f97 100644 --- a/frontend/src/components/Question/Question.scss +++ b/frontend/src/components/Question/Question.scss @@ -42,3 +42,7 @@ } + +.expected-response { + display:none; +} diff --git a/tests/tests-selenium.py b/tests/tests-selenium.py index ee014df9a..5a0f45b49 100644 --- a/tests/tests-selenium.py +++ b/tests/tests-selenium.py @@ -74,6 +74,7 @@ def tearDown(self): self.driver.quit() #warnings.simplefilter("default", ResourceWarning) + def test_beatalignment(self): self.driver.get("{}/{}".format(self.config['url']['root'], self.config['experiment_slugs']['beat_alignment'])) @@ -167,5 +168,62 @@ def test_eurovision(self): self.driver.find_element(By.XPATH, '//*[text()="Play again"]') + def test_categorization(self): + + self.driver.get("{}/{}".format(self.config['url']['root'], self.config['experiment_slugs']['categorization'])) + + # Explainer 1 + self.driver.find_element(By.XPATH, "//div[text()=\"Ok\"]").click() + + # If consent present, agree + if self.driver.find_element(By.TAG_NAME,"h4").text.lower() == "informed consent": + self.driver.find_element(By.XPATH, '//div[text()="I agree"]').click() + + # What is your age? + el = WebDriverWait(self.driver, 3).until(presence_of_element_located((By.CSS_SELECTOR,"input[type='number']"))) + el.send_keys(18) + self.driver.find_element(By.XPATH, '//*[text()="Continue"]').click() + + # What is your gender + self.driver.find_element(By.CSS_SELECTOR, ".radio:nth-child(1)").click() + self.driver.find_element(By.XPATH, '//*[text()="Continue"]').click() + + # What is your native language + select = Select(self.driver.find_element(By.TAG_NAME, 'select')) + select.select_by_value('nl') + self.driver.find_element(By.XPATH, '//*[text()="Continue"]').click() + + # Please select your level of musical experience + self.driver.find_element(By.CSS_SELECTOR, ".radio:nth-child(1)").click() + self.driver.find_element(By.XPATH, '//*[text()="Continue"]').click() + + # Explainer 2 + WebDriverWait(self.driver, 5) \ + .until(presence_of_element_located((By.XPATH, "//div[text()=\"Ok\"]"))) \ + .click() + + training_rounds = 20 + testing_rounds = 80 + training = True + for n in (training_rounds, testing_rounds): + for i in range(n): + + WebDriverWait(self.driver, 5) \ + .until(presence_of_element_located((By.CSS_SELECTOR, ".aha__play-button"))) \ + .click() + + expected_response = self.driver.execute_script('return document.querySelector(".expected-response").textContent') + button_to_click = self.driver.execute_script(f'return document.querySelector(\'input[value="{expected_response}"]\').parentElement') + WebDriverWait(self.driver, 5) \ + .until(lambda x: False if "disabled" in button_to_click.get_attribute("class") else button_to_click) \ + .click() + + if training: + WebDriverWait(self.driver, 5) \ + .until(presence_of_element_located((By.XPATH, "//div[text()=\"Ok\"]"))) \ + .click() + training = False + + if __name__ == '__main__': unittest.main() From cfd00fbab8d7f15735ab96225e0f3c24c5a8abd4 Mon Sep 17 00:00:00 2001 From: albertas-jn <24507839+albertas-jn@users.noreply.github.com> Date: Sat, 7 Oct 2023 15:22:22 +0200 Subject: [PATCH 3/3] Add comment when expected response will be visible, change condition from settings.DEBUG to settings.TESTING --- backend/experiment/rules/categorization.py | 2 +- frontend/src/components/Question/Question.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/experiment/rules/categorization.py b/backend/experiment/rules/categorization.py index 0c7bb496f..1926ab9d5 100644 --- a/backend/experiment/rules/categorization.py +++ b/backend/experiment/rules/categorization.py @@ -290,7 +290,7 @@ def plan_experiment(self, session): participant=session.participant) # Check if this participant already has a previous session - if current_sessions.count() > 1 and not settings.DEBUG: + if current_sessions.count() > 1 and not settings.TESTING: json_data = 'REPEAT' else: # Check wether a group falls behind in the count diff --git a/frontend/src/components/Question/Question.js b/frontend/src/components/Question/Question.js index 2dca2484b..ae48751bd 100644 --- a/frontend/src/components/Question/Question.js +++ b/frontend/src/components/Question/Question.js @@ -82,6 +82,7 @@ const Question = ({

{question.question}

{render(question.view)}
{question.expected_response && + /* Will only be visible when the backend settings has TESTING=True */

{question.expected_response}

}