|
1 | 1 | import unittest
|
2 | 2 |
|
| 3 | +import pytest |
3 | 4 | from mockito import mock, unstub, when
|
4 | 5 |
|
5 | 6 | from SeleniumLibrary.keywords import ElementKeywords
|
6 | 7 |
|
7 | 8 |
|
8 |
| -class KeywordArgumentsElementTest(unittest.TestCase): |
| 9 | +@pytest.fixture(scope='function') |
| 10 | +def element(): |
| 11 | + ctx = mock() |
| 12 | + ctx._browser = mock() |
| 13 | + return ElementKeywords(ctx) |
9 | 14 |
|
10 |
| - def setUp(self): |
11 |
| - ctx = mock() |
12 |
| - ctx._browser = mock() |
13 |
| - self.element = ElementKeywords(ctx) |
14 | 15 |
|
15 |
| - def tearDown(self): |
16 |
| - unstub() |
| 16 | +def teardown_function(): |
| 17 | + unstub() |
17 | 18 |
|
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) |
23 | 19 |
|
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) |
26 | 26 |
|
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