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


Python Driver.close方法代码示例

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


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

示例1: Framework

# 需要导入模块: from driver import Driver [as 别名]
# 或者: from driver.Driver import close [as 别名]
class Framework(TestCase):
    """Framework
    context - targeted environment
    contextmap - targeted environments test data
    """

    TEST_CONTEXT_K = "PYTHON_TEST_CONTEXT"
    TEST_CONTEXT_V = [
            {"name": "TEST", "domain": "localhost", "port": "8080"},
            {"name": "PROD", "domain": "localhost", "port": "8080"}
        ]
    GROUPS = []  # Derived classes have their own

    def __init__(self, args):
        super(Framework, self).__init__(args)
        log.info("running test " + self.id())
        self.args = args
        self.context = self._get_context()
        if self.context:
            context_name = self.context.get("name")
            contextmap = self._setup_context(context_name)
            self.contextmap = contextmap.get(context_name)
        else:
            self.contextmap = {}
        Driver.CONTEXT = self.context

    def setUp(self):
        self._driver = Driver()

    def tearDown(self):
        self._driver.close()
        self.context = None
        self.contextmap = None

    def _get_context(self):
        """Get the no-nonsense test context (env var)"""
        context = os.getenv(Framework.TEST_CONTEXT_K)
        match = next((c for c in self.TEST_CONTEXT_V
                     if c.get("name") == context), {})
        if match:
            return match
        else:
            log.info("Didn't find valid env var '%s'. Continuing",
                     Framework.TEST_CONTEXT_K)

    def _setup_context(self, context):
        """Establish contextmap with the target context data"""
        if context:
            derivedfilepath = inspect.getfile(self.__class__)
            derivedfile = os.path.basename(derivedfilepath)
            derivedfilejson = derivedfile.split(".")[0] + ".json"
            try:
                with open(os.path.dirname(
                  derivedfilepath) + "/" + derivedfilejson) as f:
                    contextmap = json.load(f)
                return self._find_target_context(contextmap)
            except IOError as err:
                self.tearDown()
                msg = str.format("\n{}\n'{}'", err.strerror, err.filename)
                exit("Attempt to find the external data file failed: " + msg)
            except ValueError as err:
                self.tearDown()
                msg = str.format("\n{}", err.message)
                exit("Invalid json format in input file: " + msg)

    def _find_target_context(self, contextmap):
        """Pick the target context data the test will run with"""
        log.debug("Loading context map with " + str(self.context))
        try:
            target_context = [o for o in contextmap.get("contexts") if
                              self.context.get("name") in o][0]
            return target_context
        except (AttributeError, IndexError) as err:
            self.tearDown()
            msg = str.format("{}\n{}", "Using context " +
                             self.context.get("name") + err.message)
            exit("Didn't find the target context in the json: " + msg)
开发者ID:tmillner,项目名称:selenium-exsource,代码行数:79,代码来源:framework.py


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