Skip to content

Commit

Permalink
[qacode] added support for multiples tbodies #248
Browse files Browse the repository at this point in the history
  • Loading branch information
netzulo committed Jul 15, 2019
1 parent 1831624 commit 12c0c34
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added
- New '__repr__' method for class 'StrictRule' #287
- Now 'ControlTable' support multiples tbodies #248

### Changed
- Internal vars at controls packages moved to pythonic properties #287
Expand Down
3 changes: 2 additions & 1 deletion qacode/configs/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
{ "name": "dd_menu_data", "selector": "#ddData"},
{ "name": "dd_menu_data_lists", "selector": "a[href='/qacode/data/lists']"},
{ "name": "tbl_ok", "selector": "#tblOk"},
{ "name": "tbl_html5_ok", "selector": "#tblHtml5Ok"}
{ "name": "tbl_html5_ok", "selector": "#tblHtml5Ok"},
{ "name": "tbl_html_tbodies_ok", "selector": "#tblHtml5OkTbodies"}
]
},
{ "name": "qacode_inputs",
Expand Down
1 change: 0 additions & 1 deletion qacode/core/loggers/logger_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,3 @@
CT_BADTAG = "ctl_tb | Can't use this for not <table> tag element" # noqa:E501
CT_LOADED = "ctl_tb | ctl.table property for <table>" # noqa:E501
CT_TBLNOTCHILD = "ctl_tb | this table haven't got '{}' selector" # noqa:E501
CT_TBL2ORMORETBODIES = "2 or more tbodys not supported, Open an issue on Github" # noqa:E501
7 changes: 3 additions & 4 deletions qacode/core/webs/controls/control_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,12 @@ def __load_table_html5__(self):
self._caption = self.__try__("find_child", "caption")
self._thead = self.__try__("find_child", "thead")
self._tfoot = self.__try__("find_child", "tfoot")
if len(self._tbodies) > 1:
raise ControlException(MSG.CT_TBL2ORMORETBODIES)
rows = []
if self._thead is not None:
rows.append(self.__get_row__(self._thead.find_child("tr"), "th"))
for ctl_row in self._tbodies[0].find_children("tr"):
rows.append(self.__get_row__(ctl_row, "td"))
for tbody in self._tbodies:
for ctl_row in tbody.find_children("tr"):
rows.append(self.__get_row__(ctl_row, "td"))
return rows

def __get_row__(self, ctl_row, selector):
Expand Down
36 changes: 19 additions & 17 deletions tests/001_functionals/suite_008_controltable.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def setup_class(cls, **kwargs):
'dd_menu_data_lists', cls.cfg_control('dd_menu_data_lists'))
cls.add_property('tbl_ok', cls.cfg_control('tbl_ok'))
cls.add_property('tbl_html5_ok', cls.cfg_control('tbl_html5_ok'))
cls.add_property(
'tbl_html_tbodies_ok', cls.cfg_control('tbl_html_tbodies_ok'))

def setup_method(self, test_method):
"""Configure self.attribute"""
Expand Down Expand Up @@ -93,17 +95,23 @@ def setup_login_to_data(self):
@pytest.mark.parametrize("auto_reload", [True, False])
@pytest.mark.parametrize("rules", [
[{"tag": "table", "type": "tag", "severity": "hight"}]])
@pytest.mark.parametrize("ctl_name", ['tbl_ok', 'tbl_html5_ok'])
@pytest.mark.parametrize(
"ctl_name,rows,cols", [
('tbl_ok', 3, 2),
('tbl_html5_ok', 4, 3),
('tbl_html_tbodies_ok', 4, 3)
])
def test_controltable_instance(self, on_instance_search,
rules, auto_reload, ctl_name):
rules, auto_reload, ctl_name, rows, cols):
"""Testcase: test_controltable_instance"""
cfg = getattr(self, ctl_name).copy()
cfg.update({
"instance": "ControlTable",
"on_instance_search": on_instance_search,
"auto_reload": auto_reload,
"rules": rules
})
if ctl_name == "tbl_html_tbodies_ok" and not on_instance_search:
import pdb; pdb.set_trace()
# functional testcases
ctl = ControlTable(self.bot, **cfg)
self.assert_is_instance(ctl, ControlTable)
Expand All @@ -124,21 +132,15 @@ def test_controltable_instance(self, on_instance_search,
self.assert_is_instance(ctl.table, ControlBase)
self.assert_is_instance(ctl.rows, list)
# Use case 1. not html5:: TABLE > (TR > TH)+(TR > TD)
if ctl_name == 'tbl_ok':
self.assert_lower(len(ctl.rows), 3)
for row in ctl.rows:
self.assert_is_instance(row, list)
self.assert_lower(len(row), 2)
for cell in row:
self.assert_is_instance(cell, ControlBase)
# Use case 2. html5:: TABLE > (THEAD > (TR > TH))+(TBODY > (TR > TH))
if ctl_name == 'tbl_html5_ok':
self.assert_lower(len(ctl.rows), 4)
for row in ctl.rows:
self.assert_is_instance(row, list)
self.assert_lower(len(row), 3)
for cell in row:
self.assert_is_instance(cell, ControlBase)
# Use case 3. html5:: TABLE >
# (THEAD > (TR > TH))+[(TBODY > (TR > TH))]
self.assert_lower(len(ctl.rows), rows)
for row in ctl.rows:
self.assert_is_instance(row, list)
self.assert_lower(len(row), cols)
for cell in row:
self.assert_is_instance(cell, ControlBase)

@pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG)
@pytest.mark.parametrize("strict_rules", [None])
Expand Down

0 comments on commit 12c0c34

Please sign in to comment.