selene icon indicating copy to clipboard operation
selene copied to clipboard

consider forceful type conversion to str in have.value or adding type hints

Open roman-isakov opened this issue 3 years ago • 0 comments

Idea: Since method below always returns string values, I'd like to suggest to cast input values to strings or add type hints, since error logs:

webelement.py: def get_attribute(self, name) -> str

'.limit__input[tabindex="1"]')).has attribute 'value' with value '33'
E                       
E                       Reason: AssertionError: actual attribute_value: 33

Problematic code:

...
v = 33  # int
input.set_value(v).should(have.value(v))

Fix solution:

...
v = 33  # int
input.set_value(v).should(have.value(str(v)))

LOGS

self = <utils.assist.selene.report.wait.ReportedWait object at 0x7f5056dda910>
fn = <selene.core.conditions.ElementCondition object at 0x7f5056ddabe0>

        def for_(self, fn: Callable[[E], R]) -> R:
            finish_time = time.time() + self._timeout
    
            while True:
                try:
                    return fn(self._entity)
                except Exception as reason:
                    if time.time() > finish_time:
    
                        reason_message = str(reason)
    
                        reason_string = '{name}: {message}'.format(
                            name=reason.__class__.__name__, message=reason_message
                        )
                        # todo: think on how can we improve logging failures in selene, e.g. reverse msg and stacktrace
                        # stacktrace = getattr(reason, 'stacktrace', None)
                        timeout = self._timeout
                        entity = self._entity
    
                        failure = TimeoutException(
                            f'''
    
    Timed out after {timeout}s, while waiting for:
    {entity}.{fn}
    
    Reason: {reason_string}'''
                        )
    
>                       raise self._hook_failure(failure)
E                       selene.core.exceptions.TimeoutException: Message: 
E                       
E                       Timed out after 25s, while waiting for:
E                       browser.element(('css selector', 'app-sensor-limits')).element(('css selector', 'mat-dialog-content')).element(('css selector', '.control')).all(('css selector', '.limit'))[0].element(('css selector', '.limit__input[tabindex="1"]')).has attribute 'value' with value '33'
E                       
E                       Reason: AssertionError: actual attribute_value: 33
E                       Screenshot: file:///home/roman/.selene/screenshots/1662718766200/1662718766201.png
E                       PageSource: file:///home/roman/.selene/screenshots/1662718766200/1662718766201.html

../.venv/lib/python3.9/site-packages/selene/core/wait.py:125: TimeoutException

roman-isakov avatar Sep 09 '22 10:09 roman-isakov