summaryrefslogtreecommitdiff
path: root/yaksh/live_server_tests/selenium_test.py
diff options
context:
space:
mode:
authoradityacp2017-12-14 12:04:38 +0530
committeradityacp2017-12-14 12:04:38 +0530
commitbe6d0f480d2b48cf6b6dbe80afae29c17dbf1bd1 (patch)
tree12f6ef2df77494d57a55571001c154c232b6c710 /yaksh/live_server_tests/selenium_test.py
parent209dd65b0bf97bdac883881c4d96b7670cd902a2 (diff)
downloadonline_test-be6d0f480d2b48cf6b6dbe80afae29c17dbf1bd1.tar.gz
online_test-be6d0f480d2b48cf6b6dbe80afae29c17dbf1bd1.tar.bz2
online_test-be6d0f480d2b48cf6b6dbe80afae29c17dbf1bd1.zip
Change test files
- Add new views test - Fix Selenium tests
Diffstat (limited to 'yaksh/live_server_tests/selenium_test.py')
-rw-r--r--yaksh/live_server_tests/selenium_test.py50
1 files changed, 32 insertions, 18 deletions
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()
-