From ee3b4a2a081557f510674df489ac7479e31f5e82 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Wed, 1 Mar 2017 17:43:38 +0530 Subject: Fix selenium tests: - Fix addition of answer to codemirror using selenium - Add custom exception when selenium fails - Add id to logout button on student interface - Fix imports for Python3 support in load_test.py --- yaksh/live_server_tests/load_test.py | 34 +++++++++++++++++--------------- yaksh/live_server_tests/selenium_test.py | 16 ++++++++++----- yaksh/templates/user.html | 2 +- yaksh/templates/yaksh/question.html | 15 +++++++------- 4 files changed, 38 insertions(+), 29 deletions(-) (limited to 'yaksh') diff --git a/yaksh/live_server_tests/load_test.py b/yaksh/live_server_tests/load_test.py index 17934d4..21c25ba 100644 --- a/yaksh/live_server_tests/load_test.py +++ b/yaksh/live_server_tests/load_test.py @@ -9,11 +9,11 @@ from selenium.webdriver.firefox.webdriver import WebDriver from django.contrib.staticfiles.testing import StaticLiveServerTestCase from yaksh.models import User, Profile, Question, Quiz, Course, QuestionPaper, TestCase -from selenium_test import SeleniumTest - from yaksh.code_server import ServerPool from yaksh import settings +from .selenium_test import SeleniumTest + class YakshSeleniumTests(StaticLiveServerTestCase): @classmethod @@ -26,44 +26,46 @@ class YakshSeleniumTests(StaticLiveServerTestCase): "yaksh.cpp_code_evaluator.CppCodeEvaluator" settings.code_evaluators['bash']['standardtestcase'] = \ "yaksh.bash_code_evaluator.BashCodeEvaluator" - settings.SERVER_POOL_PORT = 53578 code_server_pool = ServerPool(ports=settings.SERVER_PORTS, pool_port=settings.SERVER_POOL_PORT) cls.code_server_pool = code_server_pool cls.code_server_thread = t = Thread(target=code_server_pool.run) t.start() - demo_student = User.objects.create_user(username='demo_student', + cls.demo_student = User.objects.create_user(username='demo_student', password='demo_student', email='demo_student@test.com' ) - demo_student_profile = Profile.objects.create(user=demo_student, + cls.demo_student_profile = Profile.objects.create(user=cls.demo_student, roll_number=3, institute='IIT', department='Chemical', position='Student' ) - demo_mod = User.objects.create_user(username='demo_mod', + cls.demo_mod = User.objects.create_user(username='demo_mod', password='demo_mod', email='demo_mod@test.com' ) - demo_mod_profile = Profile.objects.create(user=demo_mod, + cls.demo_mod_profile = Profile.objects.create(user=cls.demo_mod, roll_number=0, institute='IIT', department='Chemical', position='Moderator' ) course_obj = Course() - course_obj.create_demo(demo_mod) - demo_course = Course.objects.get(id=1) + course_obj.create_demo(cls.demo_mod) + cls.demo_course = Course.objects.get(id=1) - demo_course.students.add(demo_student) + cls.demo_course.students.add(cls.demo_student) @classmethod def tearDownClass(cls): - User.objects.all().delete() - Question.objects.all().delete() - Quiz.objects.all().delete() - Course.objects.all().delete() - - settings.SERVER_POOL_PORT = 53579 + # User.objects.all().delete() + # Question.objects.all().delete() + # Quiz.objects.all().delete() + # Course.objects.all().delete() + cls.demo_student.delete() + cls.demo_student_profile.delete() + cls.demo_mod.delete() + cls.demo_mod_profile.delete() + cls.demo_course.delete() cls.code_server_pool.stop() cls.code_server_thread.join() diff --git a/yaksh/live_server_tests/selenium_test.py b/yaksh/live_server_tests/selenium_test.py index 7eeb22c..e6908e7 100644 --- a/yaksh/live_server_tests/selenium_test.py +++ b/yaksh/live_server_tests/selenium_test.py @@ -8,6 +8,9 @@ from selenium.common.exceptions import WebDriverException import multiprocessing import argparse +class SeleniumTestError(Exception): + pass + class SeleniumTest(): def __init__(self, url, quiz_name): self.driver = webdriver.Firefox() @@ -24,9 +27,12 @@ class SeleniumTest(): self.logout() self.driver.close() except Exception as e: - with open("/tmp/yaksh_load_test_log.txt", "ab") as f: - f.write('Username: {0}\nError: {1}\n'.format(username, e)) self.driver.close() + msg = ("An Error occurred while running the Selenium load" + " test on Yaksh!" + "Error:\n ".format(e)) + + raise SeleniumTestError() def login(self, username, password): # get the username, password and submit form elements @@ -44,7 +50,7 @@ class SeleniumTest(): for count in range(loop_count): self.driver.find_element_by_link_text(question_label).click() submit_answer_elem = self.driver.find_element_by_id("check") - self.driver.execute_script('editor.setValue({})'.format(answer)) + self.driver.execute_script('global_editor.editor.setValue({});'.format(answer)) submit_answer_elem.click() def test_c_question(self, question_label): @@ -105,9 +111,9 @@ class SeleniumTest(): ) start_exam_elem.click() - self.test_c_question(question_label=1) + self.test_c_question(question_label=2) self.test_python_question(question_label=3) - self.test_bash_question(question_label=2) + self.test_bash_question(question_label=1) def close_quiz(self): quit_link_elem = WebDriverWait(self.driver, 5).until( diff --git a/yaksh/templates/user.html b/yaksh/templates/user.html index 1707305..0d1f980 100644 --- a/yaksh/templates/user.html +++ b/yaksh/templates/user.html @@ -16,7 +16,7 @@ diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html index 6218b18..1f6e67d 100644 --- a/yaksh/templates/yaksh/question.html +++ b/yaksh/templates/yaksh/question.html @@ -89,7 +89,10 @@ function call_skip(url) } -- cgit From 76e3a9575cc1211509a2986970aa299eeaae6c6c Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 2 Mar 2017 19:21:14 +0530 Subject: Remove commented code --- yaksh/live_server_tests/load_test.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'yaksh') diff --git a/yaksh/live_server_tests/load_test.py b/yaksh/live_server_tests/load_test.py index 21c25ba..47d267c 100644 --- a/yaksh/live_server_tests/load_test.py +++ b/yaksh/live_server_tests/load_test.py @@ -57,10 +57,6 @@ class YakshSeleniumTests(StaticLiveServerTestCase): @classmethod def tearDownClass(cls): - # User.objects.all().delete() - # Question.objects.all().delete() - # Quiz.objects.all().delete() - # Course.objects.all().delete() cls.demo_student.delete() cls.demo_student_profile.delete() cls.demo_mod.delete() -- cgit From ea58f85532a6a5cc42780d90c907cfb6e8a6d95d Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Fri, 3 Mar 2017 10:43:39 +0530 Subject: Add message argument to SeleniumTestError --- yaksh/live_server_tests/selenium_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh') diff --git a/yaksh/live_server_tests/selenium_test.py b/yaksh/live_server_tests/selenium_test.py index e6908e7..d91f3ec 100644 --- a/yaksh/live_server_tests/selenium_test.py +++ b/yaksh/live_server_tests/selenium_test.py @@ -32,7 +32,7 @@ class SeleniumTest(): " test on Yaksh!" "Error:\n ".format(e)) - raise SeleniumTestError() + raise SeleniumTestError(msg) def login(self, username, password): # get the username, password and submit form elements -- cgit