Exemple #1
0
 def getCSSProperty(self, propertyName):
     """
         Return value of CSS property of base element (value of property consisted in attribute
           'style'). Ex. <div style='display:none'>, where getCSSProperty(propertyName='display')
           will be 'none'.
         @param propertyName: Name of CSS property (ex. 'border-style', 'background-color').
         @return: Value of CSS property (ex. 'solid dotted', 'red').
     """
     cssProperty = self.element.value_of_css_property(property_name=propertyName)
     LOG.l5("%s.getCSSProperty(%s): '%s'" % (self.name, propertyName, cssProperty))
     return cssProperty
Exemple #2
0
 def waitUntilVisible(self):
     """
         Wait until base element of component has become visible on web page.
     """
     timeout = Timeout(timeout=self.driver.timeout, description='%s.waitUntilVisible(): Time out.'
         % self.name)
     while not self.isVisible(suppressLog=True):
         if timeout.exceeded(raiseException=False):
             raise ComponentFailedStateException(message='%s.waitUntilVisible(): Time out.' %
             self.name, driver=self.driver, screenshotName=self.name + '.waitUntilVisible')
         time.sleep(self.driver.delay)
     LOG.l5('%s.waitUntilVisible()' % self.name)
Exemple #3
0
 def waitUntilAbsent(self):
     """
         Wait until base element of component has completely disappeared from DOM.
     """
     timeout = Timeout(timeout=self.driver.timeout, description='%s.waitUntilAbsent(): Time out.'
         % self.name)
     while self.isPresent(suppressLog=True):
         if timeout.exceeded(raiseException=False):
             raise ComponentFailedStateException(message='%s.waitUntilAbsent(): Time out.' %
             self.name, driver=self.driver, screenshotName=self.name + '.waitUntilAbsent')
         time.sleep(self.driver.delay)
     LOG.l5('%s.waitUntilAbsent()' % self.name)
Exemple #4
0
 def waitUntilHidden(self):
     """
         Wait until base element of component became invisible on web page; still, it's present
           in DOM, the same as isDisplayed() == False.
     """
     timeout = Timeout(timeout=self.driver.timeout, description='%s.waitUntilHidden(): Time out.'
         % self.name)
     while self.isVisible(suppressLog=True):
         if timeout.exceeded(raiseException=False):
             raise ComponentFailedStateException(message='%s.waitUntilHidden(): Time out.' %
             self.name, driver=self.driver, screenshotName=self.name + '.waitUntilHidden')
         time.sleep(self.driver.delay)
     LOG.l5('%s.waitUntilHidden()' % self.name)
Exemple #5
0
 def isVisible(self, suppressLog=False):
     """
         Inspect if base HTML element is visible. Setting <... style='display:none>' hides
           element from visibility on web page, still retaining it in DOM.
         @return: True if base element of component visible, otherwise False.
     """
     try:
         isVisible = self.element.is_displayed()
     except ComponentNotFoundException:
         isVisible = False
     if not suppressLog:
         LOG.l5('%s.isVisible(): %s' % (self.name, isVisible))
     return isVisible
Exemple #6
0
 def getAttribute(self, attributeName, suppressLog=False):
     """
         Returns attribute of HTML node of base WebElement of component such as 'id', 'class',
           'data-mg-comp' etc. Do not confuse with Python object's attribute which __getattr__
           above deals with.
         @param attributeName: Name of attribute of HTML node.
         @return: Attribute of HTML node.
     """
     attribute = self.element.get_attribute(name=attributeName)
     if not suppressLog:
         LOG.l5("%s.getAttribute(attributeName='%s'): '%s'" % (self.name, attributeName,
             attribute))
     return attribute
Exemple #7
0
 def waitUntilPresent(self):
     """
         Wait until base element of component is present in DOM. Useful for checking if web page
           or component have been loaded.
           Note: Present <> enabled, element can easily be disabled still being present.
     """
     timeout = Timeout(timeout=self.driver.timeout, description='%s.waitUntilPresent(): Time out.'
         % self.name)
     while not self.isPresent(suppressLog=True):
         if timeout.exceeded(raiseException=False):
             raise ComponentNotFoundException(message='%s.waitUntilPresent(): Time out.' %
             self.name, driver=self.driver, screenshotName=self.name + '.waitUntilPresent')
         time.sleep(self.driver.delay)
     LOG.l5('%s.waitUntilPresent()' % self.name)
Exemple #8
0
 def waitUntilClosed(self):
     """
         Customized solution doing inspection of absence or invisibility of page-specific
           components.
     """
     timeout = Timeout(timeout=self.driver.timeout,
                       description='%s.waitUntilClosed(): Time out.' %
                       self.name)
     while self.isOpen(suppressLog=True):
         if timeout.exceeded(raiseException=False):
             raise PageException(
                 message='%s.waitUntilClosed(): Time out.' % self.name,
                 driver=self.driver,
                 screenshotName=self.name + '.waitUntilClosed')
         time.sleep(self.driver.delay)
     LOG.l5('%s.waitUntilClosed()' % self.name)
Exemple #9
0
 def isPresent(self, suppressLog=False):
     """
         Inspects if element is present (can be found) in DOM.
           Note: This is not equal to isVisible(), as element could be present in DOM but hidden.
         @return: True if present, otherwise False.
     """
     try:
         # To determine if component is present, we just 'touch' it using __getattr__ above with
         #   any attribute.
         if self.element.id():
             isPresent = True
     except ComponentNotFoundException:
         isPresent = False
     if not suppressLog:
         LOG.l5('%s.isPresent(): %s' % (self.name, isPresent))
     return isPresent
Exemple #10
0
 def callAttribute(self, *args, **kwargs):
     """
         Translates attribute names to corresponding attribute calls. Takes care of
           named/unnamed parameters.
         @param args: Unnamed parameters (ex. 'admin' in send_keys('admin')). Optional.
         @param kwargs: Named parameters (ex. {'name': 'class'} in
           get_attribute(name='class'))
     """
     timeout = Timeout(timeout=self.driver.timeout, description="%s.element.%s(%s, %s): selector='%s'. Time out."
         % (self.name, self.attributeName, args, kwargs, self.selector))
     while True:
         if not timeout.exceeded(raiseException=False):
             if self.element is None:
                 try:
                     # Base web element of component, instance of WebDriver.WebElement. In
                     #   complex components, such as ComboBox or Grid, it is head element
                     #   which all other element/components are related to as children.
                     self.element = self.webDriver.find_element_by_xpath(xpath=self.selector)
                 except NoSuchElementException:
                     self.element = None
                     time.sleep(self.driver.delay)
                     continue
             try:
                 attribute = getattr(self.element, self.attributeName)
                 # TODO: Investigate if there more elegant solutions are.
                 if callable(attribute):
                     if len(args) and len(kwargs):
                         result = attribute(*args, **kwargs)
                     elif len(args):
                         result = attribute(*args)
                     elif len(kwargs):
                         result = attribute(**kwargs)
                     else:
                         result = attribute()
                 else:
                     result = attribute
                 break
             except (StaleElementReferenceException, ElementNotVisibleException):
                 self.element = None
                 time.sleep(self.driver.delay)
         else:
             raise ComponentNotFoundException(message="%s.element.%s(%s, %s): selector='%s'. Time out."
             % (self.name, self.attributeName, args, kwargs, self.selector),
             driver=self.driver, takeScreenshot=False)
     LOG.l5('%s.element.%s(%s, %s)' % (self.name, self.attributeName, args, kwargs))
     return result