Best Python code snippet using splinter
__init__.py
Source:__init__.py  
...79        self.close()80    def __str__(self):81        """Print the temporary file's absolute path"""82        return self.name83def selenium_server_is_running(host=DEFAULT_HOST, port=DEFAULT_PORT):84    """Check if a selenium-server is running on `host` and `port`"""85    conn = httplib.HTTPConnection(host, int(port))86    try: conn.connect()87    except httplib.socket.error: return False88    else: return True89@exception_retry_decorator(RuntimeError, "waiting for selenium-server")90def wait_until_server_has_started(host=DEFAULT_HOST, port=DEFAULT_PORT):91    """Stall callee until selenium-server on `host` and `port` becomes active"""92    log("waiting until selenium-server has started")93    if not selenium_server_is_running(host, port): raise RuntimeError 94class wbSelenium(SeleniumLibrary):95    """This class checks the plugins directory for any selenium extensions96    that the user may have added and generates a selenium object which97    contains these plugins. It also controls a selenium server which can98    use custom javascript files specified in your plugin directory. Acts99    as a wrapper to the Robot SeleniumLibrary.100    By default this class looks at the class variable BASE_DIR to load the101    standard wbSelenium keywords and their respective JS files which are102    found in BASE_DIR/JS_DIR. If the user specifies an additional103    plugin_dir as an argument to the "Library wbSelenium" then this104    folder will be searched for py files, and the JS_DIR subdirectory will105    be searched for js files to allow custom keywords. This file merely106    locates the external python and js files, and extends from the classes107    specified in this py files.108    This plugin system eliminates the need for wb-SELENIUM users to modify their109    local SeleniumLibrary installations or their selenium-server.jar files.110    Thus, SeleniumLibrary and selenium-server can be easily upgraded111    without the need to merge changes or deal with dependencies.112    """113    ROBOT_LIBRARY_SCOPE = 'GLOBAL'114    ROBOT_LIBRARY_VERSION = __wb_SELENIUM_LIBRARY_VER__115    BASE_DIR = os.path.join(os.path.dirname(__file__), "plugins")116    JS_DIR = 'js'117    def __init__(self, timeout=60, host=DEFAULT_HOST, port=DEFAULT_PORT, plugin_dir=""):118        """Load the wbSelenium library with arguments for Robot's119        SeleniumLibrary and selenium-server.120        Classes defined in python files are searched in the base directory121        and plugin directory. This class inherits from SeleniumLibrary and122        also all other classes specified in the plugin and base123        directories. Dynamic inheritance is implemented using the124        Class.__bases__ += method which means all external classes must be125        new style (inherit from object). """126        SeleniumLibrary.__init__(self, timeout, host, port)127        # use plugin dir if specified, otherwise just load WikiBhasha base128        extension_paths = [wbSelenium.BASE_DIR] + (plugin_dir and [os.path.abspath(plugin_dir)] or [])129        # get list of all of the javascript files and flatten list130        js_files = sum([self._get_ext_js(path) for path in extension_paths], [])131        self._user_ext_file = js_files and TempJSExtensionFile() or None132        def process_curry(file):133            self._process_js_ext(file, self._user_ext_file)134        map(process_curry, js_files)135        # inherit from other extensions (must take a flat tuple)136        ext_classes = tuple(sum([self._get_ext_classes(path) for path in extension_paths], []))137        # plugins override SeleniumLibrary in MRO138        wbSelenium.__bases__ = ext_classes + wbSelenium.__bases__ 139        for klass in ext_classes:140            log("wbSelenium imported class: " + klass.__name__)141            #super(klass, self).__init__()142            klass.__init__(self)143    def start_selenium_server(self, *params):144        """Start a selenium-server using extensions specified in the 145        constructor and selenium-server *params.146        Note that server params `port`, `timeout` and `userExtensions` are 147        not appliciable as they are specified in the wbSelenium 148        constructor."""149        if selenium_server_is_running(self._server_host, self._server_port):150            error = 'an instance of selenium-server on host %s, port %s is already running, please shutdown and rerun testcase' % (self._server_host, self._server_port) 151            warn(error)152            raise RuntimeError, error153        params += ('-port', str(self._server_port))154        if self._user_ext_file:155            params += ('-userExtensions', self._user_ext_file.name)156        SeleniumLibrary.start_selenium_server(self, *params) # unfortunatly this fails silently as well157        wait_until_server_has_started(self._server_host, self._server_port)158    @exception_retry_decorator(OSError, "could not close file")159    def shut_down_selenium_server(self):160        """Stop the previously started selenium-server and clean up any161        temporary files that were created."""162        try: SeleniumLibrary.shut_down_selenium_server(self)163        # error only is thrown when log file was not created,...test_webdriver_remote.py
Source:test_webdriver_remote.py  
...10from splinter import Browser11from .fake_webapp import EXAMPLE_APP12from .base import WebDriverTests13import pytest14def selenium_server_is_running():15    try:16        from splinter.driver.webdriver.remote import WebDriver17        page_contents = urlopen(WebDriver.DEFAULT_URL).read()18    except IOError:19        return False20    return "WebDriver Hub" in page_contents21class RemoteBrowserTest(WebDriverTests, unittest.TestCase):22    @pytest.fixture(autouse=True, scope='class')23    def setup_browser(self, request):24        request.cls.browser = Browser("remote")25        request.addfinalizer(request.cls.browser.quit)26    def setUp(self):27        self.browser.visit(EXAMPLE_APP)28    def test_support_with_statement(self):...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
