|
2 | 2 | Test Short Answer question directive |
3 | 3 | """ |
4 | 4 |
|
| 5 | +import pytest |
| 6 | + |
5 | 7 | __author__ = "yasinovskyy" |
6 | 8 |
|
7 | | -from time import sleep |
8 | | -from runestone.unittest_base import module_fixture_maker, RunestoneTestCase |
9 | | - |
10 | | -setUpModule, tearDownModule = module_fixture_maker(__file__) |
11 | | - |
12 | | - |
13 | | -class ShortAnswerQuestion_Tests(RunestoneTestCase): |
14 | | - def test_sa1(self): |
15 | | - """No input. Button not clicked""" |
16 | | - self.driver.get(self.host + "/index.html") |
17 | | - t1 = self.driver.find_element_by_id("question1") |
18 | | - |
19 | | - fb = t1.find_element_by_id("question1_feedback") |
20 | | - self.assertIsNotNone(fb) |
21 | | - cnamestr = fb.get_attribute("class") |
22 | | - self.assertIn("alert-danger", cnamestr) |
23 | | - |
24 | | - def test_sa2(self): |
25 | | - """No input. Button clicked""" |
26 | | - self.driver.get(self.host + "/index.html") |
27 | | - sleep(2) |
28 | | - t1 = self.driver.find_element_by_id("question1") |
29 | | - |
30 | | - btn_check = t1.find_element_by_tag_name("button") |
31 | | - btn_check.click() |
32 | | - |
33 | | - fb = t1.find_element_by_id("question1_feedback") |
34 | | - self.assertIsNotNone(fb) |
35 | | - cnamestr = fb.get_attribute("class") |
36 | | - self.assertIn("alert-success", cnamestr) |
37 | | - |
38 | | - def test_sa3(self): |
39 | | - """Answer entered""" |
40 | | - self.driver.get(self.host + "/index.html") |
41 | | - t1 = self.driver.find_element_by_id("question1") |
42 | | - ta = t1.find_element_by_id("question1_solution") |
43 | | - ta.send_keys("My answer") |
44 | | - |
45 | | - btn_check = t1.find_element_by_tag_name("button") |
46 | | - btn_check.click() |
47 | | - |
48 | | - fb = t1.find_element_by_id("question1_feedback") |
49 | | - self.assertIsNotNone(fb) |
50 | | - cnamestr = fb.get_attribute("class") |
51 | | - self.assertIn("alert-success", cnamestr) |
52 | | - |
53 | | - def test_sa4(self): |
54 | | - """Answer entered and cleared""" |
55 | | - self.driver.get(self.host + "/index.html") |
56 | | - t1 = self.driver.find_element_by_id("question1") |
57 | | - ta = t1.find_element_by_id("question1_solution") |
58 | | - ta.send_keys("My answer") |
59 | | - |
60 | | - btn_check = t1.find_element_by_tag_name("button") |
61 | | - btn_check.click() |
62 | | - |
63 | | - fb = t1.find_element_by_id("question1_feedback") |
64 | | - self.assertIsNotNone(fb) |
65 | | - cnamestr = fb.get_attribute("class") |
66 | | - self.assertIn("alert-success", cnamestr) |
| 9 | +DIV_ID = "test_short_answer_1" |
| 10 | + |
| 11 | + |
| 12 | +@pytest.fixture |
| 13 | +def selenium_utils_1(selenium_utils): |
| 14 | + selenium_utils.get("index.html") |
| 15 | + selenium_utils.wait_until_ready(DIV_ID) |
| 16 | + return selenium_utils |
| 17 | + |
| 18 | + |
| 19 | +def test_sa1(selenium_utils_1): |
| 20 | + """No input. Button not clicked""" |
| 21 | + self = selenium_utils_1 |
| 22 | + t1 = self.driver.find_element_by_id(DIV_ID) |
| 23 | + |
| 24 | + fb = t1.find_element_by_id(f"{DIV_ID}_feedback") |
| 25 | + assert "alert-danger" in fb.get_attribute("class") |
| 26 | + |
| 27 | + |
| 28 | +def test_sa2(selenium_utils_1): |
| 29 | + """No input. Button clicked""" |
| 30 | + t1 = selenium_utils_1.driver.find_element_by_id(DIV_ID) |
| 31 | + |
| 32 | + btn_check = t1.find_element_by_tag_name("button") |
| 33 | + btn_check.click() |
| 34 | + |
| 35 | + fb = t1.find_element_by_id(f"{DIV_ID}_feedback") |
| 36 | + assert "alert-success" in fb.get_attribute("class") |
| 37 | + |
| 38 | + |
| 39 | +def test_sa3(selenium_utils_1): |
| 40 | + """Answer entered""" |
| 41 | + t1 = selenium_utils_1.driver.find_element_by_id(DIV_ID) |
| 42 | + ta = t1.find_element_by_id(f"{DIV_ID}_solution") |
| 43 | + ta.clear() |
| 44 | + ta.send_keys("My answer") |
| 45 | + |
| 46 | + btn_check = t1.find_element_by_tag_name("button") |
| 47 | + btn_check.click() |
| 48 | + |
| 49 | + fb = t1.find_element_by_id(f"{DIV_ID}_feedback") |
| 50 | + assert fb is not None |
| 51 | + assert "alert-success" in fb.get_attribute("class") |
| 52 | + |
| 53 | + |
| 54 | +# TODO: this is the same as ``_test_sa3``. |
| 55 | +def test_sa4(selenium_utils_1): |
| 56 | + """Answer entered and cleared""" |
| 57 | + t1 = selenium_utils_1.driver.find_element_by_id(DIV_ID) |
| 58 | + ta = t1.find_element_by_id(f"{DIV_ID}_solution") |
| 59 | + ta.clear() |
| 60 | + ta.send_keys("My answer") |
| 61 | + |
| 62 | + btn_check = t1.find_element_by_tag_name("button") |
| 63 | + btn_check.click() |
| 64 | + |
| 65 | + fb = t1.find_element_by_id(f"{DIV_ID}_feedback") |
| 66 | + assert fb is not None |
| 67 | + assert "alert-success" in fb.get_attribute("class") |
0 commit comments