Skip to content

Commit

Permalink
selenium: attempt at handling exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
naisanzaa committed Dec 27, 2023
1 parent d27ae96 commit a9f9119
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
27 changes: 6 additions & 21 deletions automon/integrations/seleniumWrapper/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from .config import SeleniumConfig
from .user_agents import SeleniumUserAgentBuilder
from .exceptions import *

logger = log.logging.getLogger(__name__)
logger.setLevel(log.DEBUG)
Expand Down Expand Up @@ -153,15 +154,7 @@ def action_click(self, xpath: str, note: str = None) -> str or False:
return click

except Exception as error:
message, session, stacktrace = self.error_parsing(error)
logger.error(str(dict(
url=self.url,
xpath=xpath,
message=message,
session=session,
stacktrace=stacktrace,
)))
return False
raise Exception(error)

def action_type(self, key: str or Keys, secret: bool = True):
"""perform keyboard command"""
Expand All @@ -180,15 +173,7 @@ def action_type(self, key: str or Keys, secret: bool = True):
return True

except Exception as error:
message, session, stacktrace = self.error_parsing(error)
logger.error(str(dict(
url=self.url,
send_keys=key,
message=message,
session=session,
stacktrace=stacktrace,
)))
return False
raise Exception(error)

def add_cookie(self, cookie_dict: dict) -> bool:
result = self.webdriver.add_cookie(cookie_dict=cookie_dict)
Expand Down Expand Up @@ -312,8 +297,8 @@ def error_parsing(error) -> tuple:

return message, session, stacktrace

except Exception as e:
logger.error(e)
except Exception as error:
logger.error(error)

return error, None, None

Expand Down Expand Up @@ -576,7 +561,7 @@ def wait_for(
value=value,
)))

return False
raise NoSuchElementException(values)

def wait_for_element(
self,
Expand Down
10 changes: 10 additions & 0 deletions automon/integrations/seleniumWrapper/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class ActionClickException(Exception):
pass


class ActionTypeException(Exception):
pass


class NoSuchElementException(Exception):
pass

0 comments on commit a9f9119

Please sign in to comment.