Skip to content

Commit

Permalink
add logging to show what scripts are being executed
Browse files Browse the repository at this point in the history
  • Loading branch information
lmtierney committed Jun 21, 2022
1 parent 4520e5a commit f76485b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion nerodia/browser.py
Expand Up @@ -230,16 +230,20 @@ def status(self):
"""
return self.execute_script('return window.status;')

def execute_script(self, script, *args):
def execute_script(self, script, *args, function_name=None):
"""
Executes JavaScript snippet
:param script: Javascript Snippet to execute
:type script: str
:param args: Arguments will be available in the given script in the 'arguments' pseudo-array
:param function_name: name of function being executed
:type function_name: str or None
:return: result of script
"""
from .elements.element import Element
args = [e.wait_until(lambda x: x.exists).wd if isinstance(e, Element) else e for e in args]
if function_name:
nerodia.logger.info(f'Executing Script on Browser: {function_name}')
returned = self.driver.execute_script(script, *args)

return self._wrap_elements_in(self, returned)
Expand Down
5 changes: 4 additions & 1 deletion nerodia/elements/i_frame.py
@@ -1,6 +1,7 @@
import six
from selenium.common.exceptions import NoSuchFrameException

import nerodia
from .html_elements import HTMLElement, HTMLElementCollection
from ..exception import UnknownFrameException
from ..meta_elements import MetaHTMLElement
Expand Down Expand Up @@ -35,10 +36,12 @@ def send_keys(self, *args):
"""
self.wd.send_keys(*args)

def execute_script(self, script, *args):
def execute_script(self, script, *args, function_name=None):
""" Executes JavaScript in context of frame """
from nerodia.elements.element import Element
args = [e.wait_until(lambda e: e.exists).wd if isinstance(e, Element) else e for e in args]
if function_name:
nerodia.logger.info(f'Executing Script on Frame: {function_name}')
returned = self.driver.execute_script(script, *args)

return self.browser._wrap_elements_in(self, returned)
Expand Down
4 changes: 2 additions & 2 deletions nerodia/js_execution.py
Expand Up @@ -5,13 +5,13 @@


class JSExecution(object):
def execute_script(self, script, *args):
def execute_script(self, script, *args, function_name=None):
"""
Delegates script execution to Browser or IFrame
:param script: script to execute
"""
return self.query_scope.execute_script(script, *args)
return self.query_scope.execute_script(script, *args, function_name=function_name)

def fire_event(self, event_name):
"""
Expand Down
2 changes: 1 addition & 1 deletion nerodia/js_snippet.py
Expand Up @@ -14,4 +14,4 @@ def _execute_js(self, function_name, *args):

with open(filepath, 'r') as myfile:
script = 'return ({}).apply(null, arguments)'.format(myfile.read())
return self.query_scope.execute_script(script, *args)
return self.query_scope.execute_script(script, *args, function_name=function_name)

0 comments on commit f76485b

Please sign in to comment.