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


Python Display.is_alive方法代码示例

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


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

示例1: new_driver_wrapper

# 需要导入模块: from pyvirtualdisplay import Display [as 别名]
# 或者: from pyvirtualdisplay.Display import is_alive [as 别名]
def new_driver_wrapper(startup_url=None):
    logger = logging.getLogger(__name__)
    browser_config = BrowserConfig()

    display = None
    if browser_config.getbool('use_headless_browser') and not browser_config.getbool('use_remote'):
        display = Display(visible=0, size=(1280, 1024))
        display.start()
        display_pid = display.pid

        def process_exists(pid):
            try:
                os.kill(pid, 0)
            except OSError:
                return False
            else:
                return True

        polling.poll(
            lambda: display.is_alive(),
            timeout=60,
            exception_message='Display was not alive; process was: {}'.format(display_pid),
            ontimeout=(
                lambda: logger.critical('Display process {} exists: {}'.format(
                    display_pid,
                    process_exists(display_pid))
                ),
            )
        )

        polling.poll(
            lambda: display.is_started,
            timeout=60,
            exception_message='Display was alive but not started; process was: {}'.format(display_pid)
        )

        # TODO: Is there a better condition we can check here?
        time.sleep(1.5)

    driver = new_driver()

    logging.getLogger(__name__).info('Browser successfully launched')

    action_callbacks = []
    # Fail if there are errors in the console
    if TestrunConfig().getbool('fail_on_console_errors'):
        action_callbacks.append(_log_fail_callback)

    driver_wrapper = CoyoteDriver(driver=driver, display=display, options={
        'timeout': 40,
        'page_load_timeout': 45,
        'ignore_page_load_timeouts': True,  # Prevent page timeouts from breaking out tests
        'action_callbacks': action_callbacks
    })
    driver.set_window_size(*(1280, 1024))
    return driver_wrapper
开发者ID:Shapeways,项目名称:coyote_framework,代码行数:58,代码来源:coyote_driverfactory.py

示例2: SeleniumExecutor

# 需要导入模块: from pyvirtualdisplay import Display [as 别名]
# 或者: from pyvirtualdisplay.Display import is_alive [as 别名]

#.........这里部分代码省略.........
        if not isinstance(script_path, string_types) and not isinstance(script_path, text_type):
            raise RuntimeError("Nothing to test, no files were provided in scenario")
        test_files = []
        for dir_entry in os.walk(script_path):
            if dir_entry[2]:
                for test_file in dir_entry[2]:
                    if os.path.splitext(test_file)[1].lower() in SeleniumExecutor.SUPPORTED_TYPES:
                        test_files.append(test_file)

        if os.path.isdir(script_path):
            file_ext = os.path.splitext(test_files[0])[1].lower()
        else:
            file_ext = os.path.splitext(script_path)[1]

        if file_ext not in SeleniumExecutor.SUPPORTED_TYPES:
            raise RuntimeError("Supported tests types %s was not found" % SeleniumExecutor.SUPPORTED_TYPES)
        return file_ext

    def startup(self):
        """
        Start runner
        :return:
        """
        self.start_time = time.time()
        if self.virtual_display:
            msg = "Starting virtual display[%s]: %s"
            self.log.info(msg, self.virtual_display.size, self.virtual_display.new_display_var)
            self.virtual_display.start()
        self.runner.run_tests()

    def check(self):
        """
        check if test completed
        :return:
        """
        if self.widget:
            self.widget.update()

        if self.virtual_display and not self.virtual_display.is_alive():
            self.log.info("Virtual display out: %s", self.virtual_display.stdout)
            self.log.warning("Virtual display err: %s", self.virtual_display.stderr)
            raise RuntimeError("Virtual display failed: %s" % self.virtual_display.return_code)

        return self.runner.is_finished()

    def shutdown(self):
        """
        shutdown test_runner
        :return:
        """
        try:
            self.runner.shutdown()
        finally:
            if self.virtual_display and self.virtual_display.is_alive():
                self.virtual_display.stop()

        if self.start_time:
            self.end_time = time.time()
            self.log.debug("Selenium tests ran for %s seconds", self.end_time - self.start_time)

    def post_process(self):
        if self.reader and not self.reader.buffer:
            raise RuntimeWarning("Empty results, most likely Selenium failed")

    def get_widget(self):
        if not self.widget:
            self.widget = SeleniumWidget(self.scenario.get("script"), self.runner.settings.get("stdout"))
        return self.widget

    def resource_files(self):
        if not self.scenario:
            self.scenario = self.get_scenario()

        if "script" not in self.scenario:
            return []

        script = self.scenario.get("script")
        script_type = self.detect_script_type(script)

        if script_type == ".py":
            runner_config = self.settings.get("selenium-tools").get("nose")
        elif script_type == ".jar" or script_type == ".java":
            runner_config = self.settings.get("selenium-tools").get("junit")
        else:
            raise ValueError("Unsupported script type: %s" % script_type)

        if self.runner_working_dir is None:
            self.runner_working_dir = self.engine.create_artifact(runner_config.get("working-dir", "classes"), "")

        self._cp_resource_files(self.runner_working_dir)

        return [os.path.basename(self.runner_working_dir)]

    def __tests_from_requests(self):
        filename = self.engine.create_artifact("test_requests", ".py")
        nose_test = SeleniumScriptBuilder(self.scenario, self.log)
        nose_test.scenario = self.scenario
        nose_test.gen_test_case()
        nose_test.save(filename)
        return filename
开发者ID:SPSCommerce,项目名称:taurus,代码行数:104,代码来源:selenium.py


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