summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authorprathamesh2017-08-22 14:58:50 +0530
committerprathamesh2017-08-23 11:59:45 +0530
commit055d0d1c51f90b4496a096a13bab5e4978fe9b92 (patch)
treebb57de0a5c2d7f8013189a58adba7d14ac977e19 /yaksh
parent4af405d525a5fdf6dfbcdb386a43e01d6393202e (diff)
downloadonline_test-055d0d1c51f90b4496a096a13bab5e4978fe9b92.tar.gz
online_test-055d0d1c51f90b4496a096a13bab5e4978fe9b92.tar.bz2
online_test-055d0d1c51f90b4496a096a13bab5e4978fe9b92.zip
Added custom expected condition class
To check if the ontop div display is none. If so then the selenium will proceed ahead else wait for the div property to change. Currently I have not specified the actual exception in try except, will add later Modified JS to handle ontop div
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/live_server_tests/selenium_test.py22
-rw-r--r--yaksh/static/yaksh/js/requesthandler.js19
2 files changed, 38 insertions, 3 deletions
diff --git a/yaksh/live_server_tests/selenium_test.py b/yaksh/live_server_tests/selenium_test.py
index 00e1847..859d032 100644
--- a/yaksh/live_server_tests/selenium_test.py
+++ b/yaksh/live_server_tests/selenium_test.py
@@ -7,7 +7,23 @@ from selenium.common.exceptions import WebDriverException
import multiprocessing
import argparse
-import time
+
+
+class ElementDisplay(object):
+ '''Custom expected condition '''
+ def __init__(self, locator):
+ self.locator = locator
+
+ def __call__(self, driver):
+ try:
+ element = EC._find_element(driver, self.locator)
+ a = element.value_of_css_property("display") == "none"
+ print(a)
+ return a
+ except Exception as e:
+ print(e)
+ return False
+
class SeleniumTestError(Exception):
pass
@@ -49,11 +65,13 @@ class SeleniumTest():
def submit_answer(self, question_label, answer, loop_count=1):
self.driver.implicitly_wait(2)
for count in range(loop_count):
- time.sleep(15)
+ print("in")
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))
submit_answer_elem.click()
+ WebDriverWait(self.driver, 90).until(ElementDisplay(
+ (By.XPATH, "//*[@id='ontop']")))
def test_c_question(self, question_label):
# Incorrect Answer
diff --git a/yaksh/static/yaksh/js/requesthandler.js b/yaksh/static/yaksh/js/requesthandler.js
index f653da1..c5629ab 100644
--- a/yaksh/static/yaksh/js/requesthandler.js
+++ b/yaksh/static/yaksh/js/requesthandler.js
@@ -1,22 +1,25 @@
request_status = "initial"
count = 0;
+checker = null
function submitRequest(){
document.forms["code"].submit();
}
function check_state(state, uid) {
- if ((state == "running" || state == "not started") && count < 15) {
+ if ((state == "running" || state == "not started") && count < 7) {
count++;
setTimeout(function() {get_result(uid);}, 2000);
} else if (state == "unknown") {
request_status = "initial";
count = 0;
notify("You are requesting for a wrong data");
+ clearInterval(checker);
unlock_screen();
} else {
request_status = "initial";
count = 0;
notify("Please try after few minutes");
+ clearInterval(checker);
unlock_screen();
}
}
@@ -36,6 +39,13 @@ function unlock_screen() {
document.getElementById("ontop").style.display = "none";
}
+function check_lock_screen() {
+ var $ontop_div = document.getElementById("ontop");
+ if ($ontop_div.style.display == "block") {
+ $ontop_div.style.display = "none";
+ }
+}
+
function get_result(uid){
$.ajax({
method: "GET",
@@ -44,6 +54,7 @@ function get_result(uid){
success: function(data, status, xhr) {
content_type = xhr.getResponseHeader("content-type");
if(content_type.includes("text/html")) {
+ clearInterval(checker);
unlock_screen();
document.open();
document.write(data);
@@ -55,12 +66,14 @@ function get_result(uid){
} else {
request_status = "initial";
count = 0;
+ clearInterval(checker);
unlock_screen();
}
},
error: function(xhr, text_status, error_thrown ) {
request_status = "initial";
count = 0;
+ clearInterval(checker);
unlock_screen();
notify("There is some problem. Try later.")
}
@@ -103,6 +116,7 @@ $(document).ready(function(){
global_editor.editor.clearHistory();
}
$('#code').submit(function(e) {
+ checker = setInterval(check_lock_screen, 30000);
lock_screen();
$.ajax({
type: 'POST',
@@ -114,6 +128,7 @@ $(document).ready(function(){
if(content_type.includes("text/html")) {
request_status = "initial"
count = 0;
+ clearInterval(checker);
unlock_screen();
document.open();
document.write(data);
@@ -126,12 +141,14 @@ $(document).ready(function(){
} else {
request_status = "initial";
count = 0;
+ clearInterval(checker);
unlock_screen();
}
},
error: function(xhr, text_status, error_thrown ) {
request_status = "initial";
count = 0;
+ clearInterval(checker);
unlock_screen();
notify("There is some problem. Try later.")
}