summaryrefslogtreecommitdiff
path: root/yaksh/live_server_tests
diff options
context:
space:
mode:
authorPrabhu Ramachandran2018-01-02 18:07:39 +0530
committerGitHub2018-01-02 18:07:39 +0530
commite566d54239efcb46f253e324b7295a676378f656 (patch)
tree3a93f3305c8b72dc2052ca33837b9b3dadb5d7af /yaksh/live_server_tests
parent29a06f7372690796a05262fac6c428580e1f3155 (diff)
parent9bfdc506c3a54835ba9a1cd1fb70e9c2f825f0fb (diff)
downloadonline_test-e566d54239efcb46f253e324b7295a676378f656.tar.gz
online_test-e566d54239efcb46f253e324b7295a676378f656.tar.bz2
online_test-e566d54239efcb46f253e324b7295a676378f656.zip
Merge pull request #401 from FOSSEE/yaksh_video_lessons
Yaksh Learning Module
Diffstat (limited to 'yaksh/live_server_tests')
-rw-r--r--yaksh/live_server_tests/load_test.py41
-rw-r--r--yaksh/live_server_tests/selenium_test.py51
2 files changed, 57 insertions, 35 deletions
diff --git a/yaksh/live_server_tests/load_test.py b/yaksh/live_server_tests/load_test.py
index 5ab1cc2..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,5 +70,11 @@ class YakshSeleniumTests(StaticLiveServerTestCase):
def test_load(self):
url = '%s%s' % (self.live_server_url, '/exam/login/')
quiz_name = "Yaksh Demo quiz"
- selenium_test = SeleniumTest(url=url, quiz_name=quiz_name)
- selenium_test.run_load_test(url=url, username='demo_student', password='demo_student')
+ module_name = "Demo Module"
+ course_name = "Yaksh Demo course"
+ selenium_test = SeleniumTest(url=url, quiz_name=quiz_name,
+ 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 31efcac..5635add 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,17 +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):
+ 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):
@@ -44,8 +45,8 @@ class SeleniumTest():
except Exception as e:
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)
@@ -53,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)
@@ -65,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']")))
@@ -119,9 +122,13 @@ class SeleniumTest():
self.submit_answer(question_label, answer, loop_count)
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"))
@@ -155,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/"
@@ -165,15 +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"
- selenium_test = SeleniumTest(url=opts.url, quiz_name=quiz_name)
+ module_name = "Demo Module"
+ course_name = "Yaksh Demo course"
+ selenium_test = SeleniumTest(url=opts.url, quiz_name=quiz_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()
-