本文整理汇总了Python中selenium.webdriver.Remote.get方法的典型用法代码示例。如果您正苦于以下问题:Python Remote.get方法的具体用法?Python Remote.get怎么用?Python Remote.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.Remote
的用法示例。
在下文中一共展示了Remote.get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BuyPageTest
# 需要导入模块: from selenium.webdriver import Remote [as 别名]
# 或者: from selenium.webdriver.Remote import get [as 别名]
class BuyPageTest(unittest.TestCase):
def setUp(self):
browser = os.environ.get('TTHA2BROWSER', 'CHROME')
self.driver = Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=getattr(DesiredCapabilities, browser).copy()
)
self.driver.get("https://cars.mail.ru/sale/msk/all/")
def tearDown(self):
self.driver.quit()
def test_price_sort(self):
page = BuyPage(self.driver)
page.price_sort_btn.click()
cards = page.read_cards()
prices = [x.price for x in cards]
for i in range(0, len(prices) - 1):
self.assertTrue(prices[i] <= prices[i + 1])
def test_region(self):
page = BuyPage(self.driver)
page.region_btn.click()
page.region_input.send_keys(u'Казань')
page.city_first_result.click()
page.submit_region_btn.click()
page.apply_filter_lnk.click()
cards = page.read_cards()
for x in cards:
self.assertTrue(x.region == u'Казань')
示例2: test_open_driver
# 需要导入模块: from selenium.webdriver import Remote [as 别名]
# 或者: from selenium.webdriver.Remote import get [as 别名]
def test_open_driver(self,host,brower):
driver = Remote(command_executor=host,
desired_capabilities=brower
)
# fileList = fileRead().get_ip_address()
# ipAdd = fileList[0].strip('\n')
driver.maximize_window()
driver.get("https://" + ipAdd + "/fort")
if brower == DesiredCapabilities.INTERNETEXPLORER:
#https访问时弹出安全警告页面后点击继续,0代表有安全警告,1代表没有安全警告
driver.get("javascript:document.getElementById('overridelink').click();")
#获取浏览器版本
#brower_name = DesiredCapabilities.INTERNETEXPLORER.get('browserName')
return driver
示例3: remote_open_driver
# 需要导入模块: from selenium.webdriver import Remote [as 别名]
# 或者: from selenium.webdriver.Remote import get [as 别名]
def remote_open_driver(self,host,brower):
driver = Remote(command_executor=host,
desired_capabilities={'platform':'ANY',
'browserName':brower,
# 'version':'',
'javascriptEnabled':True,
'marionette':False
}
)
ipAdd = jsonTranscoding().get_app_ip().strip()
driver.maximize_window()
driver.get("https://" + ipAdd + "/fort")
if brower == "internet explorer":
#https访问时弹出安全警告页面后点击继续,0代表有安全警告,1代表没有安全警告
driver.get("javascript:document.getElementById('overridelink').click();")
return driver
示例4: test_baidu_search_english
# 需要导入模块: from selenium.webdriver import Remote [as 别名]
# 或者: from selenium.webdriver.Remote import get [as 别名]
def test_baidu_search_english(self):
u'''搜索英文'''
for host,browser in self.browser_list.items():
print host,browser
driver = Remote(
command_executor=host,
desired_capabilities={
'platform':'ANY',
'browserName':browser,
'version':'',
'javascriptEnabled':True
}
)
driver.get(self.baseurl) #访问url
driver.find_element_by_id("kw").send_keys(u"selenium") #搜索框输入
driver.find_element_by_id("su").click() #点击搜索按钮
time.sleep(1)
assert(u"selenium_百度搜索" == driver.title),'Test Rusult:Fail' #断言结果
driver.quit()
print time.ctime()
示例5: Browser
# 需要导入模块: from selenium.webdriver import Remote [as 别名]
# 或者: from selenium.webdriver.Remote import get [as 别名]
class Browser(object):
def __init__(self, host_name=None, readlog=False):
self.readlog = readlog
self.host_name = host_name
self.caps = self._init_caps()
self._init_driver()
def _init_local(self):
raise NotImplemented()
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')
def close(self):
if self.driver:
self.driver.quit()
def visit(self, url):
try:
self.driver.get(url)
except:
self._init_driver()
self.driver.get(url)
results = {}
return results
示例6: TakeScreenshotScenarioTestCase
# 需要导入模块: from selenium.webdriver import Remote [as 别名]
# 或者: from selenium.webdriver.Remote import get [as 别名]
class TakeScreenshotScenarioTestCase(BrowserTestCase):
def setUp(self):
self.current_directory = os.path.dirname(os.path.abspath(__file__))
super(TakeScreenshotScenarioTestCase, self).setUp()
def tearDown(self):
self.driver.quit()
try:
os.remove(self.screenshot1)
except (OSError, AttributeError):
pass
try:
os.remove(self.screenshot2)
except (OSError, AttributeError):
pass
super(TakeScreenshotScenarioTestCase, self).tearDown()
def test_scenario_firefox(self):
self.driver = Remote(
desired_capabilities=DesiredCapabilities.FIREFOX,
command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port),
)
dali = Dali(self.driver)
# driver can navigate through himself
self.driver.get(self.page_url("colored"))
self.screenshot1 = dali.take_screenshot(resolution="800x600", path_to_save=self.current_directory)
# and we can use scenario with preset resolution
def scenario(driver):
driver.get(self.page_url("colored"))
self.screenshot2 = dali.take_screenshot(
resolution="800x600", scenario=scenario, scenario_args=self.driver, path_to_save=self.current_directory
)
self.assertTrue(os.path.exists(self.screenshot1))
self.assertTrue(os.path.exists(self.screenshot2))
image1 = Image.open(self.screenshot1)
image2 = Image.open(self.screenshot2)
matrix1 = numpy.asarray(image1)
matrix2 = numpy.asarray(image2)
numpy.testing.assert_array_equal(matrix1, matrix2)
def test_scenario_chrome(self):
self.driver = Remote(
desired_capabilities=DesiredCapabilities.CHROME,
command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port),
)
dali = Dali(self.driver)
# driver can navigate through himself
self.driver.get(self.page_url("colored"))
self.screenshot1 = dali.take_screenshot(resolution="800x600", path_to_save=self.current_directory)
# and we can use scenario with preset resolution
def scenario(driver):
driver.get(self.page_url("colored"))
self.screenshot2 = dali.take_screenshot(
resolution="800x600", scenario=scenario, scenario_args=self.driver, path_to_save=self.current_directory
)
self.assertTrue(os.path.exists(self.screenshot1))
self.assertTrue(os.path.exists(self.screenshot2))
image1 = Image.open(self.screenshot1)
image2 = Image.open(self.screenshot2)
matrix1 = numpy.asarray(image1)
matrix2 = numpy.asarray(image2)
numpy.testing.assert_array_equal(matrix1, matrix2)
@unittest.expectedFailure
def test_scenario_opera(self):
self.driver = Remote(
desired_capabilities=DesiredCapabilities.OPERA,
command_executor="http://{host}:{port}/wd/hub".format(host=Config.server, port=Config.port),
)
dali = Dali(self.driver)
# driver can navigate through himself
self.driver.get(self.page_url("colored"))
self.screenshot1 = dali.take_screenshot(resolution="800x600", path_to_save=self.current_directory)
# and we can use scenario with preset resolution
def scenario(driver):
driver.get(self.page_url("colored"))
self.screenshot2 = dali.take_screenshot(
resolution="800x600", scenario=scenario, scenario_args=self.driver, path_to_save=self.current_directory
)
#.........这里部分代码省略.........
示例7: selenium_scaner
# 需要导入模块: from selenium.webdriver import Remote [as 别名]
# 或者: from selenium.webdriver.Remote import get [as 别名]
class selenium_scaner():
links = dict()
current_page = ""
current_submit_button = 0
current_submit_input = 0
def __init__(self):
browser = os.environ.get('TTHA2BROWSER', 'CHROME')
self.driver = Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=getattr(DesiredCapabilities, browser).copy()
)
self.driver.maximize_window()
def check_xss(self):
problems_found = False
problems = self.wait_and_find_many(XSS_SELECTOR)
for i in problems:
problems_found = True
file_logger().trace("Most likely XSS found.\n"+
"Xss script was found in page\n"+
"Outputing page source code to file", LOG_XSS)
file_logger().print_to_file(self.current_page + "\n" + self.driver.page_source + "\n\n")
break
if not problems_found:
if self.driver.page_source.find(XSS_BLOCK) >= 0:
file_logger().trace("Potential XSS found.\n"+
"Xss script was found in page\n"+
"Outputing page source code to file", LOG_XSS)
file_logger().print_to_file(self.current_page + "\n" + self.driver.page_source + "\n\n")
pass
def check_page(self):
self.current_submit_button = -1
self.current_submit_input = -1
inputs_checked = False
submits_checked = False
while ((not inputs_checked) or (not submits_checked)):
text_input_fields = self.wait_and_find_many('input[type="text"]')
password_input_fields = self.wait_and_find_many('input[type="password"]')
text_areas = self.wait_and_find_many('textarea')
submit_inputs = self.wait_and_find_many('input[type="submit"]')
submit_buttons = self.wait_and_find_many('button[type="submit"]')
for i in text_input_fields:
i.send_keys(XSS_BLOCK)
for i in password_input_fields:
i.send_keys(XSS_BLOCK)
for i in text_areas:
i.send_keys(XSS_BLOCK)
inputs_checked = True
for i in submit_inputs:
if i > self.current_submit_input:
self.current_submit_input = i
inputs_checked = False
i.click()
if inputs_checked == True:
submits_checked = True
for i in submit_buttons:
if i >= self.current_submit_button:
self.current_submit_button = i
submits_checked = False
i.click()
self.check_xss()
self.driver.get(self.current_page)
def visit_page(self, target):
found_new_page = False
file_logger().trace("visit " + target, LOG_PROGRESS)
self.current_page = target
self.driver.get(target)
results = self.wait_and_find_many("a[href]")
for i in results:
link = i.get_attribute("href")
if not (link in self.links):
found_new_page = True
self.links[link] = False
self.check_page()
self.links[target] = True
return found_new_page
def scan_site_with_selenium(self, target):
self.target = target
#.........这里部分代码省略.........
示例8: Remote
# 需要导入模块: from selenium.webdriver import Remote [as 别名]
# 或者: from selenium.webdriver.Remote import get [as 别名]
#coding=utf-8
from selenium.webdriver import Remote
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
#desired_capabilities=DesiredCapabilities.CHROME
desired_capabilities={
'platform':'ANY',
'browserName':'chrome',
'version':'',
'javascriptEnabled':True
}
)
driver.get('http://www.baidu.com')
driver.quit()
示例9: Browser
# 需要导入模块: from selenium.webdriver import Remote [as 别名]
# 或者: from selenium.webdriver.Remote import get [as 别名]
class Browser(object):
def __init__(self, harness, selenium_server_url, selenium_browser, width=1024, height=600):
self.harness = harness
self.selenium_server_url = selenium_server_url
self.selenium_browser = selenium_browser
self.width = width
self.height = height
self.selenium = Remote(
self.selenium_server_url.encode('ascii'),
desired_capabilities = {
'browserName': self.selenium_browser,
},
)
self.selenium.set_window_size(width, height)
def __enter__(self):
self.harness.browser_stack.append(self)
return self
def __exit__(self, type, value, traceback):
if self.harness.browser_stack[-1] != self:
raise Exception("Unexpected browser on the top of the stack")
self.harness.browser_stack.pop()
return
def shutdown(self):
self.selenium.quit()
def back(self):
self.selenium.back()
def refresh(self):
self.selenium.refresh()
def title(self):
return self.selenium.title
def source(self):
return self.selenium.page_source
def get(self, uri):
self.selenium.get(uri)
def find(self, selector):
return WebElementSet(self, elements=self.selenium).find(selector)
def add_cookie(self, cookie_dict):
self.selenium.add_cookie(cookie_dict)
def get_cookie(self, name):
return self.selenium.get_cookie(name)
def endpoint(self):
return self.find('html').attr('id').replace('endpoint-', '').replace('-', '.')
def endpoint_is(self, endpoint):
is_equal(self.endpoint(), endpoint, "Endpoint is correct")
def wait_for_bootstrap_modal(self):
last = [None]
def inner_wait(driver):
value = self.find('.modal')[-1].css('top')
if last[0] and last[0] == value:
return True
last[0] = value
return False
WebDriverWait(self.selenium, 3).until(inner_wait)
return self
def url(self):
return furl(self.selenium.current_url)
def execute_script(self, script):
return self.selenium.execute_script(script)
def wait_for_ajax(self):
WebDriverWait(self.selenium, 10).until_not(lambda x: x.execute_script('return jQuery.active'))
return self
def wait_for_jquery(self):
WebDriverWait(self.selenium, 10).until(lambda x: x.execute_script('return window.jQuery ? true : false'))
return self
def screenshot(self, message="Screenshot: "):
if 's3_access_key' not in app.settings.options('test'):
print "No screenshot S3 instance configured - skipping screenshot"
return
if not hasattr(self, 's3_connection'):
if 's3_host' in app.settings.options('test'):
self.s3_connection = boto.s3.connection.S3Connection(
app.settings.get('test', 's3_access_key'),
app.settings.get('test', 's3_secret_key'),
host = app.settings.get('test', 's3_host'),
)
else:
self.s3_connection = boto.s3.connection.S3Connection(
app.settings.get('test', 's3_access_key'),
#.........这里部分代码省略.........
示例10: AdminSeleniumWebDriverTestCase
# 需要导入模块: from selenium.webdriver import Remote [as 别名]
# 或者: from selenium.webdriver.Remote import get [as 别名]
class AdminSeleniumWebDriverTestCase(LiveServerTestCase):
available_apps = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
]
def _get_remote_capabilities(self, specs):
platforms = {
"s": "Windows 2008",
"x": "Windows 2003",
"e": "Windows 2012",
"l": "Linux",
"m": "Mac 10.6",
"i": "Mac 10.8",
}
browsers = {
"ff": "firefox",
"op": "opera",
"ie": "internet explorer",
"sa": "safari",
"ip": "ipad",
"ih": "iphone",
"an": "android",
"gc": "chrome",
}
browser = browsers[specs[:2]]
if specs[-1] in platforms:
platform = platforms.get(specs[-1])
version = specs[2:-1]
else:
platform = None
version = specs[2:]
caps = {"browserName": browser, "version": version, "platform": platform, "public": "public"}
if "BUILD_NUMBER" in os.environ:
caps["build"] = os.environ["BUILD_NUMBER"]
elif "TRAVIS_BUILD_NUMBER" in os.environ:
caps["build"] = os.environ["TRAVIS_BUILD_NUMBER"]
return caps
def _get_local_webdriver_class(self, specs):
browsers = {
"ff": "selenium.webdriver.Firefox",
"op": "selenium.webdriver.Opera",
"ie": "selenium.webdriver.Ie",
"gc": "selenium.webdriver.Chrome",
}
return import_by_path(browsers[specs[:2]])
def setUp(self):
test_method = getattr(self, self._testMethodName)
if not hasattr(test_method, "spec"):
raise SkipTest("Please make sure your test class is decorated with @browserize")
elif not test_method.spec:
raise SkipTest("Selenium tests not requested")
try:
selenium_specs = test_method.spec
if os.environ.get("DJANGO_SELENIUM_REMOTE", False):
webdriver_class = import_by_path("selenium.webdriver.Remote")
else:
webdriver_class = self._get_local_webdriver_class(selenium_specs)
except Exception as e:
raise SkipTest(
'Selenium specifications "%s" not valid or '
"corresponding WebDriver not installed: %s" % (selenium_specs, str(e))
)
from selenium.webdriver import Remote
if webdriver_class is Remote:
if not (os.environ.get("REMOTE_USER") and os.environ.get("REMOTE_KEY")):
raise self.failureException(
"Both REMOTE_USER and REMOTE_KEY environment variables are required for remote tests."
)
capabilities = self._get_remote_capabilities(selenium_specs)
capabilities["name"] = self.id()
auth = "%(REMOTE_USER)s:%(REMOTE_KEY)s" % os.environ
hub = os.environ.get("REMOTE_HUB", "ondemand.saucelabs.com:80")
self.selenium = Remote(
command_executor="http://%[email protected]%s/wd/hub" % (auth, hub), desired_capabilities=capabilities
)
else:
self.selenium = webdriver_class()
super(AdminSeleniumWebDriverTestCase, self).setUp()
def tearDown(self):
if hasattr(self, "selenium"):
from selenium.webdriver import Remote
if isinstance(self.selenium, Remote):
self._report_sauce_pass_fail()
self.selenium.quit()
super(AdminSeleniumWebDriverTestCase, self).tearDown()
def _report_sauce_pass_fail(self):
# Sauce Labs has no way of knowing if the test passed or failed, so we
#.........这里部分代码省略.........