当前位置: 首页>>代码示例>>Python>>正文


Python Marionette.screenshot方法代码示例

本文整理汇总了Python中marionette.Marionette.screenshot方法的典型用法代码示例。如果您正苦于以下问题:Python Marionette.screenshot方法的具体用法?Python Marionette.screenshot怎么用?Python Marionette.screenshot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在marionette.Marionette的用法示例。


在下文中一共展示了Marionette.screenshot方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: B2gExecutor

# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import screenshot [as 别名]

#.........这里部分代码省略.........
                    if input_field.get_id() and not input_field.get_id().startswith(DomAnalyzer.serial_prefix):
                        self._marionette.find_element('id', input_field.get_id()).send_keys(input_field.get_value())
                    elif input_field.get_xpath():
                        self._marionette.find_element('xpath', input_field.get_xpath()).send_keys(input_field.get_value())
                    else:
                        logger.error('No id nor xpath for an input field in the form id: %s (xpath: %s)', f.get_id(), f.get_xpath())
                        sys.exit()
                except (ElementNotVisibleException, InvalidElementStateException, NoSuchElementException):
                    logger.info('Element is not interactable in fill_form(): id: %s (xpath: %s)', f.get_id(), f.get_xpath())
                except Exception as e:
                    logger.error('Unknown Exception: %s in fill_form(): id: %s (xpath: %s)', str(e), f.get_id(), f.get_xpath())
                    sys.exit()

    def empty_form(self, clickable):
        for f in clickable.get_forms():
            for input_field in f.get_inputs():
                try:
                    if input_field.get_id() and not input_field.get_id().startswith(DomAnalyzer.serial_prefix):
                        self._marionette.find_element('id', input_field.get_id()).clear()
                    elif input_field.get_xpath():
                        self._marionette.find_element('xpath', input_field.get_xpath()).clear()
                    else:
                        logger.error('No id nor xpath for an input field in the form %s (%s)', f.get_id(), f.get_xpath())
                        sys.exit()
                except (ElementNotVisibleException, InvalidElementStateException, NoSuchElementException):
                    logger.info('Element is not interactable in empty_form(): id: %s (xpath: %s)', f.get_id(), f.get_xpath())
                except Exception as e:
                    logger.error('Unknown Exception: %s in empty_form(): id: %s (xpath: %s)', str(e), f.get_id(), f.get_xpath())
                    sys.exit()

    def get_source(self):
        return self._marionette.page_source.encode(sys.stdout.encoding, 'ignore')

    def get_screenshot(self, clickable=None):
        element = None
        if clickable:
            try:
                if clickable.get_id() and not clickable.get_id().startswith(DomAnalyzer.serial_prefix):
                    element = self._marionette.find_element('id', clickable.get_id())
                elif clickable.get_xpath():
                    element = self._marionette.find_element('xpath', clickable.get_xpath())
                else:
                    logger.error('No id nor xpath for the clickable: id: %s (xpath: %s)', clickable.get_id(), clickable.get_xpath())
                    sys.exit()
            except (ElementNotVisibleException, InvalidElementStateException, NoSuchElementException):
                logger.info('Element is not interactable in get_screenshot(): id: %s (xpath: %s)', clickable.get_id(), clickable.get_xpath())
            except Exception as e:
                logger.error('Unknown Exception: %s in get_screenshot(): id: %s (xpath: %s)', str(e), clickable.get_id(), clickable.get_xpath())
                sys.exit()
        if not element:
            # set context to CHROME to capture whole screen
            # system frame e.g. FileNotFound cannot be captured without CONTEXT_CHROME (Don't know why)
            self._marionette.set_context(self._marionette.CONTEXT_CHROME)
        screenshot = self._marionette.screenshot(element)
        self._marionette.set_context(self._marionette.CONTEXT_CONTENT)
        return screenshot

    def switch_to_frame(self, by, frame_str):
        """
        :param by: options: "id", "xpath", "link text", "partial link text", "name",
        "tag name", "class name", "css selector", "anon attribute"
        """
        # self.switch_to_top_frame()
        frame = self._marionette.find_element(by, frame_str)
        self._marionette.switch_to_frame(frame)
开发者ID:jwlin,项目名称:b2g-monkey,代码行数:69,代码来源:executor.py

示例2: current_frame

# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import screenshot [as 别名]
class current_frame():
    
    def main(self, LOGDIR, p_el, p_frame_array=False):
        #
        # p_el is an array for the element.
        # p_frame_array is a list of iframes to iterate through (optional).
        #
        self.marionette = Marionette(host='localhost', port=2828)  
        self.marionette.start_session()
        self.marionette.set_search_timeout(1000)
        
        #
        # Switch to the correct iframe (unless it's "()").
        #
        self.marionette.switch_to_frame()
        
        first_iframe = True
        for x in p_frame_array:
            # (just to make it look nice ;)
            typ_str = "'" + x[0] + "'"
            
            if first_iframe:
                first_iframe = False
                print ""
                print "Switching to iframe with " + typ_str.rjust(10) + " = '" + x[1] + "'"
            else:
                print "... then to iframe with  " + typ_str.rjust(10) + " = '" + x[1] + "'"
            
            my_iframe = self.marionette.find_element("xpath", "//iframe[@" + x[0] + "='" + x[1] + "']")
            self.marionette.switch_to_frame(my_iframe)
            
        if first_iframe:
            print ""
            print "Using 'top level' iframe () ..."
        
        #
        # Grab a screenshot and html dump of this frame.
        #
        p_sfnam = LOGDIR + "screenshot.png"
        p_hfnam = LOGDIR + "html_dump.html"
        print ""
        print "Screenshot of this frame saved to: " + p_sfnam
        screenshot = self.marionette.screenshot()[22:]
        with open(p_sfnam, 'w') as f:
            f.write(base64.decodestring(screenshot))
        f.close()

        print "HTML dump of this frame saved to : " + p_hfnam
        f = open(p_hfnam, 'w')
        f.write(self.marionette.page_source.encode('ascii', 'ignore') )
        f.close()

        #
        # Test to see if the element is present / displayed / etc...
        #
        print ""
        print "Checking for element: " + str(p_el)
        b_present   = False
        b_displayed = False
        b_enabled   = False
        try:
            x = self.marionette.find_element(*p_el)
            if x:
                b_present = True
                
                if x.is_displayed():
                    b_displayed = True
                    
                if x.is_enabled():
                    b_enabled = True
        except:
            pass
        
        print ""
        print "Present  : " + str(b_present)
        print "Displayed: " + str(b_displayed)
        print "Enabled  : " + str(b_enabled)
        print ""
开发者ID:villenavg,项目名称:OWD_TEST_TOOLKIT,代码行数:80,代码来源:check_element.py

示例3: current_frame

# 需要导入模块: from marionette import Marionette [as 别名]
# 或者: from marionette.Marionette import screenshot [as 别名]
class current_frame():
    
    filename_screenshot = ""
    filename_htmldump   = ""
    
    def main(self, LOGDIR):
        #
        # The first variable is the log directory.
        #
        ucount  = 0
        self.marionette = Marionette(host='localhost', port=2828)  
        self.marionette.start_session()
        self.marionette.set_search_timeout(1000)
        
        #
        # Now loop through all the iframes, gathering details about each one.
        #
        print ""
        print "Iframe for 'top level' () ..."
        self.filename_screenshot = LOGDIR + "top_level" + ".png"
        self.filename_htmldump   = LOGDIR + "top_level" + ".html"
        self.marionette.switch_to_frame()
        self.record_frame()
        
        frames = self.marionette.find_elements("tag name", "iframe")
        for fnum in range (0, len(frames)):
          
            #
            # App name is usually in the "src" attribute, so it's worth a shot..
            #
            frame_src = frames[fnum].get_attribute("src")
              
            if frame_src != "":
                startpos = frame_src.index('/') + 2
                stoppos  = frame_src.index('.')
                appname  = frame_src[startpos:stoppos]
                filename = appname
            else:
                ucount = ucount + 1
                appname  = "(unknown)"
                filename = "unknown_" + str(ucount)
            
            #
            # Because we call this script sometimes when we hit a Marionette issue,
            # these filenames may already exist (and we'd overwrite them!), so
            # add 'DEBUG_' to the start of the filename.
            #
            filename = "DEBUG_" + filename
                 
            filename_details         = LOGDIR + filename + "_iframe_details.txt"
            self.filename_screenshot = LOGDIR + filename + ".png"
            self.filename_htmldump   = LOGDIR + filename + ".html"
            
            #
            # This iframe gives me problems sometimes, so I'm ignoring it for now.
            #
            if appname == "costcontrol":
                continue
            
            print ""
            print "Iframe for app \"" + appname + "\" ..."
        
            #
            # Record the iframe details (pretty verbose, but 'execute_script' 
            # wasn't letting me use 'for' loops in js for some reason).
            #
            print "    |_ iframe details saved to : " + filename_details
            f = open(filename_details, 'w')
            f.write("Attributes for this iframe ...\n")
            num_attribs = self.marionette.execute_script("return document.getElementsByTagName('iframe')[" + str(fnum) + "].attributes.length;")
            for i in range(0,num_attribs):
                attrib_name  = self.marionette.execute_script("return document.getElementsByTagName('iframe')[" + str(fnum) + "].attributes[" + str(i) + "].nodeName;")
                attrib_value = self.marionette.execute_script("return document.getElementsByTagName('iframe')[" + str(fnum) + "].attributes[" + str(i) + "].nodeValue;")
        
                f.write("    |_ " + attrib_name.ljust(20) + ": \"" + attrib_value + "\"\n")   
            f.close()
            
            #
            # Switch to this frame.
            #
            self.marionette.switch_to_frame(fnum)
                   
            self.record_frame()
         
            self.marionette.switch_to_frame()


    def record_frame(self):
        #
        # Take the screenshot and save it to the file.
        #
        print "    |_ screenshot saved to     : " + self.filename_screenshot
        screenshot = self.marionette.screenshot()[22:]
        with open(self.filename_screenshot, 'w') as f:
            f.write(base64.decodestring(screenshot))
        f.close()
              
        #
        # Take the html dump and save it to the file.
        #
#.........这里部分代码省略.........
开发者ID:villenavg,项目名称:OWD_TEST_TOOLKIT,代码行数:103,代码来源:get_iframe_details.py


注:本文中的marionette.Marionette.screenshot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。