|
1 |
| -import unittest |
2 |
| - |
| 1 | +import pytest |
3 | 2 | from mockito import mock, unstub, when
|
4 | 3 |
|
5 | 4 | from SeleniumLibrary.keywords import WaitingKeywords
|
6 | 5 |
|
| 6 | +TIMEOUT = 0.01 |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture(scope='module') |
| 10 | +def waiting(): |
| 11 | + ctx = mock() |
| 12 | + ctx.driver = mock() |
| 13 | + ctx.timeout = TIMEOUT |
| 14 | + return WaitingKeywords(ctx) |
| 15 | + |
| 16 | + |
| 17 | +def teardown_module(): |
| 18 | + unstub() |
| 19 | + |
| 20 | + |
| 21 | +def test_wait_for_condition(waiting): |
| 22 | + condition = 'return document.getElementById("intro")' |
| 23 | + error = 'did not become true' |
| 24 | + with pytest.raises(AssertionError) as error: |
| 25 | + waiting.wait_for_condition(condition) |
| 26 | + assert 'did not become true' in str(error.value) |
| 27 | + |
| 28 | + with pytest.raises(AssertionError) as error: |
| 29 | + waiting.wait_for_condition(condition, 'None', 'foobar') |
| 30 | + assert 'foobar' in str(error.value) |
| 31 | + |
| 32 | + |
| 33 | +def test_wait_until_page_contains(waiting): |
| 34 | + text = 'text' |
| 35 | + when(waiting).is_text_present(text).thenReturn(None) |
| 36 | + with pytest.raises(AssertionError) as error: |
| 37 | + waiting.wait_until_page_contains(text) |
| 38 | + assert "Text 'text' did not" in str(error.value) |
7 | 39 |
|
8 |
| -class KeywordArgumentsWaitingKeywordsTest(unittest.TestCase): |
9 |
| - |
10 |
| - def setUp(self): |
11 |
| - self.ctx = mock() |
12 |
| - self.ctx.driver = mock() |
13 |
| - self.ctx.timeout = 0.01 |
14 |
| - self.waiting = WaitingKeywords(self.ctx) |
15 |
| - |
16 |
| - def tearDown(self): |
17 |
| - unstub() |
18 |
| - |
19 |
| - def test_wait_for_condition(self): |
20 |
| - condition = 'return document.getElementById("intro")' |
21 |
| - error = 'did not become true' |
22 |
| - with self.assertRaisesRegexp(AssertionError, error): |
23 |
| - self.waiting.wait_for_condition(condition) |
24 |
| - with self.assertRaisesRegexp(AssertionError, 'foobar'): |
25 |
| - self.waiting.wait_for_condition(condition, 'None', 'foobar') |
26 |
| - |
27 |
| - def test_wait_until_page_contains(self): |
28 |
| - text = 'text' |
29 |
| - when(self.waiting).is_text_present(text).thenReturn(None) |
30 |
| - with self.assertRaisesRegexp(AssertionError, "Text 'text' did not"): |
31 |
| - self.waiting.wait_until_page_contains(text) |
32 |
| - with self.assertRaisesRegexp(AssertionError, "error"): |
33 |
| - self.waiting.wait_until_page_contains(text, 'None', 'error') |
| 40 | + with pytest.raises(AssertionError) as error: |
| 41 | + waiting.wait_until_page_contains(text, 'None', 'error') |
| 42 | + assert 'error' in str(error.value) |
0 commit comments