diff options
Diffstat (limited to 'yaksh/live_server_tests')
-rw-r--r-- | yaksh/live_server_tests/load_test.py | 41 | ||||
-rw-r--r-- | yaksh/live_server_tests/selenium_test.py | 50 |
2 files changed, 53 insertions, 38 deletions
diff --git a/yaksh/live_server_tests/load_test.py b/yaksh/live_server_tests/load_test.py index c3eb6e6..520bebe 100644 --- a/yaksh/live_server_tests/load_test.py +++ b/yaksh/live_server_tests/load_test.py @@ -1,17 +1,10 @@ -import os -import signal -import subprocess -from datetime import datetime -import pytz from threading import Thread -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 +# Local imports +from yaksh.models import User, Profile, Course from yaksh.code_server import ServerPool from yaksh import settings - from .selenium_test import SeleniumTest @@ -33,20 +26,24 @@ class YakshSeleniumTests(StaticLiveServerTestCase): cls.code_server_thread = t = Thread(target=code_server_pool.run) t.start() - cls.demo_student = User.objects.create_user(username='demo_student', - password='demo_student', - email='demo_student@test.com' + cls.demo_student = User.objects.create_user( + username='demo_student', + password='demo_student', + email='demo_student@test.com' ) - cls.demo_student_profile = Profile.objects.create(user=cls.demo_student, + cls.demo_student_profile = Profile.objects.create( + user=cls.demo_student, roll_number=3, institute='IIT', department='Chemical', position='Student' ) - cls.demo_mod = User.objects.create_user(username='demo_mod', - password='demo_mod', - email='demo_mod@test.com' + cls.demo_mod = User.objects.create_user( + username='demo_mod', + password='demo_mod', + email='demo_mod@test.com' ) - cls.demo_mod_profile = Profile.objects.create(user=cls.demo_mod, + cls.demo_mod_profile = Profile.objects.create( + user=cls.demo_mod, roll_number=0, institute='IIT', department='Chemical', position='Moderator' ) @@ -73,7 +70,11 @@ class YakshSeleniumTests(StaticLiveServerTestCase): def test_load(self): url = '%s%s' % (self.live_server_url, '/exam/login/') quiz_name = "Yaksh Demo quiz" - module_name = "demo module" + module_name = "Demo Module" + course_name = "Yaksh Demo course" selenium_test = SeleniumTest(url=url, quiz_name=quiz_name, - module_name=module_name) - selenium_test.run_load_test(url=url, username='demo_student', password='demo_student') + module_name=module_name, + course_name=course_name) + selenium_test.run_load_test( + url=url, username='demo_student', password='demo_student' + ) diff --git a/yaksh/live_server_tests/selenium_test.py b/yaksh/live_server_tests/selenium_test.py index 160ad02..0d9e8b8 100644 --- a/yaksh/live_server_tests/selenium_test.py +++ b/yaksh/live_server_tests/selenium_test.py @@ -1,9 +1,7 @@ from selenium import webdriver -from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC -from selenium.common.exceptions import WebDriverException import multiprocessing import argparse @@ -18,18 +16,20 @@ class ElementDisplay(object): try: element = EC._find_element(driver, self.locator) return element.value_of_css_property("display") == "none" - except Exception as e: + except Exception: return False class SeleniumTestError(Exception): pass + class SeleniumTest(): - def __init__(self, url, quiz_name, module_name): + def __init__(self, url, quiz_name, module_name, course_name): self.driver = webdriver.Firefox() self.quiz_name = quiz_name self.module_name = module_name + self.course_name = course_name self.url = url def run_load_test(self, url, username, password): @@ -43,10 +43,10 @@ class SeleniumTest(): self.logout() self.driver.close() except Exception as e: - self.driver.close() + # self.driver.close() msg = ("An Error occurred while running the Selenium load" - " test on Yaksh!\n" - "Error:\n{0}".format(e)) + " test on Yaksh!\n" + "Error:\n{0}".format(e)) raise SeleniumTestError(msg) @@ -54,7 +54,8 @@ class SeleniumTest(): # get the username, password and submit form elements username_elem = self.driver.find_element_by_id("id_username") password_elem = self.driver.find_element_by_id("id_password") - submit_login_elem = self.driver.find_element_by_css_selector('button.btn') + submit_login_elem = self.driver.find_element_by_css_selector( + 'button.btn') # Type in the username, password and submit form username_elem.send_keys(username) @@ -66,7 +67,8 @@ 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('global_editor.editor.setValue({});'.format(answer)) + self.driver.execute_script( + 'global_editor.editor.setValue({});'.format(answer)) submit_answer_elem.click() WebDriverWait(self.driver, 90).until(ElementDisplay( (By.XPATH, "//*[@id='ontop']"))) @@ -121,10 +123,12 @@ class SeleniumTest(): def open_quiz(self): # open module link + self.driver.find_elements_by_partial_link_text( + self.course_name)[0].click() self.driver.find_element_by_link_text(self.module_name).click() # open quiz link - quiz_link_elem = self.driver.find_element_by_link_text(self.quiz_name).click() - + self.driver.find_element_by_link_text(self.quiz_name).click() + # Get page elements start_exam_elem = WebDriverWait(self.driver, 5).until( EC.presence_of_element_located((By.NAME, "start")) @@ -158,8 +162,10 @@ class SeleniumTest(): ) logout_link_elem.click() + def user_gen(url, ids): - return [(url, 'User%d'%x, 'User%d'%x) for x in ids] + return [(url, 'User%d' % x, 'User%d' % x) for x in ids] + def wrap_run_load_test(args): url = "http://yaksh.fossee.aero.iitb.ac.in/exam/" @@ -168,17 +174,25 @@ def wrap_run_load_test(args): if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('url', type=str, help="url of the website being tested") + parser.add_argument( + 'url', type=str, help="url of the website being tested" + ) parser.add_argument('start', type=int, help="Starting user id") - parser.add_argument("-n", "--number", type=int, default=10, help="number of users") + parser.add_argument( + "-n", "--number", type=int, default=10, help="number of users" + ) opts = parser.parse_args() quiz_name = "Demo quiz" - module_name = "demo module" + module_name = "Demo Module" + course_name = "Yaksh Demo course" selenium_test = SeleniumTest(url=opts.url, quiz_name=quiz_name, - module_name=module_name) + module_name=module_name, + course_name=course_name) pool = multiprocessing.Pool(opts.number) - pool.map(wrap_run_load_test, user_gen(opts.url, range(opts.start, opts.start + opts.number))) + pool.map( + wrap_run_load_test, + user_gen(opts.url, range(opts.start, opts.start + opts.number)) + ) pool.close() pool.join() - |