Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 72c08bb

Browse files
committed
Fix: Duplicate ID
Add: Smart waits Port: To pytest
1 parent 4f9369c commit 72c08bb

4 files changed

Lines changed: 70 additions & 76 deletions

File tree

runestone/showeval/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<h2>ShowEval</h2>
22

33
```html
4-
<div data-childcomponent="showeval" class="runestone explainer alert alert-warning">
4+
<div data-component="showeval" class="runestone explainer alert alert-warning">
55
<button class="btn btn-success" id="showEval_0_nextStep">Forward</button>
66
<button class="btn btn-default" id ="showEval_0_reset">Reset</button>
77
<div class="evalCont" style="background-color: #FDFDFD;"> <br /></div>

runestone/showeval/js/showEval.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import "../css/showEval.css";
1414

1515
var seList = [];
1616

17-
export class ShowEval {
17+
export class ShowEval extends RunestoneBase {
1818
constructor(opts) {
19+
super(opts);
1920
this.divid = opts.orig.id;
20-
this.container = $(`#${this.divid}`);
21-
this.container.addClass("showEval");
21+
this.containerDiv = opts.orig;
22+
this.containerDiv.classList.add("showEval");
2223
let steps = [];
2324
for (let s of opts.raw) {
2425
steps.push(s.replace(/\\/g, ""));
@@ -29,7 +30,7 @@ export class ShowEval {
2930
this.rb = new RunestoneBase(opts);
3031
// create elements
3132
this.currentStepDiv = $("<div>").addClass("currentStepDiv");
32-
this.container.append(this.currentStepDiv);
33+
$(this.containerDiv).append(this.currentStepDiv);
3334
this.currentStepDiv.append($("<span>").addClass("pre"));
3435
this.currentStepDiv.append($("<span>").addClass("eval"));
3536
this.currentStepDiv.append($("<span>").addClass("post"));
@@ -66,10 +67,9 @@ export class ShowEval {
6667
this.steps[i].push(comment); // 'anno'
6768
}
6869
this.reset();
69-
this.rb.caption = "ShowEval";
70-
this.rb.containerDiv = this.container[0].parentElement;
71-
this.rb.divid = this.container[0].id;
72-
this.rb.addCaption("runestone");
70+
this.caption = "ShowEval";
71+
this.addCaption("runestone");
72+
this.indicate_component_ready();
7373
}
7474

7575
setNextButton(nextButtonSelector) {
@@ -87,12 +87,12 @@ export class ShowEval {
8787
}
8888

8989
reset() {
90-
this.container.find(".previousStep").remove();
90+
$(this.containerDiv).find(".previousStep").remove();
9191
this.setStep(0);
9292
this.rb.logBookEvent({
9393
event: "showeval",
9494
act: "reset",
95-
div_id: this.container[0].id,
95+
div_id: this.containerDiv.id,
9696
});
9797
}
9898

@@ -197,7 +197,7 @@ export class ShowEval {
197197
this.rb.logBookEvent({
198198
event: "showeval",
199199
act: "next",
200-
div_id: this.container[0].id,
200+
div_id: this.containerDiv.id,
201201
});
202202
}
203203
}
@@ -207,7 +207,7 @@ export class ShowEval {
207207
== execute our code on them ==
208208
=================================*/
209209
$(document).bind("runestone:login-complete", function () {
210-
$("[data-childcomponent=showeval]").each(function (index) {
210+
$("[data-component=showeval]").each(function (index) {
211211
// MC
212212
var opts = {
213213
orig: this,

runestone/showeval/showeval.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ def depart_showeval_node(self, node):
5050

5151

5252
CODE = """
53-
<div data-childcomponent="showeval" data-question_label="%(question_label)s" class="%(divclass)s" id="%(divid)s" data-tracemode="%(trace_mode)s" %(optional)s>
53+
<div data-component="showeval" data-question_label="%(question_label)s" class="%(divclass)s" id="%(divid)s" data-tracemode="%(trace_mode)s" %(optional)s>
5454
<button class="btn btn-success" id="%(divid)s_nextStep">Next Step</button>
5555
<button class="btn btn-default" id ="%(divid)s_reset">Reset</button>
5656
<div class="evalCont" style="background-color: #FDFDFD;">%(preReqLines)s</div>
57-
<div class="evalCont" id="%(divid)s"></div>
57+
<div class="evalCont"></div>
5858
<script>
5959
if (typeof window.raw_steps === "undefined") {
6060
window.raw_steps = {};
Lines changed: 55 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,77 @@
11
import time
2-
from runestone.unittest_base import module_fixture_maker, RunestoneTestCase
3-
from selenium.webdriver.support import expected_conditions as EC
4-
from selenium.webdriver.support.ui import WebDriverWait
5-
from selenium.webdriver.common.by import By
2+
import pytest
63

74
__author__ = "wayne brown"
85

9-
mf, setUpModule, tearDownModule = module_fixture_maker(__file__, True)
106

7+
@pytest.fixture
8+
def selenium_utils_1(selenium_utils):
9+
selenium_utils.get("trace.html")
10+
selenium_utils.wait_until_ready("showEval_3")
11+
return selenium_utils
1112

12-
class ShowEvalTest_TraceMode(RunestoneTestCase):
13-
def setUp(self):
14-
super(ShowEvalTest_TraceMode, self).setUp()
15-
print(vars(self))
16-
self.driver.get(self.host + "/trace.html")
17-
wait = WebDriverWait(self.driver, 10)
18-
try:
19-
wait.until(EC.presence_of_element_located((By.TAG_NAME, "body")))
20-
except:
21-
text = self.driver.page_source
22-
print(text[:300])
2313

24-
def test_Next_Step(self):
25-
driver = self.driver
26-
self.assertIn("ShowEval", driver.title)
27-
evalDiv = driver.find_element_by_id("showEval_3")
14+
def test_Next_Step_1(selenium_utils_1):
15+
driver = selenium_utils_1.driver
16+
assert "ShowEval" in driver.title
17+
evalDiv = driver.find_element_by_id("showEval_3")
2818

29-
prevList = driver.find_elements_by_class_name("previousStep")
30-
prevListLen = len(prevList)
31-
assert prevListLen == 0
32-
assert len(evalDiv.find_elements_by_tag_name("span")) == 3
19+
prevList = driver.find_elements_by_class_name("previousStep")
20+
prevListLen = len(prevList)
21+
assert prevListLen == 0
22+
assert len(evalDiv.find_elements_by_tag_name("span")) == 4
3323

24+
driver.find_element_by_id("showEval_3_nextStep").click()
25+
time.sleep(3)
26+
assert len(evalDiv.find_elements_by_tag_name("span")) == 4
27+
assert len(driver.find_elements_by_class_name("previousStep")) > prevListLen
28+
29+
30+
def test_Reset_Step_1(selenium_utils_1):
31+
driver = selenium_utils_1.driver
32+
assert "ShowEval" in driver.title
33+
evalDiv = driver.find_element_by_id("showEval_3")
34+
35+
for i in range(3):
3436
driver.find_element_by_id("showEval_3_nextStep").click()
3537
time.sleep(3)
36-
assert len(evalDiv.find_elements_by_tag_name("span")) == 3
37-
assert len(driver.find_elements_by_class_name("previousStep")) > prevListLen
3838

39-
def test_Reset_Step(self):
40-
driver = self.driver
41-
self.assertIn("ShowEval", driver.title)
42-
evalDiv = driver.find_element_by_id("showEval_3")
39+
assert len(evalDiv.find_elements_by_class_name("previousStep")) > 0
40+
driver.find_element_by_id("showEval_3_reset").click()
41+
assert len(evalDiv.find_elements_by_class_name("previousStep")) == 0
4342

44-
for i in range(3):
45-
driver.find_element_by_id("showEval_3_nextStep").click()
46-
time.sleep(3)
4743

48-
assert len(evalDiv.find_elements_by_class_name("previousStep")) > 0
49-
driver.find_element_by_id("showEval_3_reset").click()
50-
assert len(evalDiv.find_elements_by_class_name("previousStep")) == 0
44+
@pytest.fixture
45+
def selenium_utils_2(selenium_utils):
46+
selenium_utils.get("replace.html")
47+
selenium_utils.wait_until_ready("showEval_2")
48+
return selenium_utils
5149

5250

53-
class ShowEvalTest_ReplaceMode(RunestoneTestCase):
54-
def setUp(self):
55-
super(ShowEvalTest_ReplaceMode, self).setUp()
56-
self.driver.get(self.host + "/replace.html")
51+
def test_Next_Step_2(selenium_utils_2):
52+
driver = selenium_utils_2.driver
53+
assert "ShowEval" in driver.title
54+
evalDiv = driver.find_element_by_id("showEval_2")
5755

58-
def test_Next_Step(self):
59-
driver = self.driver
60-
self.assertIn("ShowEval", driver.title)
61-
evalDiv = driver.find_element_by_id("showEval_2")
56+
assert len(evalDiv.find_elements_by_tag_name("span")) == 4
57+
evalText = driver.find_element_by_class_name("eval").text
58+
assert evalText != ""
6259

63-
assert len(evalDiv.find_elements_by_tag_name("span")) == 3
64-
evalText = driver.find_element_by_class_name("eval").text
65-
assert evalText != ""
60+
driver.find_element_by_id("showEval_2_nextStep").click()
61+
time.sleep(3)
62+
assert len(evalDiv.find_elements_by_tag_name("span")) == 4
63+
assert driver.find_element_by_class_name("eval").text != evalText
6664

67-
driver.find_element_by_id("showEval_2_nextStep").click()
68-
time.sleep(3)
69-
assert len(evalDiv.find_elements_by_tag_name("span")) == 3
70-
assert driver.find_element_by_class_name("eval").text != evalText
7165

72-
def test_Reset_Step(self):
73-
driver = self.driver
74-
self.assertIn("ShowEval", driver.title)
75-
evalText1 = driver.find_element_by_class_name("eval").text
66+
def test_Reset_Step_2(selenium_utils_2):
67+
driver = selenium_utils_2.driver
68+
assert "ShowEval" in driver.title
69+
evalText1 = driver.find_element_by_class_name("eval").text
7670

77-
for i in range(4):
78-
driver.find_element_by_id("showEval_2_nextStep").click()
79-
time.sleep(3)
71+
for i in range(4):
72+
driver.find_element_by_id("showEval_2_nextStep").click()
73+
time.sleep(3)
8074

81-
assert driver.find_element_by_class_name("eval").text != evalText1
82-
driver.find_element_by_id("showEval_2_reset").click()
83-
assert driver.find_element_by_class_name("eval").text == evalText1
75+
assert driver.find_element_by_class_name("eval").text != evalText1
76+
driver.find_element_by_id("showEval_2_reset").click()
77+
assert driver.find_element_by_class_name("eval").text == evalText1

0 commit comments

Comments
 (0)