Python selenium.webdriver.Remote() Examples
The following are 30
code examples of selenium.webdriver.Remote().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
selenium.webdriver
, or try the search function
.
Example #1
Source File: views.py From MPContribs with MIT License | 29 votes |
def get_browser(): if "browser" not in g: options = webdriver.ChromeOptions() options.add_argument("no-sandbox") options.add_argument("--disable-gpu") options.add_argument("--window-size=800,600") options.add_argument("--disable-dev-shm-usage") options.set_headless() host = "chrome" if current_app.config["DEBUG"] else "127.0.0.1" g.browser = webdriver.Remote( command_executor=f"http://{host}:4444/wd/hub", desired_capabilities=DesiredCapabilities.CHROME, options=options, ) return g.browser
Example #2
Source File: DriverFactory.py From qxf2-page-object-model with MIT License | 10 votes |
def run_sauce_lab(self,os_name,os_version,browser,browser_version): "Run the test in sauce labs when remote flag is 'Y'" #Get the sauce labs credentials from sauce.credentials file USERNAME = remote_credentials.USERNAME PASSWORD = remote_credentials.ACCESS_KEY if browser.lower() == 'ff' or browser.lower() == 'firefox': desired_capabilities = DesiredCapabilities.FIREFOX elif browser.lower() == 'ie': desired_capabilities = DesiredCapabilities.INTERNETEXPLORER elif browser.lower() == 'chrome': desired_capabilities = DesiredCapabilities.CHROME elif browser.lower() == 'opera': desired_capabilities = DesiredCapabilities.OPERA elif browser.lower() == 'safari': desired_capabilities = DesiredCapabilities.SAFARI desired_capabilities['version'] = browser_version desired_capabilities['platform'] = os_name + ' '+os_version return webdriver.Remote(command_executor="http://%s:%s@ondemand.saucelabs.com:80/wd/hub"%(USERNAME,PASSWORD), desired_capabilities= desired_capabilities)
Example #3
Source File: DriverFactory.py From qxf2-page-object-model with MIT License | 8 votes |
def run_browserstack(self,os_name,os_version,browser,browser_version,remote_project_name,remote_build_name): "Run the test in browser stack when remote flag is 'Y'" #Get the browser stack credentials from browser stack credentials file USERNAME = remote_credentials.USERNAME PASSWORD = remote_credentials.ACCESS_KEY if browser.lower() == 'ff' or browser.lower() == 'firefox': desired_capabilities = DesiredCapabilities.FIREFOX elif browser.lower() == 'ie': desired_capabilities = DesiredCapabilities.INTERNETEXPLORER elif browser.lower() == 'chrome': desired_capabilities = DesiredCapabilities.CHROME elif browser.lower() == 'opera': desired_capabilities = DesiredCapabilities.OPERA elif browser.lower() == 'safari': desired_capabilities = DesiredCapabilities.SAFARI desired_capabilities['os'] = os_name desired_capabilities['os_version'] = os_version desired_capabilities['browser_version'] = browser_version if remote_project_name is not None: desired_capabilities['project'] = remote_project_name if remote_build_name is not None: desired_capabilities['build'] = remote_build_name+"_"+str(datetime.now().strftime("%c")) return webdriver.Remote(RemoteConnection("http://%s:%s@hub-cloud.browserstack.com/wd/hub"%(USERNAME,PASSWORD),resolve_ip= False), desired_capabilities=desired_capabilities)
Example #4
Source File: DriverFactory.py From makemework with MIT License | 8 votes |
def run_browserstack(self,os_name,os_version,browser,browser_version,remote_project_name,remote_build_name): "Run the test in browser stack when remote flag is 'Y'" #Get the browser stack credentials from browser stack credentials file USERNAME = remote_credentials.USERNAME PASSWORD = remote_credentials.ACCESS_KEY if browser.lower() == 'ff' or browser.lower() == 'firefox': desired_capabilities = DesiredCapabilities.FIREFOX elif browser.lower() == 'ie': desired_capabilities = DesiredCapabilities.INTERNETEXPLORER elif browser.lower() == 'chrome': desired_capabilities = DesiredCapabilities.CHROME elif browser.lower() == 'opera': desired_capabilities = DesiredCapabilities.OPERA elif browser.lower() == 'safari': desired_capabilities = DesiredCapabilities.SAFARI desired_capabilities['os'] = os_name desired_capabilities['os_version'] = os_version desired_capabilities['browser_version'] = browser_version if remote_project_name is not None: desired_capabilities['project'] = remote_project_name if remote_build_name is not None: desired_capabilities['build'] = remote_build_name+"_"+str(datetime.now().strftime("%c")) return webdriver.Remote(RemoteConnection("http://%s:%s@hub-cloud.browserstack.com/wd/hub"%(USERNAME,PASSWORD),resolve_ip= False), desired_capabilities=desired_capabilities)
Example #5
Source File: DriverFactory.py From makemework with MIT License | 8 votes |
def run_sauce_lab(self,os_name,os_version,browser,browser_version): "Run the test in sauce labs when remote flag is 'Y'" #Get the sauce labs credentials from sauce.credentials file USERNAME = remote_credentials.USERNAME PASSWORD = remote_credentials.ACCESS_KEY if browser.lower() == 'ff' or browser.lower() == 'firefox': desired_capabilities = DesiredCapabilities.FIREFOX elif browser.lower() == 'ie': desired_capabilities = DesiredCapabilities.INTERNETEXPLORER elif browser.lower() == 'chrome': desired_capabilities = DesiredCapabilities.CHROME elif browser.lower() == 'opera': desired_capabilities = DesiredCapabilities.OPERA elif browser.lower() == 'safari': desired_capabilities = DesiredCapabilities.SAFARI desired_capabilities['version'] = browser_version desired_capabilities['platform'] = os_name + ' '+os_version return webdriver.Remote(command_executor="http://%s:%s@ondemand.saucelabs.com:80/wd/hub"%(USERNAME,PASSWORD), desired_capabilities= desired_capabilities)
Example #6
Source File: selenium.py From mercure with GNU General Public License v3.0 | 7 votes |
def setUp(self): # We use a remote Chrome username = os.environ.get('SAUCE_USERNAME') accesskey = os.environ.get('SAUCE_ACCESS_KEY') desired_cap = { 'platform': 'LINUX', 'browserName': 'chrome', 'version': '', 'tunnel-identifier': os.environ.get('TRAVIS_JOB_NUMBER') } self.drv = webdriver.Remote( command_executor='http://%s:%s@ondemand.saucelabs.com/wd/hub' % (username, accesskey), desired_capabilities=desired_cap, ) super(SeleniumTestCase, self).setUp()
Example #7
Source File: webpages.py From eavatar-me with Apache License 2.0 | 6 votes |
def browser(request): browser_type = os.environ.get('AVA_TEST_BROWSER', 'Firefox') if browser_type == 'PhantomJS': b = webdriver.PhantomJS() if browser_type == 'Chrome': b = webdriver.Chrome() elif browser_type == 'Opera': b = webdriver.Opera() elif browser_type == 'IE': b = webdriver.Ie() elif browser_type == 'Safari': b = webdriver.Safari() elif browser_type == 'Remote': b = webdriver.Remote() else: b = webdriver.Firefox() b.implicitly_wait(5) def teardown_browser(): b.quit() request.addfinalizer(teardown_browser) return b
Example #8
Source File: scrape_lib.py From finance-dl with GNU General Public License v2.0 | 6 votes |
def attach_to_session(executor_url, session_id): original_execute = WebDriver.execute def new_command_execute(self, command, params=None): if command == "newSession": # Mock the response return {'success': 0, 'value': None, 'sessionId': session_id} else: return original_execute(self, command, params) # Patch the function before creating the driver object WebDriver.execute = new_command_execute driver = webdriver.Remote(command_executor=executor_url, desired_capabilities={}) driver.session_id = session_id # Replace the patched function with original function WebDriver.execute = original_execute return driver
Example #9
Source File: browser.py From airgun with GNU General Public License v3.0 | 6 votes |
def _get_saucelabs_browser(self): """Returns saucelabs webdriver instance of selected ``browser``. Note: should not be called directly, use :meth:`get_browser` instead. :raises: ValueError: If wrong ``browser`` specified. """ self._webdriver = webdriver.Remote( command_executor=_sauce_ondemand_url( settings.selenium.saucelabs_user, settings.selenium.saucelabs_key ), desired_capabilities=self._get_webdriver_capabilities() ) self._set_session_cookie() idle_timeout = settings.webdriver_desired_capabilities.idleTimeout if idle_timeout: self._webdriver.command_executor.set_timeout(int(idle_timeout)) return self._webdriver
Example #10
Source File: browser.py From vanguard-api with MIT License | 6 votes |
def start(self): self.driver = webdriver.Remote( command_executor=self.remote, desired_capabilities=self.browser_type)
Example #11
Source File: browser.py From browsertrix with MIT License | 6 votes |
def _init_driver(self): self.driver = None if not self.host_name: self.driver = self._init_local() return while True: try: self.driver = Remote(command_executor='http://{0}:4444/wd/hub'.format(self.host_name), desired_capabilities=self.caps) break except: import traceback traceback.print_exc() print('RETRY CONN')
Example #12
Source File: tv.py From Kairos with GNU General Public License v3.0 | 6 votes |
def find_element(browser, locator, locator_strategy=By.CSS_SELECTOR, except_on_timeout=True, visible=False, delay=CHECK_IF_EXISTS_TIMEOUT): if except_on_timeout: if visible: element = WebDriverWait(browser, delay).until( ec.visibility_of_element_located((locator_strategy, locator))) else: element = WebDriverWait(browser, delay).until( ec.presence_of_element_located((locator_strategy, locator))) return element else: try: if visible: element = WebDriverWait(browser, delay).until( ec.visibility_of_element_located((locator_strategy, locator))) else: element = WebDriverWait(browser, delay).until( ec.presence_of_element_located((locator_strategy, locator))) return element except TimeoutException as e: log.debug(e) log.debug("Check your {} locator: {}".format(locator_strategy, locator)) # print the session_id and url in case the element is not found if browser is webdriver.Remote: # noinspection PyProtectedMember log.debug("In case you want to reuse session, the session_id and _url for current browser session are: {},{}".format(browser.session_id, browser.command_executor._url))
Example #13
Source File: webview.py From uiautomator2 with MIT License | 6 votes |
def driver(package_name): serial = adbutils.adb.device().serial capabilities = { "androidDeviceSerial": serial, "androidPackage": package_name, "androidUseRunningApp": True, } dr = webdriver.Remote("http://localhost:9515", { "chromeOptions": capabilities }) try: yield dr finally: dr.quit()
Example #14
Source File: common.py From boardfarm with BSD 3-Clause Clear License | 6 votes |
def firefox_webproxy_driver(ipport): ''' Use this if you started web proxy on a machine connected to router's LAN. ''' proxy = Proxy({ 'proxyType': 'MANUAL', 'httpProxy': ipport, 'ftpProxy': ipport, 'sslProxy': ipport, 'noProxy': '' }) print("Attempting to open firefox via proxy %s" % ipport) profile = webdriver.FirefoxProfile() profile.set_preference('network.http.phishy-userpass-length', 255) driver = webdriver.Firefox(proxy=proxy, firefox_profile=profile) caps = webdriver.DesiredCapabilities.FIREFOX proxy.add_to_capabilities(caps) #driver = webdriver.Remote(desired_capabilities=caps) driver.implicitly_wait(30) driver.set_page_load_timeout(30) return driver
Example #15
Source File: custom_driver.py From king-bot with MIT License | 6 votes |
def remote(self) -> None: if not self.debug: log("debug mode is turned off, can't reuse old session") return file = open(self.current_session_path, "r") content = file.read() lines = content.split(";") url = lines[0] session = lines[1] self.driver = webdriver.Remote( command_executor=url, desired_capabilities=DesiredCapabilities.CHROME ) self.driver.session_id = session self.set_config()
Example #16
Source File: browser.py From capybara.py with MIT License | 5 votes |
def get_browser(browser_name, capabilities=None, **options): """ Returns an instance of the given browser with the given capabilities. Args: browser_name (str): The name of the desired browser. capabilities (Dict[str, str | bool], optional): The desired capabilities of the browser. Defaults to None. options: Arbitrary keyword arguments for the browser-specific subclass of :class:`webdriver.Remote`. Returns: WebDriver: An instance of the desired browser. """ if browser_name == "chrome": return webdriver.Chrome(desired_capabilities=capabilities, **options) if browser_name == "edge": return webdriver.Edge(capabilities=capabilities, **options) if browser_name in ["ff", "firefox"]: return webdriver.Firefox(capabilities=capabilities, **options) if browser_name in ["ie", "internet_explorer"]: return webdriver.Ie(capabilities=capabilities, **options) if browser_name == "phantomjs": return webdriver.PhantomJS(desired_capabilities=capabilities, **options) if browser_name == "remote": return webdriver.Remote(desired_capabilities=capabilities, **options) if browser_name == "safari": return webdriver.Safari(desired_capabilities=capabilities, **options) raise ValueError("unsupported browser: {}".format(repr(browser_name)))
Example #17
Source File: win.py From automation-for-humans with MIT License | 5 votes |
def init_driver(program, arguments): global desiredCapabilities desiredCapabilities["app"] = program[COMMANDS][0][ARGS][SUBJECT] driver = webdriver.Remote( command_executor=APPIUM_URL, desired_capabilities=desiredCapabilities ) return driver
Example #18
Source File: mac.py From automation-for-humans with MIT License | 5 votes |
def init_driver(program, arguments): driver = webdriver.Remote( command_executor=APPIUM_URL, desired_capabilities=desiredCapabilities ) return driver
Example #19
Source File: browser.py From airgun with GNU General Public License v3.0 | 5 votes |
def _get_remote_browser(self): """Returns remote webdriver instance of selected ``browser``. Note: should not be called directly, use :meth:`get_browser` instead. """ self._webdriver = webdriver.Remote( command_executor=settings.selenium.command_executor, desired_capabilities=self._get_webdriver_capabilities() ) self._set_session_cookie() idle_timeout = settings.webdriver_desired_capabilities.idleTimeout if idle_timeout: self._webdriver.command_executor.set_timeout(int(idle_timeout)) return self._webdriver
Example #20
Source File: browser.py From airgun with GNU General Public License v3.0 | 5 votes |
def _init_webdriver(self): """Init the selenium Remote webdriver.""" if self.webdriver or not self.container: return exception = None # An exception can be raised while the container is not ready # yet. Give up to 10 seconds for a container being ready. for _ in range(20): try: self.webdriver = webdriver.Remote( command_executor='http://127.0.0.1:{0}/wd/hub'.format( self.container['HostPort']), desired_capabilities=self._capabilities ) except Exception as err: # Capture the raised exception for later usage and wait # a few for the next attempt. exception = err time.sleep(.5) else: # Connection succeeded time to leave the for loop break else: # Reraise the captured exception. raise DockerBrowserError( 'Failed to connect the webdriver to the containerized ' 'selenium.' ) from exception
Example #21
Source File: test_selenium.py From ckanext-datarequests with GNU Affero General Public License v3.0 | 5 votes |
def setUp(self): self.clearBBDD() if 'WEB_DRIVER_URL' in os.environ and 'CKAN_SERVER_URL' in os.environ: self.driver = webdriver.Remote(os.environ['WEB_DRIVER_URL'], webdriver.DesiredCapabilities.FIREFOX.copy()) self.base_url = os.environ['CKAN_SERVER_URL'] else: self.driver = webdriver.Firefox() self.base_url = 'http://127.0.0.1:5000/' self.driver.implicitly_wait(5) self.driver.set_window_size(1024, 768)
Example #22
Source File: conftest.py From marvin with BSD 3-Clause "New" or "Revised" License | 5 votes |
def driver(base_url, osinfo, browserinfo): ostype, os_version = osinfo browser, browser_version = browserinfo buildid = '{0}_{1}_{2}_{3}'.format(ostype.lower().replace(' ', '_'), os_version.lower().replace(' ', '_'), browser, browser_version) # skip some combinations if os_version == 'Sierra' and browser == 'safari' and browser_version == '9.1': pytest.skip('cannot have Sierra running safari 9.1') elif os_version == 'El Capitan' and browser == 'safari' and browser_version == '10': pytest.skip('cannot have El Capitan running safari 10') # set driver if browserstack: username = os.environ.get('BROWSERSTACK_USER', None) access = os.environ.get('BROWSERSTACK_ACCESS_KEY', None) desired_cap = {'os': ostype, 'os_version': os_version, 'browser': browser, 'build': buildid, 'browser_version': browser_version, 'project': 'marvin', 'resolution': '1920x1080'} desired_cap['browserstack.local'] = True desired_cap['browserstack.debug'] = True desired_cap['browserstack.localIdentifier'] = os.environ['BROWSERSTACK_LOCAL_IDENTIFIER'] driver = webdriver.Remote( command_executor='http://{0}:{1}@hub.browserstack.com:80/wd/hub'.format(username, access), desired_capabilities=desired_cap) else: if browser == 'chrome': driver = webdriver.Chrome() elif browser == 'firefox': driver = webdriver.Firefox() elif browser == 'safari': driver = webdriver.Safari() driver.get(base_url) yield driver # teardown driver.quit()
Example #23
Source File: conftest.py From sos-notebook with BSD 3-Clause "New" or "Revised" License | 5 votes |
def make_sauce_driver(): """This function helps travis create a driver on Sauce Labs. This function will err if used without specifying the variables expected in that context. """ username = os.environ["SAUCE_USERNAME"] access_key = os.environ["SAUCE_ACCESS_KEY"] capabilities = { "tunnel-identifier": os.environ["TRAVIS_JOB_NUMBER"], "build": os.environ["TRAVIS_BUILD_NUMBER"], "tags": [os.environ['TRAVIS_PYTHON_VERSION'], 'CI'], "platform": "Windows 10", "browserName": os.environ['JUPYTER_TEST_BROWSER'], "version": "latest", } if capabilities['browserName'] == 'firefox': # Attempt to work around issue where browser loses authentication capabilities['version'] = '57.0' hub_url = "%s:%s@localhost:4445" % (username, access_key) print("Connecting remote driver on Sauce Labs") driver = Remote( desired_capabilities=capabilities, command_executor="http://%s/wd/hub" % hub_url) return driver
Example #24
Source File: chromedriver.py From ATX with Apache License 2.0 | 5 votes |
def driver(self, package=None, attach=True, activity=None, process=None): """ Args: - package(string): default current running app - attach(bool): default true, Attach to an already-running app instead of launching the app with a clear data directory - activity(string): Name of the Activity hosting the WebView. - process(string): Process name of the Activity hosting the WebView (as given by ps). If not given, the process name is assumed to be the same as androidPackage. Returns: selenium driver """ app = self._d.current_app() capabilities = { 'chromeOptions': { 'androidDeviceSerial': self._d.serial, 'androidPackage': package or app.package, 'androidUseRunningApp': attach, 'androidProcess': process or app.package, 'androidActivity': activity or app.activity, } } try: dr = webdriver.Remote('http://localhost:%d' % self._port, capabilities) except URLError: self._launch_webdriver() dr = webdriver.Remote('http://localhost:%d' % self._port, capabilities) # always quit driver when done atexit.register(dr.quit) return dr
Example #25
Source File: test.py From selenium-grid-docker-swarm-test with MIT License | 5 votes |
def setUp(self): caps = {'browserName': os.getenv('BROWSER', 'chrome')} address = os.getenv('NODE_HUB_ADDRESS') self.browser = webdriver.Remote( command_executor=f'http://{address}:4444/wd/hub', desired_capabilities=caps )
Example #26
Source File: docker_quickstart.py From bot with GNU General Public License v3.0 | 5 votes |
def selenium_driver(selenium_url): mobile_emulation = {"deviceName": "iPhone 5"} chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--incognito') chrome_options.add_argument("start-maximized") # open Browser in maximized mode chrome_options.add_argument("disable-infobars") # disabling infobars chrome_options.add_argument("--disable-extensions") # disabling extensions chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-dev-shm-usage") # overcome limited resource problems chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']) chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) selenium_driver = webdriver.Remote(command_executor=selenium_url, desired_capabilities=chrome_options.to_capabilities()) return selenium_driver
Example #27
Source File: docker_tryLogin.py From bot with GNU General Public License v3.0 | 5 votes |
def selenium_driver(selenium_url): mobile_emulation = {"deviceName": "iPhone 5"} chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--incognito') chrome_options.add_argument("start-maximized") # open Browser in maximized mode chrome_options.add_argument("disable-infobars") # disabling infobars chrome_options.add_argument("--disable-extensions") # disabling extensions chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-dev-shm-usage") # overcome limited resource problems chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']) chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) selenium_driver = webdriver.Remote(command_executor=selenium_url, desired_capabilities=chrome_options.to_capabilities()) return selenium_driver
Example #28
Source File: pytest_webdriver.py From pytest-plugins with MIT License | 5 votes |
def webdriver(request): """ Connects to a remote selenium webdriver and returns the browser handle. Scoped on a per-function level so you get one browser window per test. Creates screenshots automatically on test failures. Attributes ---------- root_uri: URI to the pyramid_server fixture if it's detected in the test run """ from selenium import webdriver # Look for the pyramid server funcarg in the current session, and save away its root uri root_uri = [] try: root_uri.append(request.getfixturevalue('pyramid_server').uri) except LookupError: pass if CONFIG.browser.lower() == 'phantomjs': driver = webdriver.PhantomJS(executable_path=CONFIG.phantomjs) elif CONFIG.browser.lower() == 'chrome': chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--headless') chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') driver = webdriver.Chrome(chrome_options=chrome_options) else: selenium_uri = CONFIG.uri if not selenium_uri: selenium_uri = 'http://{0}:{1}'.format(CONFIG.host, CONFIG.port) driver = webdriver.Remote( selenium_uri, browser_to_use(webdriver, CONFIG.browser) ) if root_uri: driver.__dict__['root_uri'] = root_uri[0] yield driver driver.close()
Example #29
Source File: __init__.py From tigre with MIT License | 5 votes |
def build(self): """ Build a remote selenium remote webdriver using maked capabilities. # NOTE: to set correct command_executor you can use config, like >>> from tigre import config >>> config.remote_url = 'my_remote_grid_url' """ return webdriver.Remote( command_executor=config.remote_url, desired_capabilities={**self._fixed_caps, **self._caps}, )
Example #30
Source File: conftest.py From temboard with PostgreSQL License | 5 votes |
def selenium(): executor = os.environ.get('SELENIUM', 'http://localhost:4444') + '/wd/hub' driver = Remote( command_executor=executor, desired_capabilities=DesiredCapabilities.FIREFOX.copy(), ) driver.implicitly_wait(3) yield driver driver.quit()