Skip to content

Commit

Permalink
Issue259 (#260)
Browse files Browse the repository at this point in the history
* [qacode] fix for issue #259

* [qacode] CHANGELOG for issue #259

* [qacode] fix for tox flake8

* [qacode] reordered tox envs at CIs
  • Loading branch information
netzulo committed Apr 10, 2019
1 parent 6e4cc7f commit 6432456
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 97 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ install:
- pip install tox
- python setup.py clean build install sdist
script:
- tox -e "{$TOXENV},flake8"
- tox -e "flake8,{$TOXENV}"
after_success:
- tox -e docs
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Removed
- Deleted ControlGroup + tests #256
- Deleted controls property named 'on_instance_load' #259

## [v0.6.0] - 2019-03-18

Expand Down
4 changes: 1 addition & 3 deletions USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ It's base control to load web element from ``WebDriver + browser session`` , *th
+ Param **locator** : This text it's parsed down selenium class ``selenium.webdriver.common.by.By`` (*default:* ``css selector`` == ``By.CSS_SELECTOR``)
+ Param **instance** : Allow to generate your own inherit classes from ``ControlBase`` and instance them using qacode strategy (*default:* ``ControlBase``)
+ Param **auto_reload** : Allow to reload element searching first when need to use some function of control instance and isn't loaded (*default:* ``True``)
+ Param **on_instance_search** : enable searching element at instance `ControlBase` (*default:* `False`)
+ Param **on_instance_load** : enable loading ``ControlBase`` properties when element it's loaded (*default:* ``False``) , will need enabled if want to access to base properties values obtained from selenium methods at ``BotBase.navigation``
+ Param **on_instance_search** : enable searching element at instance `ControlBase` , also properties when element it's loaded (*default:* `False`) *access to base properties values obtained from selenium methods at* ``BotBase.navigation``

- Methods for **ControlBase**

Expand Down Expand Up @@ -115,7 +114,6 @@ Example of usage
"selector": "button[type='submit']",
"instance": "ControlBase",
"on_instance_search": false,
"on_instance_load": false,
"auto_reload": True,
}
]
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ install:
- "python -m pip install --pre -U tox"

test_script:
- "tox -e %TOXENV%,flake8"
- "tox -e flake8,%TOXENV%"

after_test:
- "python setup.py sdist"
Expand Down
34 changes: 3 additions & 31 deletions qacode/core/webs/controls/control_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class ControlBase(object):
locator = None
selector = None
on_instance_search = None
on_instance_load = None
auto_reload = None
instance = None
# Element properties
Expand All @@ -40,11 +39,6 @@ class ControlBase(object):
is_selected = None
attr_id = None
attr_class = None
# Reload configuration
RELOAD_CONFIG = {
"on_instance_search": True,
"on_instance_load": True,
}

def __init__(self, bot, **kwargs):
"""Wrapper for Selenium class named 'WebElement' using
Expand All @@ -69,7 +63,6 @@ def load(self, **kwargs):
self._load_search(
enabled=self.on_instance_search,
element=self.settings.get("element"))
self._load_properties(enabled=self.on_instance_load)

def load_settings_keys(self, settings, update=False, default_keys=None):
"""Load default setting for ControlBase instance"""
Expand All @@ -81,7 +74,6 @@ def load_settings_keys(self, settings, update=False, default_keys=None):
("name", "UNNAMED"),
("locator", By.CSS_SELECTOR),
("on_instance_search", False),
("on_instance_load", False),
("auto_reload", True),
("instance", 'ControlBase'),
("element", None)
Expand Down Expand Up @@ -110,8 +102,9 @@ def load_settings_keys(self, settings, update=False, default_keys=None):

def _load_search(self, enabled=False, element=None):
"""Load element searching at selenium WebDriver"""
if not enabled or enabled is None:
if enabled is None or not enabled:
self.bot.log.debug(MSG.CB_SEARCH_DISABLED)
self.bot.log.debug(MSG.CB_PROP_DISABLED)
return False
self.bot.log.debug(MSG.CB_SEARCH_LOADING)
try:
Expand All @@ -130,26 +123,6 @@ def _load_search(self, enabled=False, element=None):
self.selector, locator=self.locator)
if self.element:
self.bot.log.debug(MSG.CB_SEARCH_FOUND)
return True

def _load_properties(self, enabled=False):
"""Load default properties for base element
Keyword Arguments:
enabled {bool} -- load at enabled (default: {False})
Raises:
ControlException -- if enabled and settings
haven't key on_instance_search
"""
if enabled and not self.settings.get('on_instance_search'):
msg = ("Can't call to load_properties "
"wihout call first to load_search")
self.bot.log.error(msg)
raise ControlException(msg=msg)
if not enabled or enabled is None:
self.bot.log.debug(MSG.CB_PROP_DISABLED)
return False
self.bot.log.debug(MSG.CB_PROP_LOADING)
self.tag = self.get_tag()
self.text = self.get_text()
Expand Down Expand Up @@ -395,14 +368,13 @@ def reload(self, **kwargs):
config = kwargs.copy()
else:
config = self.settings.copy()
config.update(self.RELOAD_CONFIG)
config.update({"on_instance_search": True})
# needed for self._load_* functions
self.load_settings_keys(config, update=True)
# instance logic
self._load_search(
enabled=self.on_instance_search,
element=self.element)
self._load_properties(enabled=self.on_instance_load)
if class_name == 'ControlBase':
self.bot.log.debug(MSG.CB_RELOAD_LOADED.format(class_name))

Expand Down
5 changes: 1 addition & 4 deletions qacode/core/webs/controls/control_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def __load__(self, **kwargs):
self._load_search(
enabled=self.on_instance_search,
element=self.settings.get("element"))
self._load_properties(enabled=self.on_instance_load)
# at least 1 rule to enable this feature
self.__load__rules__(enabled=len(self.strict_rules))

Expand All @@ -53,7 +52,6 @@ def load_settings_keys(self, settings, update=False):
("name", "UNNAMED"),
("locator", By.CSS_SELECTOR),
("on_instance_search", False),
("on_instance_load", False),
("auto_reload", True),
("instance", 'ControlForm'),
("strict_rules", []),
Expand Down Expand Up @@ -134,14 +132,13 @@ def reload(self, **kwargs):
config = kwargs.copy()
else:
config = self.settings.copy()
config.update(self.RELOAD_CONFIG)
config.update({"on_instance_search": True})
# needed for self._load_* functions
self.load_settings_keys(config, update=True)
# instance logic
self._load_search(
enabled=self.on_instance_search,
element=self.element)
self._load_properties(enabled=self.on_instance_load)
# at least 1 rule to enable this feature
self.__load__rules__(enabled=len(kwargs.get("strict_rules")))
self.bot.log.debug(MSG.CF_RELOAD_LOADED)
Expand Down
53 changes: 14 additions & 39 deletions tests/001_functionals/suite_005_controlbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ def setup_login_to_data(self):

@pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG)
@pytest.mark.parametrize("on_instance_search", [True, False])
@pytest.mark.parametrize("on_instance_load", [True, False])
@pytest.mark.parametrize("auto_reload", [True, False])
def test_controlbase_instance(self, on_instance_search,
on_instance_load, auto_reload):
def test_controlbase_instance(self, on_instance_search, auto_reload):
"""Testcase: test_instance_base"""
tag_name = "input"
cfg = {
Expand All @@ -115,14 +113,8 @@ def test_controlbase_instance(self, on_instance_search,
"selector": "#txtUsername-field",
"instance": "ControlBase",
"on_instance_search": on_instance_search,
"on_instance_load": on_instance_load,
"auto_reload": auto_reload,
}
# negative testcases
if not on_instance_search and on_instance_load:
with pytest.raises(ControlException):
ControlBase(self.bot, **cfg)
return True
# functional testcases
ctl = ControlBase(self.bot, **cfg)
self.assert_is_instance(ctl, ControlBase)
Expand All @@ -132,13 +124,11 @@ def test_controlbase_instance(self, on_instance_search,
self.assert_equals(ctl.locator, cfg.get('locator'))
self.assert_equals(
ctl.on_instance_search, cfg.get('on_instance_search'))
self.assert_equals(ctl.on_instance_load, cfg.get('on_instance_load'))
self.assert_equals(ctl.auto_reload, cfg.get('auto_reload'))
self.assert_equals(ctl.instance, cfg.get('instance'))
if on_instance_search and on_instance_load:
self.assert_equals(ctl.tag, tag_name)
if on_instance_search:
self.assert_is_instance(ctl.element, WebElement)
self.assert_equals(ctl.tag, tag_name)
else:
self.assert_none(ctl.element)

Expand All @@ -150,7 +140,6 @@ def test_controlbase_instance_raises(self):
"selector": None,
"instance": None,
"on_instance_search": None,
"on_instance_load": None,
"auto_reload": None,
}
with pytest.raises(ControlException):
Expand All @@ -170,54 +159,47 @@ def test_instance_raises_nonesettings(self):
def test_property_gettext(self):
"""Testcase: test_property_gettext"""
cfg_btn = self.btn_submit.copy()
cfg_btn.update({"on_instance_load": True})
cfg_btn.update({"on_instance_search": True})
control = ControlBase(self.bot, **cfg_btn)
self.assert_equals(control.text, 'Login')

@pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG)
def test_property_raises_gettext(self):
"""Testcase: test_property_raises_gettext"""
cfg_btn = self.btn_submit.copy()
control = ControlBase(self.bot, **cfg_btn)
self.assert_equals(control.text, None)

@pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG)
def test_method_gettext(self):
"""Testcase: test_method_gettext"""
cfg_btn = self.btn_submit.copy()
cfg_btn.update({"on_instance_load": True})
cfg_btn.update({"on_instance_search": True})
control = ControlBase(self.bot, **cfg_btn)
self.assert_equals(control.get_text(), 'Login')

@pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG)
def test_property_attr_id(self):
"""Testcase: test_property_attr_id"""
cfg_input = self.txt_username.copy()
cfg_input.update({"on_instance_load": True})
cfg_input.update({"on_instance_search": True})
control = ControlBase(self.bot, **cfg_input)
self.assert_not_none(control.attr_id)

@pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG)
def test_property_attr_class(self):
"""Testcase: test_property_attr_class"""
cfg_form = self.form_login.copy()
cfg_form.update({"on_instance_load": True})
cfg_form.update({"on_instance_search": True})
control = ControlBase(self.bot, **cfg_form)
self.assert_in('ember-view', control.attr_class)

@pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG)
def test_method_getattrvalue(self):
"""Testcase: test_method_getattrvalue"""
cfg_form = self.form_login.copy()
cfg_form.update({"on_instance_load": True})
cfg_form.update({"on_instance_search": True})
control = ControlBase(self.bot, **cfg_form)
self.assert_not_none(control.get_attr_value('id'))

@pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG)
def test_method_get_attrs(self):
"""Testcase: test_method_get_attrs"""
cfg_form = self.form_login.copy()
cfg_form.update({"on_instance_load": True})
cfg_form.update({"on_instance_search": True})
control = ControlBase(self.bot, **cfg_form)
attrs = control.get_attrs(['id', 'class'])
self.assert_equals(attrs[0]['name'], 'id')
Expand All @@ -229,7 +211,7 @@ def test_method_get_attrs(self):
def test_property_tag(self):
"""Testcase: test_property_tag"""
cfg_form = self.form_login.copy()
cfg_form.update({"on_instance_load": True})
cfg_form.update({"on_instance_search": True})
control = ControlBase(self.bot, **cfg_form)
self.assert_equals(control.tag, 'form')

Expand All @@ -246,7 +228,7 @@ def test_method_click(self, retry):
@pytest.mark.parametrize(
"control_config",
[
{"on_instance_load": True},
{"on_instance_search": True},
{"auto_reload": True}
])
def test_method_typetext(self, control_config, clear):
Expand All @@ -263,7 +245,7 @@ def test_method_typetext(self, control_config, clear):
def test_method_getcssvalue(self):
"""Testcase: test_method_getcssvalue"""
cfg_input = self.txt_username.copy()
cfg_input.update({"on_instance_load": True})
cfg_input.update({"on_instance_search": True})
control = ControlBase(self.bot, **cfg_input)
self.assert_equals(
control.get_css_value('color'),
Expand All @@ -273,7 +255,7 @@ def test_method_getcssvalue(self):
def test_method_setcssrule(self):
"""Testcase: test_method_setcssrule"""
cfg_input = self.txt_username.copy()
cfg_input.update({"on_instance_load": True})
cfg_input.update({"on_instance_search": True})
control = ControlBase(self.bot, **cfg_input)
control.type_text('test')
control.set_css_value('color', 'red')
Expand All @@ -286,7 +268,7 @@ def test_method_gettext_onscreenfalse(self):
"""Testcase: test_method_gettext_onscreenfalse"""
msg_err = 'Failed at obtain text, open issue on Github'
cfg_btn = self.btn_submit.copy()
cfg_btn.update({"on_instance_load": True})
cfg_btn.update({"on_instance_search": True})
control = ControlBase(self.bot, **cfg_btn)
control.set_css_value('display', 'none')
text = control.get_text(on_screen=False)
Expand All @@ -304,21 +286,14 @@ def test_method_reload_base(self, selector, instance):
"selector": selector,
"instance": instance,
"on_instance_search": False,
"on_instance_load": False,
}
control = ControlBase(self.bot, **cfg_base)
self.assert_equals(control.on_instance_search, False)
self.assert_equals(control.on_instance_load, False)
self.assert_none(control.element)
# Real test behaviour
cfg_update = {
"on_instance_search": True,
"on_instance_load": True
}
cfg_base.update(cfg_update)
cfg_base.update({"on_instance_search": True})
control.reload(**cfg_base)
self.assert_equals(control.on_instance_search, True)
self.assert_equals(control.on_instance_load, True)
self.assert_is_instance(control.element, WebElement)

@pytest.mark.skipIf(SKIP_CONTROLS, SKIP_CONTROLS_MSG)
Expand Down

0 comments on commit 6432456

Please sign in to comment.