Exemple #1
0
def __capture_tag(pathbuilder, tags_per_campaign, tagsize, capabilities,
                  capture_existing=False):
    pathbuilder.size = tagsize

    # Check if we already have the files from default path
    default_pb = pathbuilder.clone(build=output.DEFAULT_BUILD_NAME)
    if default_pb.pathexists() and not capture_existing:
        LOGGER.debug("Skipping existing captures %s", default_pb.path)
        return False

    with __start_webdriver_capture(capabilities,
                                   build=pathbuilder.build,
                                   name=pathbuilder.config) as driver:
        try:
            tag_html = tags_per_campaign[tagsize]
            webdriver.display_tag(driver, tag_html)
        except Exception:
            LOGGER.exception("Exception while displaying tags!")
            return None

        # Getting ready to write to files
        pathbuilder.create()
        # TODO: Only works for iframe tags atm
        try:
            tag_element = driver.find_element_by_tag_name('iframe')
            webdriver.screenshot_element(driver, tag_element,
                                         pathbuilder.tagimage)
        except Exception:
            LOGGER.exception(
                "Exception while getting screenshot for tag: %s",
                pathbuilder.path)
            return None
    _write_html(tag_html=tag_html, output_path=pathbuilder.taghtml)
Exemple #2
0
def __capture_tag(pathbuilder, tags_per_campaign, driver,
                  capture_existing=False):
    """
    Captures a tag
    :param pathbuilder:
    :param tags_per_campaign:
    :param tagsize:
    :param capabilities:
    :param capture_existing:
    :return: list of browser errors during capture.
        False on error, None on skip
    """
    # Check if we already have the files from default path
    default_pb = pathbuilder.clone(build=output.DEFAULT_BUILD_NAME)
    if default_pb.pathexists() and not capture_existing:
        LOGGER.debug("Skipping existing captures %s", default_pb.path)
        return None

    try:
        tag_html = tags_per_campaign[pathbuilder.tagsize][pathbuilder.tagtype]
        errors = webdriver.display_tag(driver, tag_html)
        # Getting ready to write to files
        pathbuilder.create()
        tag_element = driver.find_element_by_tag_name(pathbuilder.tagtype)
        webdriver.screenshot_element(driver, tag_element, pathbuilder.tagimage)
    except selenium.common.exceptions.WebDriverException:
        LOGGER.exception("Exception while capturing tags!")
        return False

    __write_html(tag_html=tag_html, output_path=pathbuilder.taghtml)
    return errors
Exemple #3
0
def __capture_tag(pathbuilder,
                  tags_per_campaign,
                  driver,
                  capture_existing=False):
    """
    Captures a tag
    :param pathbuilder:
    :param tags_per_campaign:
    :param tagsize:
    :param capabilities:
    :param capture_existing:
    :return: list of browser errors during capture.
        False on error, None on skip
    """
    # Check if we already have the files from default path
    default_pb = pathbuilder.clone(build=output.DEFAULT_BUILD_NAME)
    if default_pb.pathexists() and not capture_existing:
        LOGGER.debug("Skipping existing captures %s", default_pb.path)
        return None

    try:
        tag_html = tags_per_campaign[pathbuilder.tagsize][pathbuilder.tagtype]
        errors = webdriver.display_tag(driver, tag_html)
        # Getting ready to write to files
        pathbuilder.create()
        tag_element = driver.find_element_by_tag_name(pathbuilder.tagtype)
        webdriver.screenshot_element(driver, tag_element, pathbuilder.tagimage)
    except selenium.common.exceptions.WebDriverException:
        LOGGER.exception("Exception while capturing tags!")
        return False

    __write_html(tag_html=tag_html, output_path=pathbuilder.taghtml)
    return errors
Exemple #4
0
 def capture_tag(self, tag_html, output_path, tagtype='iframe'):
     """
     Generic/public method to capture a tag
     :param driver:
     :param tag_html:
     :param output_path:
     :param tagtype:
     :return:
     """
     errors = webdriver.display_tag(self._driver, tag_html,
                                    wait_time=self._wait_time)
     tag_element = self._driver.find_element_by_tag_name(tagtype)
     webdriver.screenshot_element(
         self._driver, tag_element, output_path)
     if errors:
         self.logger.warn(
             'Found browser errors while capturing %s:\n%s',
             output_path, errors)
     return errors