Skip to content

Commit cdeee59

Browse files
committed
Fixing test_keyword_arguments_waiting.py for pytest
1 parent e337c77 commit cdeee59

File tree

2 files changed

+39
-28
lines changed

2 files changed

+39
-28
lines changed
Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
1-
import unittest
2-
1+
import pytest
32
from mockito import mock, unstub, when
43

54
from SeleniumLibrary.keywords import WaitingKeywords
65

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)
739

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)

utest/test/keywords/test_waiting_stale_element_refereance_exception.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def _raise(*a):
1414

1515
@pytest.fixture(scope='module')
1616
def waiting():
17+
ctx = mock()
18+
ctx.timeout = TIMEOUT
1719
return WaitingKeywords(mock())
1820

1921

0 commit comments

Comments
 (0)