Skip to content

Commit

Permalink
removed Tips and ANSI colors from errors
Browse files Browse the repository at this point in the history
Signed-off-by: René <[email protected]>
  • Loading branch information
Snooz82 committed Oct 7, 2024
1 parent 94c9785 commit 16d701d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 48 deletions.
46 changes: 16 additions & 30 deletions Browser/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from concurrent.futures._base import Future
from datetime import timedelta
from pathlib import Path
from typing import Any, ClassVar, Optional, Union
from typing import Any, Optional, Union

from assertionengine import AssertionOperator
from overrides import overrides
Expand Down Expand Up @@ -777,23 +777,6 @@ class Browser(DynamicCore):
ROBOT_LISTENER_API_VERSION = 2
ROBOT_LIBRARY_LISTENER: "Browser"
ROBOT_LIBRARY_SCOPE = "GLOBAL"
ERROR_AUGMENTATION: ClassVar[list[dict]] = [
{
"re": re.compile(r"Timeout .+ exceeded."),
"callable": lambda msg: (
f'{msg}\nTip: Use "Set Browser Timeout" for increasing the timeout or '
"double check your locator as the targeted element(s) couldn't be found."
),
"selector": True,
},
{
"re": re.compile(r"Timeout .+ exceeded."),
"callable": lambda msg: (
f'{msg}\nTip: Use "Set Browser Timeout" for increasing the timeout.'
),
"selector": False,
},
]

_context_cache = ContextCache()
_suite_cleanup_done = False
Expand Down Expand Up @@ -1279,19 +1262,22 @@ def _prune_execution_stack(self, catalog_before: dict) -> None:
def _alter_keyword_error(self, name: str, args: tuple) -> tuple:
if not (args and isinstance(args, tuple)):
return args

message = args[0]
argument_specification = self.keywords_spec[name].argument_specification
selector_in_args = "selector" in argument_specification
for augmentation in self.ERROR_AUGMENTATION:
regex, augment, selector = (
augmentation["re"],
augmentation["callable"],
augmentation["selector"],
ansi_escape = re.compile(
r"""
\x1B # ESC
(?: # 7-bit C1 Fe (except CSI)
[@-Z\\-_]
| # or [ for CSI, followed by a control sequence
\[
[0-?]* # Parameter bytes
[ -/]* # Intermediate bytes
[@-~] # Final byte
)
if regex.search(message) and selector == selector_in_args:
message = augment(message)
return (message,) + args[1:]
""",
re.VERBOSE,
)
clean_message = ansi_escape.sub("", args[0])
return (clean_message,) + args[1:]

def _set_logging(self, status: bool):
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ New Page Will Timeout And Page Will Be Removed From Catalog
${Catalog} = Get Browser Catalog
TRY
New Page ${SLOW_PAGE}
EXCEPT *timeout* type=glob
EXCEPT *Timeout* type=glob
${new_catalog} = Get Browser Catalog
Should Be Equal ${Catalog} ${new_catalog}
ELSE
Expand Down
4 changes: 2 additions & 2 deletions atest/test/01_Browser_Management/persistent_state.robot
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ New Persistent Context Cleaned Up After Timeout
${catalog_1} = Get Browser Catalog
TRY
New Persistent Context url=${SLOW_PAGE} timeout=1s
EXCEPT *timeout* type=GLOB
EXCEPT *Timeout* type=GLOB
${catalog_2} = Get Browser Catalog
Should Be Equal ${catalog_1} ${catalog_2}
END
Expand All @@ -90,7 +90,7 @@ New Persistent Context Cleaned Up After Timeout
${catalog_3} = Get Browser Catalog
TRY
New Persistent Context url=${SLOW_PAGE} timeout=1s
EXCEPT *timeout* type=GLOB
EXCEPT type=GLOB
${catalog_4} = Get Browser Catalog
Should Be Equal ${catalog_3} ${catalog_4}
END
Expand Down
4 changes: 1 addition & 3 deletions atest/test/01_Browser_Management/timeout.robot
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ Resource imports.resource
Suite Setup New Browser headless=${HEADLESS}
Suite Teardown Close Browser

Force Tags timeout no-iframe
Test Tags timeout no-iframe

*** Variables ***
${err_goto} = page.goto: Timeout 1ms exceeded.
${err_click} = SEPARATOR=
... locator.click: Timeout 100ms exceeded.
... *Use "Set Browser Timeout" for increasing the timeout or double check${SPACE}
... your locator as the targeted element(s) couldn't be found.

*** Test Cases ***
Test GoTo With Short Default Timeout
Expand Down
4 changes: 2 additions & 2 deletions atest/test/02_Content_Keywords/dialogs.robot
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Handle Multiple Dialogs With Wrong Texts
Log Got expected error, all is good.
END

Handle Conform And Prompt
Handle Conform And Prompt With Dismiss Accept
[Setup] New Page ${DIALOGS_TWO_URL}
${promise} = Promise To
... Wait For Alerts
Expand All @@ -138,7 +138,7 @@ Handle Conform And Prompt
Get Text id=confirm == First alert declined!
Get Text id=prompt == Second alert input: I am a prompt

Handle Conform And Prompt
Handle Conform And Prompt With Accept Dismiss
[Setup] New Page ${DIALOGS_TWO_URL}
${promise} = Promise To
... Wait For Alerts
Expand Down
10 changes: 0 additions & 10 deletions atest/test/03_Waiting/wait_for_http.robot
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ Wait Until Network Is Idle Works
Wait Until Network Is Idle timeout=3s
Get Text \#server_delayed_response == after some time I respond

Wait Until Network Is Fails And Contains Correct Tip
[Tags] slow
Go To ${ROOT_URL}delayed-load.html
Get Text \#server_delayed_response == Server response after 400ms
TRY
Wait Until Network Is Idle timeout=0.1s
EXCEPT AS ${error}
Should End With ${error} Tip: Use "Set Browser Timeout" for increasing the timeout. strip_spaces=True
END

Wait For Navigation Works
[Tags] slow
Go To ${ROOT_URL}redirector.html
Expand Down

0 comments on commit 16d701d

Please sign in to comment.