Skip to content

Commit 9c23ba0

Browse files
committed
Fixing test_keyword_arguments_element.py to use pytest
1 parent a232cc5 commit 9c23ba0

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed
Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,43 @@
11
import unittest
22

3+
import pytest
34
from mockito import mock, unstub, when
45

56
from SeleniumLibrary.keywords import ElementKeywords
67

78

8-
class KeywordArgumentsElementTest(unittest.TestCase):
9+
@pytest.fixture(scope='function')
10+
def element():
11+
ctx = mock()
12+
ctx._browser = mock()
13+
return ElementKeywords(ctx)
914

10-
def setUp(self):
11-
ctx = mock()
12-
ctx._browser = mock()
13-
self.element = ElementKeywords(ctx)
1415

15-
def tearDown(self):
16-
unstub()
16+
def teardown_function():
17+
unstub()
1718

18-
def test_locator_should_match_x_times(self):
19-
locator = '//div'
20-
when(self.element).find_elements(locator).thenReturn([])
21-
with self.assertRaisesRegexp(AssertionError, 'should have matched'):
22-
self.element.locator_should_match_x_times(locator, 1)
2319

24-
with self.assertRaisesRegexp(AssertionError, 'foobar'):
25-
self.element.locator_should_match_x_times(locator, 1, 'foobar')
20+
def test_locator_should_match_x_times(element):
21+
locator = '//div'
22+
when(element).find_elements(locator).thenReturn([])
23+
with pytest.raises(AssertionError) as error:
24+
element.locator_should_match_x_times(locator, 1)
25+
assert 'should have matched' in str(error.value)
2626

27-
def test_element_text_should_be(self):
28-
locator = '//div'
29-
element = mock()
30-
element.text = 'text'
31-
when(self.element).find_element(locator).thenReturn(element)
32-
with self.assertRaisesRegexp(AssertionError, 'should have been'):
33-
self.element.element_text_should_be(locator, 'not text')
34-
with self.assertRaisesRegexp(AssertionError, 'foobar'):
35-
self.element.element_text_should_be(locator, 'not text', 'foobar')
27+
with pytest.raises(AssertionError) as error:
28+
element.locator_should_match_x_times(locator, 1, 'foobar')
29+
assert 'foobar' in str(error.value)
30+
31+
32+
def test_element_text_should_be(element):
33+
locator = '//div'
34+
webelement = mock()
35+
webelement.text = 'text'
36+
when(element).find_element(locator).thenReturn(webelement)
37+
with pytest.raises(AssertionError) as error:
38+
element.element_text_should_be(locator, 'not text')
39+
assert 'should have been' in str(error.value)
40+
41+
with pytest.raises(AssertionError) as error:
42+
element.element_text_should_be(locator, 'not text', 'foobar')
43+
assert 'foobar' in str(error.value)

0 commit comments

Comments
 (0)