Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/SeleniumLibrary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
TableElementKeywords,
WaitingKeywords,
WindowKeywords)
from SeleniumLibrary.locators import ElementFinder, TableElementFinder
from SeleniumLibrary.locators import ElementFinder
from SeleniumLibrary.utils import (Deprecated, LibraryListener, timestr_to_secs,
WebDriverCache)

Expand Down Expand Up @@ -347,7 +347,6 @@ def __init__(self, timeout=5.0, implicit_wait=0.0,
DynamicCore.__init__(self, libraries)
self.ROBOT_LIBRARY_LISTENER = LibraryListener()
self._element_finder = ElementFinder(self)
self._table_element_finder = TableElementFinder(self)

_speed_in_secs = Deprecated('_speed_in_secs', 'speed')
_timeout_in_secs = Deprecated('_timeout_in_secs', 'timeout')
Expand Down
4 changes: 0 additions & 4 deletions src/SeleniumLibrary/base/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ def drivers(self):
def element_finder(self):
return self.ctx._element_finder

@property
def table_element_finder(self):
return self.ctx._table_element_finder

def find_element(self, locator, tag=None, required=True, parent=None):
"""Find element matching `locator`.

Expand Down
49 changes: 44 additions & 5 deletions src/SeleniumLibrary/keywords/tableelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def table_column_should_contain(self, locator, column, expected, loglevel='INFO'
See `Page Should Contain Element` for explanation about the
``loglevel`` argument.
"""
element = self.table_element_finder.find_by_column(locator, column, expected)
element = self._find_by_column(locator, column, expected)
if element is None:
self.ctx.log_source(loglevel)
raise AssertionError("Table '%s' column %s did not contain text "
Expand All @@ -128,7 +128,7 @@ def table_footer_should_contain(self, locator, expected, loglevel='INFO'):
See `Page Should Contain Element` for explanation about the
``loglevel`` argument.
"""
element = self.table_element_finder.find_by_footer(locator, expected)
element = self._find_by_footer(locator, expected)
if element is None:
self.ctx.log_source(loglevel)
raise AssertionError("Table '%s' footer did not contain text "
Expand All @@ -147,7 +147,7 @@ def table_header_should_contain(self, locator, expected, loglevel='INFO'):
See `Page Should Contain Element` for explanation about the
``loglevel`` argument.
"""
element = self.table_element_finder.find_by_header(locator, expected)
element = self._find_by_header(locator, expected)
if element is None:
self.ctx.log_source(loglevel)
raise AssertionError("Table '%s' header did not contain text "
Expand All @@ -171,7 +171,7 @@ def table_row_should_contain(self, locator, row, expected, loglevel='INFO'):
See `Page Should Contain Element` for explanation about the
``loglevel`` argument.
"""
element = self.table_element_finder.find_by_row(locator, row, expected)
element = self._find_by_row(locator, row, expected)
if element is None:
self.ctx.log_source(loglevel)
raise AssertionError("Table '%s' row %s did not contain text "
Expand All @@ -187,8 +187,47 @@ def table_should_contain(self, locator, expected, loglevel='INFO'):
See `Page Should Contain Element` for explanation about the
``loglevel`` argument.
"""
element = self.table_element_finder.find_by_content(locator, expected)
element = self._find_by_content(locator, expected)
if element is None:
self.ctx.log_source(loglevel)
raise AssertionError("Table '%s' did not contain text '%s'."
% (locator, expected))

def _find_by_content(self, table_locator, content):
return self._find(table_locator, '//*', content)

def _find_by_header(self, table_locator, content):
return self._find(table_locator, '//th', content)

def _find_by_footer(self, table_locator, content):
return self._find(table_locator, '//tfoot//td', content)

def _find_by_row(self, table_locator, row, content):
position = self._index_to_position(row)
locator = '//tr[{}]'.format(position)
return self._find(table_locator, locator, content)

def _find_by_column(self, table_locator, col, content):
position = self._index_to_position(col)
locator = '//tr//*[self::td or self::th][{}]'.format(position)
return self._find(table_locator, locator, content)

def _index_to_position(self, index):
index = int(index)
if index == 0:
raise ValueError('Row and column indexes must be non-zero.')
if index > 0:
return str(index)
if index == -1:
return 'position()=last()'
return 'position()=last()-{}'.format(abs(index) - 1)

def _find(self, table_locator, locator, content):
table = self.find_element(table_locator)
elements = self.find_elements(locator, parent=table)
for element in elements:
if content is None:
return element
if element.text and content in element.text:
return element
return None
1 change: 0 additions & 1 deletion src/SeleniumLibrary/locators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@

from .customlocator import CustomLocator
from .elementfinder import ElementFinder
from .tableelementfinder import TableElementFinder
from .windowmanager import WindowManager
59 changes: 0 additions & 59 deletions src/SeleniumLibrary/locators/tableelementfinder.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@

from mockito import mock, when, unstub

from SeleniumLibrary.locators.tableelementfinder import TableElementFinder
from SeleniumLibrary.keywords import TableElementKeywords


class ElementFinderTest(unittest.TestCase):
class TableKeywordsTest(unittest.TestCase):

def setUp(self):
self.ctx = mock()
self.ctx._element_finder = mock()
self.finder = TableElementFinder(self.ctx)
self.finder = TableElementKeywords(self.ctx)

def tearDown(self):
unstub()

def test_find_by_column(self):
xpath = '//tr//*[self::td or self::th][1]'
when(self.finder)._find('id:table', xpath, 'content').thenReturn(mock())
self.finder.find_by_column('id:table', 1, 'content')
self.finder._find_by_column('id:table', 1, 'content')

def test_find_by_column_with_negative_index(self):
xpath = '//tr//*[self::td or self::th][position()=last()]'
when(self.finder)._find('id:table', xpath, 'content').thenReturn(mock())
self.finder.find_by_column('id:table', -1, 'content')
self.finder._find_by_column('id:table', -1, 'content')

def test_find_by_row(self):
xpath = '//tr[2]'
when(self.finder)._find('xpath=//table', xpath, 'content').thenReturn(mock())
self.finder.find_by_row('xpath=//table', 2, 'content')
self.finder._find_by_row('xpath=//table', 2, 'content')

def test_find_by_row_with_negative_index(self):
xpath = '//tr[position()=last()-2]'
when(self.finder)._find('xpath=//table', xpath, 'content').thenReturn(mock())
self.finder.find_by_row('xpath=//table', -3, 'content')
self.finder._find_by_row('xpath=//table', -3, 'content')