Skip to content

Commit

Permalink
Adding highlighting to WT for debugging/development
Browse files Browse the repository at this point in the history
  • Loading branch information
psav committed Aug 15, 2018
1 parent 74bc409 commit 1148672
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/widgetastic/widget.py
Expand Up @@ -11,6 +11,7 @@
from collections import defaultdict, namedtuple
from copy import copy
from jsmin import jsmin
from time import sleep
from selenium.webdriver.remote.file_detector import LocalFileDetector
from selenium.webdriver.remote.webelement import WebElement
from smartloc import Locator
Expand Down Expand Up @@ -326,6 +327,7 @@ def __init__(self, parent, logger=None):
self.extra = ExtraData(self)
self._widget_cache = {}
self._initialized_included_widgets = {}
self._cache_highlight = None

def __element__(self):
"""Implement the logic of querying
Expand Down Expand Up @@ -630,6 +632,24 @@ def width(self):
def height(self):
return self.browser.size_of(self, parent=self.parent)[1]

def _do_highlight(self, border):
self.browser.execute_script(
"arguments[0].style.border='{}'".format(border), self.__element__()
)

def highlight(self, timeout=5, colour='red'):
cache_border = self.browser.execute_script("arguments[0].style.border", self.__element__())
self._do_highlight('3px solid {}'.format(colour))
sleep(timeout)
self._do_highlight(cache_border)

def highlight_on(self, colour='red'):
self._cache_highlight = self.browser.execute_script("arguments[0].style.border", self.__element__())
self._do_highlight('3px solid {}'.format(colour))

def highlight_off(self):
self._do_highlight(self._cache_highlight)

def __iter__(self):
"""Allows iterating over the widgets on the view."""
for widget_attr in self.widget_names:
Expand Down

0 comments on commit 1148672

Please sign in to comment.