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


Python Browser.__exit__方法代码示例

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


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

示例1: Client

# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import __exit__ [as 别名]
class Client(object):
    """Proxy class which adds more functionatily to Splinter's Browser."""

    def __init__(self, browser_name='firefox', url=None):
        """Initial parameters for a web browser client.

        :param str browser_name: Name for the web browser type to instantiate.
        :param str url: The base url for your server.

        """
        self.browser = Browser(browser_name)
        # If a `url` is provided...
        if url is not None:
            # ...  use it ...
            self.base_url = url
        else:
            # ... else, use the one from configuration file
            self.base_url = conf.properties['url']

    def login(self, username=None, password=None):
        """Performs a login using the provided credentials.

        :param str username: A user name.
        :param str password: A user password.

        """

        if username is None:
            username = conf.properties['username']
        if password is None:
            password = conf.properties['password']

        # Fill the login form.
        self.browser.fill_form(
            {FLD_USERNAME: username, FLD_PASSWORD: password})
        # Click the 'Login' button
        self.browser.find_by_name(BTN_LOGIN).click()

    def logout(self):
        """Performs a logout."""
        # Position the mouse over the account menu to expose submenus.
        self.browser.find_by_id(MENU_ACCOUNT).mouse_over()
        # Then, click the logout menu
        self.browser.find_by_id(MENU_LOGOUT).click()

    def __getattr__(self, name):
        """Proxy attr lookup to self.browser.

        Allows calling Splinter's Browser methods directly. If `name` is not
        a method found in either `Browser` or `Client`, then ``AttributeError``
        is raised.

        :param str name: Name for a supported method.
        :raises: ``AttributeError``

        """
        attr = getattr(self.browser, name, None)
        if attr is None:
            super(Client, self).__getattribute__(name)

        return attr

    def __enter__(self):
        return self

    def __exit__(self, *exc):
        self.browser.__exit__(*exc)
开发者ID:SatelliteQE,项目名称:staplegun,代码行数:69,代码来源:client.py


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