Telefonica / toolium

Wrapper tool of Selenium and Appium libraries to test web and mobile applications in a single project
Apache License 2.0
115 stars 62 forks source link

Is it possible to inherite from class that inheritance from Group/Button etc? #282

Closed DuXspace closed 2 years ago

DuXspace commented 2 years ago

Hello, as I see now, it's not possible to use self.driver_wrapper.config.get('Driver', 'type').split('-')[0] inside "Element" class. Maybe you know a different way to solve it?

https://pastebin.com/twMuqsq7

And it raising and exception(I simplify a little bit code in example):

` ../../../../page_object/admin_panel/General/Table/UsersTable.py:161: in block self.block_modal.apply_block_reason(reason) ../../../../page_object/admin_panel/General/Modal/BlockModal.py:36: in apply_block_reason self.add_additional_information(additional_info)\ ../../../../page_object/admin_panel/General/Modal/BaseModal.py:20: in apply self.submit_button.click() ../../../../page_object/base_page_object/page_elements/Button.py:41: in click if self.driver_wrapper.is_ios_web_test(): /Library/Python/3.8/site-packages/toolium/driver_wrapper.py:323: in is_ios_web_test return self.is_ios_test() and self.is_web_test() /Library/Python/3.8/site-packages/toolium/driver_wrapper.py:294: in is_ios_test return self.utils.get_driver_name() in ('ios', 'iphone') /Library/Python/3.8/site-packages/toolium/utils/driver_utils.py:42: in get_driver_name return self.driver_wrapper.config.get('Driver', 'type').split('-')[0] /Library/Python/3.8/site-packages/toolium/config_parser.py:187: in get return super().get(section, self._encode_option(option), *args, **kwargs) /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/configparser.py:781: in get d = self._unify_values(section, vars)


self = <toolium.config_parser.ExtendedConfigParser object at 0x1040d8d90> section = 'Driver', vars = None

def _unify_values(self, section, vars):
    """Create a sequence of lookups with 'vars' taking priority over
    the 'section' which takes priority over the DEFAULTSECT.

    """
    sectiondict = {}
    try:
        sectiondict = self._sections[section]
    except KeyError:
        if section != self.default_section:
          raise NoSectionError(section) from None

E configparser.NoSectionError: No section: 'Driver'

/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/configparser.py:1149: NoSectionError `

We need to use click from iOSHelper because we are using Safari driver in appium(https://appium.io/docs/en/drivers/safari/), but it doesn't support some of selenium methods like is_visible, delete_cookies etc. so we need to override some methods, because I'm trying to use 1 test for different platforms(desktop, android, ios)

rgonalo commented 2 years ago

Hi @DuXspace , after reviewing the issue and the provided code, I guess that the problem is not related to the inheritance, but to the configuration file. I have tested your code and it executes is_ios_web_test method correctly. Please, verify that your configuration file contains the Driver section and that the loaded config file is the expected one.

DuXspace commented 2 years ago

@rgonalo Hello! Thank you for your response! Hm, maybe I missed something, I'll try to check what config is used and I'll try to prepare code on real example, looks like we are trying to create sometimes Button classes in methods to return them, maybe thats why it doesn't work for us.

Can you also change this line parent_msg = " and parent locator '{}'".format(self.parent) if self.parent else '' to parent_msg = " and parent locator '{}'".format(self.parent.locator) if self.parent else ''

https://github.com/Telefonica/toolium/blob/06412bc7d067332b09452a675ab06b6c809d1862/toolium/pageelements/page_element.py#L89

and here

https://github.com/Telefonica/toolium/blob/06412bc7d067332b09452a675ab06b6c809d1862/toolium/pageelements/page_element.py#L221

It will help to receive more readable exceptions

rgonalo commented 2 years ago

You are right, I have updated the log lines in https://github.com/Telefonica/toolium/pull/284, thanks! In any case, if your test fails in these lines, then it should not be related with the previous error "configparser.NoSectionError: No section: 'Driver'"

DuXspace commented 2 years ago

@rgonalo Issue can be closed, we found a problem. We initialize driver wrapper in that way: driver_wrapper = DriverWrapper() config_files = DriverWrappersPool.initialize_config_files() driver_wrapper.configure(config_files) driver_wrapper.connect()

Changed it to DriverWrappersPool.connect_default_driver_wrapper() and it works properly