本文整理汇总了Python中selenium.webdriver.Remote方法的典型用法代码示例。如果您正苦于以下问题:Python webdriver.Remote方法的具体用法?Python webdriver.Remote怎么用?Python webdriver.Remote使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver
的用法示例。
在下文中一共展示了webdriver.Remote方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_browserstack
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Remote [as 别名]
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)
示例2: run_sauce_lab
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Remote [as 别名]
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)
示例3: run_browserstack
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Remote [as 别名]
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)
示例4: run_sauce_lab
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Remote [as 别名]
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)
示例5: get_browser
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Remote [as 别名]
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
示例6: _init_driver
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Remote [as 别名]
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')
示例7: remote
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Remote [as 别名]
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()
示例8: find_element
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Remote [as 别名]
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))
示例9: _get_saucelabs_browser
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Remote [as 别名]
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
示例10: firefox_webproxy_driver
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Remote [as 别名]
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
示例11: browser
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Remote [as 别名]
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
示例12: setUp
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Remote [as 别名]
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()
示例13: attach_to_session
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Remote [as 别名]
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
示例14: start
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Remote [as 别名]
def start(self):
self.driver = webdriver.Remote(
command_executor=self.remote,
desired_capabilities=self.browser_type)
示例15: __init__
# 需要导入模块: from selenium import webdriver [as 别名]
# 或者: from selenium.webdriver import Remote [as 别名]
def __init__(self, command_executor = None, session_id = None, previous_read_message = None):
chrome_options = Options()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--user-agent='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36'")
chrome_options.add_argument('--verbose')
chrome_options.add_argument('--log-path=/tmp/chrome.log')
if command_executor == None:
if config.CHROMEDRIVER_LOCATION == 'None': #Launching in docker container
chrome_options.add_argument('--headless')
self.driver = webdriver.Chrome(chrome_options=chrome_options)
self.driver.set_window_size(1920, 1080)
else:
self.driver = webdriver.Chrome(config.CHROMEDRIVER_LOCATION, chrome_options=chrome_options)
self.driver.get('https://web.whatsapp.com')
print(self.driver.session_id )
print(self.driver.command_executor._url)
self.find_scan_code()
else:
self.driver = webdriver.Remote(command_executor=command_executor,desired_capabilities={})
self.driver.close()
self.driver.session_id = session_id
self.previous_read_message = previous_read_message