Ejemplo n.º 1
0
    def __init__(self,
                 timeout=5.0,
                 server_host='localhost',
                 server_port=4444,
                 jar_path=None,
                 run_on_failure='Capture Screenshot'):
        """SeleniumLibrary can be imported with optional arguments.

        `timeout` is the default timeout used to wait for page load actions.
        It can be later set with `Set Selenium Timeout`

        `server_host` and `server_port` are used to connect to Selenium Server.
        Browsers opened with this SeleniumLibrary instance will be attached to
        that server. Note that the Selenium Server must be running before `Open
        Browser` keyword can be used. Selenium Server can be started with
        keyword `Start Selenium Server`. Starting from SeleniumLibrary 2.6.1,
        it is possible to give `server_host` as a URL with a possible embedded
        port, for example `http://192.168.52.1:4444`. If `server_host` contains
        port, the value of `server_port` is ignored.

        `jar_path` is the absolute path to the selenium-server.jar file to be
        used by the library. If set, a custom, modified version can be started
        instead of the default one distributed with the library.

        `run_on_failure` specifies the name of a SeleniumLibrary keyword to
        execute when another SeleniumLibrary keyword fails. By default
        `Capture Screenshot` will be used to take a screenshot of the situation.
        Using any value that is not a keyword name will disable this feature
        altogether. See `Register Keyword To Run On Failure` keyword for more
        information about this functionality that was added in SeleniumLibrary
        2.5.

        Because there are many optional arguments, it is often a good idea to
        use the handy named-arguments syntax supported by Robot Framework 2.5
        and later. This is demonstrated by the last two examples below.

        Examples:
        | Library | SeleniumLibrary | 15 | | | # Sets default timeout |
        | Library | SeleniumLibrary | | | 4455 | # Use default timeout and host but specify different port. |
        | Library | SeleniumLibrary | server_host=http://192.168.52.1:4444 | | | # Host as URL. |
        | Library | SeleniumLibrary | run_on_failure=Nothing | | | # Do nothing on failure. |
        """
        self._cache = utils.ConnectionCache()
        self._selenium = NoBrowserOpen()
        self.set_selenium_timeout(timeout or 5.0)
        self._server_host, self._server_port \
                = self._parse_host_and_port(server_host or 'localhost',
                                            server_port or 4444)
        self._jar_path = jar_path
        self._set_run_on_failure(run_on_failure)
        self._selenium_log = None
        self._locator_parser = LocatorParser(self)
        self._namegen = _NameGenerator()