|
2 | 2 | Test Short Answer question directive |
3 | 3 | """ |
4 | 4 |
|
5 | | -import pytest |
6 | | - |
7 | 5 | __author__ = "yasinovskyy" |
8 | 6 |
|
9 | 7 | DIV_ID = "test_short_answer_1" |
10 | 8 |
|
11 | 9 |
|
12 | | -@pytest.fixture |
13 | | -def selenium_utils_1(selenium_utils): |
14 | | - selenium_utils.get("index.html") |
| 10 | +def get_sa(selenium_utils): |
15 | 11 | selenium_utils.wait_until_ready(DIV_ID) |
16 | | - return selenium_utils |
| 12 | + # See the notes in ``test_activecode.click_run`` on the need for this call. |
| 13 | + selenium_utils.driver.execute_script("window.scrollTo(0, 0);") |
| 14 | + return selenium_utils.driver.find_element_by_id(DIV_ID) |
17 | 15 |
|
18 | 16 |
|
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) |
| 17 | +def click_button(sa_element): |
| 18 | + sa_element.find_element_by_tag_name("button").click() |
| 19 | + |
23 | 20 |
|
| 21 | +def test_sa1(selenium_utils_get): |
| 22 | + """No input. Button not clicked""" |
| 23 | + t1 = get_sa(selenium_utils_get) |
24 | 24 | fb = t1.find_element_by_id(f"{DIV_ID}_feedback") |
25 | 25 | assert "alert-danger" in fb.get_attribute("class") |
26 | 26 |
|
27 | 27 |
|
28 | | -def test_sa2(selenium_utils_1): |
| 28 | +def test_sa2(selenium_utils_get): |
29 | 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 | | - |
| 30 | + t1 = get_sa(selenium_utils_get) |
| 31 | + click_button(t1) |
35 | 32 | fb = t1.find_element_by_id(f"{DIV_ID}_feedback") |
36 | 33 | assert "alert-success" in fb.get_attribute("class") |
37 | 34 |
|
38 | 35 |
|
39 | | -def test_sa3(selenium_utils_1): |
| 36 | +def test_sa3(selenium_utils_get): |
40 | 37 | """Answer entered""" |
41 | | - t1 = selenium_utils_1.driver.find_element_by_id(DIV_ID) |
| 38 | + t1 = get_sa(selenium_utils_get) |
42 | 39 | ta = t1.find_element_by_id(f"{DIV_ID}_solution") |
43 | 40 | ta.clear() |
44 | 41 | ta.send_keys("My answer") |
45 | 42 |
|
46 | | - btn_check = t1.find_element_by_tag_name("button") |
47 | | - btn_check.click() |
| 43 | + click_button(t1) |
48 | 44 |
|
49 | 45 | fb = t1.find_element_by_id(f"{DIV_ID}_feedback") |
50 | 46 | assert fb is not None |
51 | 47 | assert "alert-success" in fb.get_attribute("class") |
52 | 48 |
|
53 | 49 |
|
54 | 50 | # TODO: this is the same as ``_test_sa3``. |
55 | | -def test_sa4(selenium_utils_1): |
| 51 | +def test_sa4(selenium_utils_get): |
56 | 52 | """Answer entered and cleared""" |
57 | | - t1 = selenium_utils_1.driver.find_element_by_id(DIV_ID) |
| 53 | + t1 = get_sa(selenium_utils_get) |
58 | 54 | ta = t1.find_element_by_id(f"{DIV_ID}_solution") |
59 | 55 | ta.clear() |
60 | 56 | ta.send_keys("My answer") |
61 | 57 |
|
62 | | - btn_check = t1.find_element_by_tag_name("button") |
63 | | - btn_check.click() |
| 58 | + click_button(t1) |
64 | 59 |
|
65 | 60 | fb = t1.find_element_by_id(f"{DIV_ID}_feedback") |
66 | 61 | assert fb is not None |
|
0 commit comments